aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/crypto/atmel-sha.c
diff options
context:
space:
mode:
authorLeilei Zhao <leilei.zhao@atmel.com>2015-04-07 05:45:05 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2015-04-08 10:20:02 -0400
commit803eeae8f3eb394d898a7aa65ba706628dd6a85c (patch)
tree52e3a4f22974040a558543f2a13c0f71b3273c63 /drivers/crypto/atmel-sha.c
parent0099286b664493c85f0f2248f09f3b467a0e3a78 (diff)
crypto: atmel-sha - fix sg list management
Having a zero length sg doesn't mean it is the end of the sg list. This case happens when calculating HMAC of IPSec packet. Signed-off-by: Leilei Zhao <leilei.zhao@atmel.com> Signed-off-by: Ludovic Desroches <ludovic.desroches@atmel.com> Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto/atmel-sha.c')
-rw-r--r--drivers/crypto/atmel-sha.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/drivers/crypto/atmel-sha.c b/drivers/crypto/atmel-sha.c
index 215858a829c3..b093862eebf3 100644
--- a/drivers/crypto/atmel-sha.c
+++ b/drivers/crypto/atmel-sha.c
@@ -163,8 +163,20 @@ static size_t atmel_sha_append_sg(struct atmel_sha_reqctx *ctx)
163 count = min(ctx->sg->length - ctx->offset, ctx->total); 163 count = min(ctx->sg->length - ctx->offset, ctx->total);
164 count = min(count, ctx->buflen - ctx->bufcnt); 164 count = min(count, ctx->buflen - ctx->bufcnt);
165 165
166 if (count <= 0) 166 if (count <= 0) {
167 break; 167 /*
168 * Check if count <= 0 because the buffer is full or
169 * because the sg length is 0. In the latest case,
170 * check if there is another sg in the list, a 0 length
171 * sg doesn't necessarily mean the end of the sg list.
172 */
173 if ((ctx->sg->length == 0) && !sg_is_last(ctx->sg)) {
174 ctx->sg = sg_next(ctx->sg);
175 continue;
176 } else {
177 break;
178 }
179 }
168 180
169 scatterwalk_map_and_copy(ctx->buffer + ctx->bufcnt, ctx->sg, 181 scatterwalk_map_and_copy(ctx->buffer + ctx->bufcnt, ctx->sg,
170 ctx->offset, count, 0); 182 ctx->offset, count, 0);