Skip to content

Commit

Permalink
crypto: mv_cesa - refactor copy_src_to_buf()
Browse files Browse the repository at this point in the history
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: Phil Sutter <phil.sutter@viprinet.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
  • Loading branch information
Phil Sutter authored and Herbert Xu committed May 11, 2011
1 parent 7a1c6bc commit 6677a77
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions drivers/crypto/mv_cesa.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ static void copy_src_to_buf(struct req_progress *p, char *dbuf, int len)
{
int ret;
void *sbuf;
int copied = 0;
int copy_len;

while (1) {
while (len) {
if (!p->sg_src_left) {
ret = sg_miter_next(&p->src_sg_it);
BUG_ON(!ret);
Expand All @@ -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;

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;
}
copy_len = min(p->sg_src_left, len);
memcpy(dbuf, sbuf, copy_len);

p->src_start += copy_len;
p->sg_src_left -= copy_len;

len -= copy_len;
dbuf += copy_len;
}
}

Expand Down

0 comments on commit 6677a77

Please sign in to comment.