Skip to content

Commit

Permalink
crypto: qce - Fix dma_map_sg error check
Browse files Browse the repository at this point in the history
dma_map_sg return 0 on error, fix the error check and return -EIO to
caller.

Cc: Thara Gopinath <[email protected]>
Cc: Herbert Xu <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

Signed-off-by: Jack Wang <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
jinpuwang authored and herbertx committed Aug 26, 2022
1 parent 66f0b6b commit 417f62f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions drivers/crypto/qce/aead.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ qce_aead_async_req_handle(struct crypto_async_request *async_req)
if (ret)
return ret;
dst_nents = dma_map_sg(qce->dev, rctx->dst_sg, rctx->dst_nents, dir_dst);
if (dst_nents < 0) {
ret = dst_nents;
if (!dst_nents) {
ret = -EIO;
goto error_free;
}

Expand Down
8 changes: 5 additions & 3 deletions drivers/crypto/qce/sha.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,16 @@ static int qce_ahash_async_req_handle(struct crypto_async_request *async_req)
}

ret = dma_map_sg(qce->dev, req->src, rctx->src_nents, DMA_TO_DEVICE);
if (ret < 0)
return ret;
if (!ret)
return -EIO;

sg_init_one(&rctx->result_sg, qce->dma.result_buf, QCE_RESULT_BUF_SZ);

ret = dma_map_sg(qce->dev, &rctx->result_sg, 1, DMA_FROM_DEVICE);
if (ret < 0)
if (!ret) {
ret = -EIO;
goto error_unmap_src;
}

ret = qce_dma_prep_sgs(&qce->dma, req->src, rctx->src_nents,
&rctx->result_sg, 1, qce_ahash_done, async_req);
Expand Down
8 changes: 4 additions & 4 deletions drivers/crypto/qce/skcipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ qce_skcipher_async_req_handle(struct crypto_async_request *async_req)
rctx->dst_sg = rctx->dst_tbl.sgl;

dst_nents = dma_map_sg(qce->dev, rctx->dst_sg, rctx->dst_nents, dir_dst);
if (dst_nents < 0) {
ret = dst_nents;
if (!dst_nents) {
ret = -EIO;
goto error_free;
}

if (diff_dst) {
src_nents = dma_map_sg(qce->dev, req->src, rctx->src_nents, dir_src);
if (src_nents < 0) {
ret = src_nents;
if (!src_nents) {
ret = -EIO;
goto error_unmap_dst;
}
rctx->src_sg = req->src;
Expand Down

0 comments on commit 417f62f

Please sign in to comment.