[PATCH] spi: add null check before pointer dereference

Subsystems: arm/samsung s3c, s5p and exynos arm architectures, samsung spi drivers, spi subsystem, the rest

STALE3384d

5 messages, 4 authors, 2017-05-30 · open the first message on its own page

[PATCH] spi: add null check before pointer dereference

From: Gustavo A. R. Silva <hidden>
Date: 2017-05-23 00:25:13

Add null check before dereferencing pointer desc

Addresses-Coverity-ID: 1397997
Signed-off-by: Gustavo A. R. Silva <redacted>
---
 drivers/spi/spi-s3c64xx.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c
index b392cca..9f1013e 100644
--- a/drivers/spi/spi-s3c64xx.c
+++ b/drivers/spi/spi-s3c64xx.c
@@ -306,6 +306,12 @@ static void prepare_dma(struct s3c64xx_spi_dma_data *dma,
 	desc = dmaengine_prep_slave_sg(dma->ch, sgt->sgl, sgt->nents,
 				       dma->direction, DMA_PREP_INTERRUPT);
 
+	if (!desc) {
+		dev_err(&sdd->master->dev,
+			"%s:dmaengine_prep_slave_sg Failed\n", __func__);
+		return;
+	}
+
 	desc->callback = s3c64xx_spi_dmacb;
 	desc->callback_param = dma;
 
-- 
2.5.0

Re: [PATCH] spi: add null check before pointer dereference

From: Krzysztof Kozlowski <krzk@kernel.org>
Date: 2017-05-23 07:24:38

On Tue, May 23, 2017 at 2:25 AM, Gustavo A. R. Silva
[off-list ref] wrote:
quoted hunk
Add null check before dereferencing pointer desc

Addresses-Coverity-ID: 1397997
Signed-off-by: Gustavo A. R. Silva <redacted>
---
 drivers/spi/spi-s3c64xx.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c
index b392cca..9f1013e 100644
--- a/drivers/spi/spi-s3c64xx.c
+++ b/drivers/spi/spi-s3c64xx.c
@@ -306,6 +306,12 @@ static void prepare_dma(struct s3c64xx_spi_dma_data *dma,
        desc = dmaengine_prep_slave_sg(dma->ch, sgt->sgl, sgt->nents,
                                       dma->direction, DMA_PREP_INTERRUPT);

+       if (!desc) {
+               dev_err(&sdd->master->dev,
+                       "%s:dmaengine_prep_slave_sg Failed\n", __func__);
+               return;
+       }
Although the check itself looks needed, but I think you did not handle
the error at all. You just bail out before submitting dma descriptor
but except that, everything else goes like there was no error. It
might work, might not... did you test this error path? How does it
behave?

Best regards,
Krzysztof

Re: [PATCH] spi: add null check before pointer dereference

From: Geert Uytterhoeven <geert@linux-m68k.org>
Date: 2017-05-23 07:33:30

On Tue, May 23, 2017 at 9:24 AM, Krzysztof Kozlowski [off-list ref] wrote:
On Tue, May 23, 2017 at 2:25 AM, Gustavo A. R. Silva
[off-list ref] wrote:
quoted
Add null check before dereferencing pointer desc

Addresses-Coverity-ID: 1397997
Signed-off-by: Gustavo A. R. Silva <redacted>
---
 drivers/spi/spi-s3c64xx.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c
index b392cca..9f1013e 100644
--- a/drivers/spi/spi-s3c64xx.c
+++ b/drivers/spi/spi-s3c64xx.c
@@ -306,6 +306,12 @@ static void prepare_dma(struct s3c64xx_spi_dma_data *dma,
        desc = dmaengine_prep_slave_sg(dma->ch, sgt->sgl, sgt->nents,
                                       dma->direction, DMA_PREP_INTERRUPT);

+       if (!desc) {
+               dev_err(&sdd->master->dev,
+                       "%s:dmaengine_prep_slave_sg Failed\n", __func__);
+               return;
+       }
Although the check itself looks needed, but I think you did not handle
the error at all. You just bail out before submitting dma descriptor
but except that, everything else goes like there was no error. It
might work, might not... did you test this error path? How does it
behave?
I.e. does it fall back to PIO?

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

Re: [PATCH] spi: add null check before pointer dereference

From: Andi Shyti <hidden>
Date: 2017-05-29 03:59:31

Hi Gustavo,
 	desc = dmaengine_prep_slave_sg(dma->ch, sgt->sgl, sgt->nents,
 				       dma->direction, DMA_PREP_INTERRUPT);
 
+	if (!desc) {
+		dev_err(&sdd->master->dev,
+			"%s:dmaengine_prep_slave_sg Failed\n", __func__);
+		return;
+	}
+
I'm sorry, I would nack this patch for now. There was a smilar I
sent before, but, as Krzysztof said, this needs more testing and
a proper solution.

That's anyway in my todo list.

Thanks,
Andi

Re: [PATCH] spi: add null check before pointer dereference

From: Gustavo A. R. Silva <hidden>
Date: 2017-05-30 02:33:22

Hi Andi,

Quoting Andi Shyti [off-list ref]:
Hi Gustavo,
quoted
 	desc = dmaengine_prep_slave_sg(dma->ch, sgt->sgl, sgt->nents,
 				       dma->direction, DMA_PREP_INTERRUPT);

+	if (!desc) {
+		dev_err(&sdd->master->dev,
+			"%s:dmaengine_prep_slave_sg Failed\n", __func__);
+		return;
+	}
+
I'm sorry, I would nack this patch for now. There was a smilar I
sent before, but, as Krzysztof said, this needs more testing and
a proper solution.
Yeah, I get it.
That's anyway in my todo list.
That's great.
Thanks,
Andi
Thanks!
--
Gustavo A. R. Silva
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help