]> git.karo-electronics.de Git - linux-beck.git/commitdiff
crypto: atmel-sha - fix sg list management
authorLeilei Zhao <leilei.zhao@atmel.com>
Tue, 7 Apr 2015 09:45:05 +0000 (17:45 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Wed, 8 Apr 2015 14:20:02 +0000 (22:20 +0800)
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>
drivers/crypto/atmel-sha.c

index 215858a829c3f9792a99ba63de988caa164144fa..b093862eebf397be7584fe65422bcbd5ac787498 100644 (file)
@@ -163,8 +163,20 @@ static size_t atmel_sha_append_sg(struct atmel_sha_reqctx *ctx)
                count = min(ctx->sg->length - ctx->offset, ctx->total);
                count = min(count, ctx->buflen - ctx->bufcnt);
 
-               if (count <= 0)
-                       break;
+               if (count <= 0) {
+                       /*
+                       * Check if count <= 0 because the buffer is full or
+                       * because the sg length is 0. In the latest case,
+                       * check if there is another sg in the list, a 0 length
+                       * sg doesn't necessarily mean the end of the sg list.
+                       */
+                       if ((ctx->sg->length == 0) && !sg_is_last(ctx->sg)) {
+                               ctx->sg = sg_next(ctx->sg);
+                               continue;
+                       } else {
+                               break;
+                       }
+               }
 
                scatterwalk_map_and_copy(ctx->buffer + ctx->bufcnt, ctx->sg,
                        ctx->offset, count, 0);