summaryrefslogtreecommitdiff
path: root/drivers/crypto
diff options
context:
space:
mode:
authorPhil Sutter <phil.sutter@viprinet.com>2011-05-05 13:29:02 (GMT)
committerHerbert Xu <herbert@gondor.apana.org.au>2011-05-11 05:06:18 (GMT)
commit6677a776cf3dc4950a790946f88d26dafc4baf7b (patch)
tree7554959e21ad98344c8e150f71c3aade49fca233 /drivers/crypto
parent7a1c6bcf269203485d716d8e3bec6671dabb5067 (diff)
downloadlinux-6677a776cf3dc4950a790946f88d26dafc4baf7b.tar.xz
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: Phil Sutter <phil.sutter@viprinet.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto')
-rw-r--r--drivers/crypto/mv_cesa.c25
1 files changed, 10 insertions, 15 deletions
diff --git a/drivers/crypto/mv_cesa.c b/drivers/crypto/mv_cesa.c
index fb3f1e3..de09303 100644
--- a/drivers/crypto/mv_cesa.c
+++ b/drivers/crypto/mv_cesa.c
@@ -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);
@@ -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;
}
}