diff options
author | Phil Sutter <phil.sutter@viprinet.com> | 2011-05-05 09:29:02 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2011-05-11 01:06:18 -0400 |
commit | 6677a776cf3dc4950a790946f88d26dafc4baf7b (patch) | |
tree | 7554959e21ad98344c8e150f71c3aade49fca233 /drivers | |
parent | 7a1c6bcf269203485d716d8e3bec6671dabb5067 (diff) |
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')
-rw-r--r-- | drivers/crypto/mv_cesa.c | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/drivers/crypto/mv_cesa.c b/drivers/crypto/mv_cesa.c index fb3f1e35623d..de09303675d8 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) | |||
187 | { | 187 | { |
188 | int ret; | 188 | int ret; |
189 | void *sbuf; | 189 | void *sbuf; |
190 | int copied = 0; | 190 | int copy_len; |
191 | 191 | ||
192 | while (1) { | 192 | while (len) { |
193 | if (!p->sg_src_left) { | 193 | if (!p->sg_src_left) { |
194 | ret = sg_miter_next(&p->src_sg_it); | 194 | ret = sg_miter_next(&p->src_sg_it); |
195 | BUG_ON(!ret); | 195 | BUG_ON(!ret); |
@@ -199,19 +199,14 @@ static void copy_src_to_buf(struct req_progress *p, char *dbuf, int len) | |||
199 | 199 | ||
200 | sbuf = p->src_sg_it.addr + p->src_start; | 200 | sbuf = p->src_sg_it.addr + p->src_start; |
201 | 201 | ||
202 | if (p->sg_src_left <= len - copied) { | 202 | copy_len = min(p->sg_src_left, len); |
203 | memcpy(dbuf + copied, sbuf, p->sg_src_left); | 203 | memcpy(dbuf, sbuf, copy_len); |
204 | copied += p->sg_src_left; | 204 | |
205 | p->sg_src_left = 0; | 205 | p->src_start += copy_len; |
206 | if (copied >= len) | 206 | p->sg_src_left -= copy_len; |
207 | break; | 207 | |
208 | } else { | 208 | len -= copy_len; |
209 | int copy_len = len - copied; | 209 | dbuf += copy_len; |
210 | memcpy(dbuf + copied, sbuf, copy_len); | ||
211 | p->src_start += copy_len; | ||
212 | p->sg_src_left -= copy_len; | ||
213 | break; | ||
214 | } | ||
215 | } | 210 | } |
216 | } | 211 | } |
217 | 212 | ||