Hi, all,
While working on a bugfix on RTRS[1], I noticed there are quite a few other
drivers have the same problem, due to the fact dma_map_sg return 0 on error,
not like most of the cases, return negative value for error.
I "grep -A 5 dma_map_sg' in kernel tree, and audit/fix the one I feel is buggy,
hence this patchset. As suggested by Christoph Hellwig, I now send the patches per
subsystem, this is for crypto subsystem.
Thanks!
[1] https://lore.kernel.org/linux-rdma/[email protected]/T/#t
Jack Wang (6):
crypto: gemin: Fix error check for dma_map_sg
crypto: sahara: Fix error check for dma_map_sg
crypto: qce: Fix dma_map_sg error check
crypto: amlogic: Fix dma_map_sg error check
crypto: allwinner: Fix dma_map_sg error check
crypto: ccree: Fix dma_map_sg error check
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c | 6 +++---
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c | 2 +-
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c | 4 ++--
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c | 2 +-
drivers/crypto/amlogic/amlogic-gxl-cipher.c | 6 +++---
drivers/crypto/ccree/cc_buffer_mgr.c | 2 +-
drivers/crypto/gemini/sl3516-ce-cipher.c | 6 +++---
drivers/crypto/qce/aead.c | 4 ++--
drivers/crypto/qce/sha.c | 8 +++++---
drivers/crypto/qce/skcipher.c | 8 ++++----
drivers/crypto/sahara.c | 4 ++--
11 files changed, 27 insertions(+), 25 deletions(-)
--
2.34.1
dma_map_sg return 0 on error.
Cc: Corentin Labbe <[email protected]>
Cc: Herbert Xu <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Fixes: 48fe583fe541 ("crypto: amlogic - Add crypto accelerator for amlogic GXL")
Signed-off-by: Jack Wang <[email protected]>
---
drivers/crypto/amlogic/amlogic-gxl-cipher.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c
index e79514fce731..af017a087ebf 100644
--- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c
+++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c
@@ -177,7 +177,7 @@ static int meson_cipher(struct skcipher_request *areq)
if (areq->src == areq->dst) {
nr_sgs = dma_map_sg(mc->dev, areq->src, sg_nents(areq->src),
DMA_BIDIRECTIONAL);
- if (nr_sgs < 0) {
+ if (!nr_sgs) {
dev_err(mc->dev, "Invalid SG count %d\n", nr_sgs);
err = -EINVAL;
goto theend;
@@ -186,14 +186,14 @@ static int meson_cipher(struct skcipher_request *areq)
} else {
nr_sgs = dma_map_sg(mc->dev, areq->src, sg_nents(areq->src),
DMA_TO_DEVICE);
- if (nr_sgs < 0 || nr_sgs > MAXDESC - 3) {
+ if (!nr_sgs || nr_sgs > MAXDESC - 3) {
dev_err(mc->dev, "Invalid SG count %d\n", nr_sgs);
err = -EINVAL;
goto theend;
}
nr_sgd = dma_map_sg(mc->dev, areq->dst, sg_nents(areq->dst),
DMA_FROM_DEVICE);
- if (nr_sgd < 0 || nr_sgd > MAXDESC - 3) {
+ if (!nr_sgd || nr_sgd > MAXDESC - 3) {
dev_err(mc->dev, "Invalid SG count %d\n", nr_sgd);
err = -EINVAL;
goto theend;
--
2.34.1
On Thu, Aug 25, 2022 at 09:24:15AM +0200, Jack Wang wrote:
> Hi, all,
>
> While working on a bugfix on RTRS[1], I noticed there are quite a few other
> drivers have the same problem, due to the fact dma_map_sg return 0 on error,
> not like most of the cases, return negative value for error.
>
> I "grep -A 5 dma_map_sg' in kernel tree, and audit/fix the one I feel is buggy,
> hence this patchset. As suggested by Christoph Hellwig, I now send the patches per
> subsystem, this is for crypto subsystem.
>
> Thanks!
>
> [1] https://lore.kernel.org/linux-rdma/[email protected]/T/#t
>
>
> Jack Wang (6):
> crypto: gemin: Fix error check for dma_map_sg
> crypto: sahara: Fix error check for dma_map_sg
> crypto: qce: Fix dma_map_sg error check
> crypto: amlogic: Fix dma_map_sg error check
> crypto: allwinner: Fix dma_map_sg error check
> crypto: ccree: Fix dma_map_sg error check
>
> drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c | 6 +++---
> drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c | 2 +-
> drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c | 4 ++--
> drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c | 2 +-
> drivers/crypto/amlogic/amlogic-gxl-cipher.c | 6 +++---
> drivers/crypto/ccree/cc_buffer_mgr.c | 2 +-
> drivers/crypto/gemini/sl3516-ce-cipher.c | 6 +++---
> drivers/crypto/qce/aead.c | 4 ++--
> drivers/crypto/qce/sha.c | 8 +++++---
> drivers/crypto/qce/skcipher.c | 8 ++++----
> drivers/crypto/sahara.c | 4 ++--
> 11 files changed, 27 insertions(+), 25 deletions(-)
These patches have already been applied to cryptodev. However,
upon further reflection I have decided to revert two of the patches
which actually made the code less robust.
Thanks,
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt