crypto: mv_cesa - Fix situations where the src sglist spans more data than the request asks for

Fix for situations where the source scatterlist spans more data than the
request nbytes

Signed-off-by: Uri Simchoni <uri@jdland.co.il>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
Uri Simchoni 2010-04-08 19:27:02 +03:00 committed by Herbert Xu
parent f565e67ec1
commit 15d4dd3594

View file

@ -143,27 +143,45 @@ static int mv_setkey_aes(struct crypto_ablkcipher *cipher, const u8 *key,
return 0; return 0;
} }
static void setup_data_in(struct ablkcipher_request *req) static void copy_src_to_buf(struct req_progress *p, char *dbuf, int len)
{ {
int ret; int ret;
void *buf; void *sbuf;
int copied = 0;
if (!cpg->p.sg_src_left) { while (1) {
ret = sg_miter_next(&cpg->p.src_sg_it); if (!p->sg_src_left) {
BUG_ON(!ret); ret = sg_miter_next(&p->src_sg_it);
cpg->p.sg_src_left = cpg->p.src_sg_it.length; BUG_ON(!ret);
cpg->p.src_start = 0; p->sg_src_left = p->src_sg_it.length;
p->src_start = 0;
}
sbuf = p->src_sg_it.addr + p->src_start;
if (p->sg_src_left <= len - copied) {
memcpy(dbuf + copied, sbuf, p->sg_src_left);
copied += p->sg_src_left;
p->sg_src_left = 0;
if (copied >= len)
break;
} else {
int copy_len = len - copied;
memcpy(dbuf + copied, sbuf, copy_len);
p->src_start += copy_len;
p->sg_src_left -= copy_len;
break;
}
} }
}
cpg->p.crypt_len = min(cpg->p.sg_src_left, cpg->max_req_size); static void setup_data_in(struct ablkcipher_request *req)
{
buf = cpg->p.src_sg_it.addr; struct req_progress *p = &cpg->p;
buf += cpg->p.src_start; p->crypt_len =
min((int)req->nbytes - p->total_req_bytes, cpg->max_req_size);
memcpy(cpg->sram + SRAM_DATA_IN_START, buf, cpg->p.crypt_len); copy_src_to_buf(p, cpg->sram + SRAM_DATA_IN_START,
p->crypt_len);
cpg->p.sg_src_left -= cpg->p.crypt_len;
cpg->p.src_start += cpg->p.crypt_len;
} }
static void mv_process_current_q(int first_block) static void mv_process_current_q(int first_block)
@ -289,12 +307,16 @@ static void dequeue_complete_req(void)
static int count_sgs(struct scatterlist *sl, unsigned int total_bytes) static int count_sgs(struct scatterlist *sl, unsigned int total_bytes)
{ {
int i = 0; int i = 0;
size_t cur_len;
do { while (1) {
total_bytes -= sl[i].length; cur_len = sl[i].length;
i++; ++i;
if (total_bytes > cur_len)
} while (total_bytes > 0); total_bytes -= cur_len;
else
break;
}
return i; return i;
} }