Commit 6677a776 authored by Phil Sutter's avatar Phil Sutter Committed by Herbert Xu

crypto: mv_cesa - refactor copy_src_to_buf()

The main goal was to have it not do anything when a zero len parameter
was being passed (which could lead to a null pointer dereference, as in
this case p->src_sg is null, either). Using the min() macro, the lower
part of the loop gets simpler, too.
Signed-off-by: default avatarPhil Sutter <phil.sutter@viprinet.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 7a1c6bcf
...@@ -187,9 +187,9 @@ static void copy_src_to_buf(struct req_progress *p, char *dbuf, int len) ...@@ -187,9 +187,9 @@ static void copy_src_to_buf(struct req_progress *p, char *dbuf, int len)
{ {
int ret; int ret;
void *sbuf; void *sbuf;
int copied = 0; int copy_len;
while (1) { while (len) {
if (!p->sg_src_left) { if (!p->sg_src_left) {
ret = sg_miter_next(&p->src_sg_it); ret = sg_miter_next(&p->src_sg_it);
BUG_ON(!ret); BUG_ON(!ret);
...@@ -199,19 +199,14 @@ static void copy_src_to_buf(struct req_progress *p, char *dbuf, int len) ...@@ -199,19 +199,14 @@ static void copy_src_to_buf(struct req_progress *p, char *dbuf, int len)
sbuf = p->src_sg_it.addr + p->src_start; sbuf = p->src_sg_it.addr + p->src_start;
if (p->sg_src_left <= len - copied) { copy_len = min(p->sg_src_left, len);
memcpy(dbuf + copied, sbuf, p->sg_src_left); memcpy(dbuf, sbuf, copy_len);
copied += p->sg_src_left;
p->sg_src_left = 0; p->src_start += copy_len;
if (copied >= len) p->sg_src_left -= copy_len;
break;
} else { len -= copy_len;
int copy_len = len - copied; dbuf += copy_len;
memcpy(dbuf + copied, sbuf, copy_len);
p->src_start += copy_len;
p->sg_src_left -= copy_len;
break;
}
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment