crypto: amcc - check return value of sg_nents_for_len
authorLABBE Corentin <clabbe.montjoie@gmail.com>
Wed, 4 Nov 2015 20:13:39 +0000 (21:13 +0100)
committerHerbert Xu <herbert@gondor.apana.org.au>
Tue, 17 Nov 2015 14:00:38 +0000 (22:00 +0800)
The sg_nents_for_len() function could fail, this patch add a check for
its return value.

Signed-off-by: LABBE Corentin <clabbe.montjoie@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/amcc/crypto4xx_core.c

index 58a630e55d5d601d7afc844626a9a7f92ff948ab..62134c8a226091c1a57d3d1687acd26e84ee3dcd 100644 (file)
@@ -781,6 +781,10 @@ u32 crypto4xx_build_pd(struct crypto_async_request *req,
 
        /* figure how many gd is needed */
        num_gd = sg_nents_for_len(src, datalen);
+       if ((int)num_gd < 0) {
+               dev_err(dev->core_dev->device, "Invalid number of src SG.\n");
+               return -EINVAL;
+       }
        if (num_gd == 1)
                num_gd = 0;