diff options
author | LABBE Corentin <clabbe.montjoie@gmail.com> | 2015-11-04 15:13:36 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2015-11-17 09:00:36 -0500 |
commit | 4fa9948ca5bf308fabd5c9b584bf710f5d393859 (patch) | |
tree | 94d2ee7a7b27ab82fe1ad1cd0db09f549846602f | |
parent | 6c2b74d4774f36ea23f9cc8bb1401c1215fcd671 (diff) |
crypto: qce - check return value of sg_nents_for_len
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>
-rw-r--r-- | drivers/crypto/qce/ablkcipher.c | 8 | ||||
-rw-r--r-- | drivers/crypto/qce/sha.c | 5 |
2 files changed, 13 insertions, 0 deletions
diff --git a/drivers/crypto/qce/ablkcipher.c b/drivers/crypto/qce/ablkcipher.c index 2c0d63d48747..dbcbbe242bd6 100644 --- a/drivers/crypto/qce/ablkcipher.c +++ b/drivers/crypto/qce/ablkcipher.c | |||
@@ -83,6 +83,14 @@ qce_ablkcipher_async_req_handle(struct crypto_async_request *async_req) | |||
83 | rctx->dst_nents = sg_nents_for_len(req->dst, req->nbytes); | 83 | rctx->dst_nents = sg_nents_for_len(req->dst, req->nbytes); |
84 | else | 84 | else |
85 | rctx->dst_nents = rctx->src_nents; | 85 | rctx->dst_nents = rctx->src_nents; |
86 | if (rctx->src_nents < 0) { | ||
87 | dev_err(qce->dev, "Invalid numbers of src SG.\n"); | ||
88 | return rctx->src_nents; | ||
89 | } | ||
90 | if (rctx->dst_nents < 0) { | ||
91 | dev_err(qce->dev, "Invalid numbers of dst SG.\n"); | ||
92 | return -rctx->dst_nents; | ||
93 | } | ||
86 | 94 | ||
87 | rctx->dst_nents += 1; | 95 | rctx->dst_nents += 1; |
88 | 96 | ||
diff --git a/drivers/crypto/qce/sha.c b/drivers/crypto/qce/sha.c index 0c9973ec80eb..47e114ac09d0 100644 --- a/drivers/crypto/qce/sha.c +++ b/drivers/crypto/qce/sha.c | |||
@@ -92,6 +92,11 @@ static int qce_ahash_async_req_handle(struct crypto_async_request *async_req) | |||
92 | } | 92 | } |
93 | 93 | ||
94 | rctx->src_nents = sg_nents_for_len(req->src, req->nbytes); | 94 | rctx->src_nents = sg_nents_for_len(req->src, req->nbytes); |
95 | if (rctx->src_nents < 0) { | ||
96 | dev_err(qce->dev, "Invalid numbers of src SG.\n"); | ||
97 | return rctx->src_nents; | ||
98 | } | ||
99 | |||
95 | ret = dma_map_sg(qce->dev, req->src, rctx->src_nents, DMA_TO_DEVICE); | 100 | ret = dma_map_sg(qce->dev, req->src, rctx->src_nents, DMA_TO_DEVICE); |
96 | if (ret < 0) | 101 | if (ret < 0) |
97 | return ret; | 102 | return ret; |