Message ID | 20220825072421.29020-1-jinpu.wang@ionos.com |
---|---|
Headers | show |
Series | Crypto: Fix dma_map_sg error check | expand |
On Thu, Aug 25, 2022 at 09:24:16AM +0200, Jack Wang wrote: > dma_map_sg return 0 on error. > > Cc: Corentin Labbe <clabbe@baylibre.com> > Cc: Hans Ulli Kroll <ulli.kroll@googlemail.com> > Cc: Linus Walleij <linus.walleij@linaro.org> > Cc: Herbert Xu <herbert@gondor.apana.org.au> > Cc: "David S. Miller" <davem@davemloft.net> > Cc: linux-crypto@vger.kernel.org > Cc: linux-arm-kernel@lists.infradead.org > Cc: linux-kernel@vger.kernel.org > Fixes: 46c5338db7bd ("crypto: sl3516 - Add sl3516 crypto engine") > Signed-off-by: Jack Wang <jinpu.wang@ionos.com> > --- > drivers/crypto/gemini/sl3516-ce-cipher.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/crypto/gemini/sl3516-ce-cipher.c b/drivers/crypto/gemini/sl3516-ce-cipher.c > index 14d0d83d388d..34fea8aa91b6 100644 > --- a/drivers/crypto/gemini/sl3516-ce-cipher.c > +++ b/drivers/crypto/gemini/sl3516-ce-cipher.c > @@ -149,7 +149,7 @@ static int sl3516_ce_cipher(struct skcipher_request *areq) > if (areq->src == areq->dst) { > nr_sgs = dma_map_sg(ce->dev, areq->src, sg_nents(areq->src), > DMA_BIDIRECTIONAL); > - if (nr_sgs <= 0 || nr_sgs > MAXDESC / 2) { > + if (!nr_sgs || nr_sgs > MAXDESC / 2) { > dev_err(ce->dev, "Invalid sg number %d\n", nr_sgs); > err = -EINVAL; > goto theend; The original code is correct and this patch is arguably making it less robust. So I'll drop this particular patch. Thanks,
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/20220818105355.110344-1-haris.iqbal@ionos.com/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,