Message ID | 20200819123208.12337-7-l.stelmach@samsung.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [1/8] spi: spi-s3c64xx: swap s3c64xx_spi_set_cs() and s3c64xx_enable_datapath() | expand |
On Wed, Aug 19, 2020 at 02:32:06PM +0200, Łukasz Stelmach wrote: > Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com> > --- > drivers/spi/spi-s3c64xx.c | 12 ++++++++++++ > 1 file changed, 12 insertions(+) Oh, come on, stop fixing the same local issue without fixing bigger picture... or at least documenting why bigger picture does not have to be fixed and simple 'return' is enough. That's the third, same fix for the same problem. https://lore.kernel.org/lkml/20190314064202.14864-1-kjlu@umn.edu/ https://lore.kernel.org/lkml/20170207204520.h2eo3yn5kge56lk7@kozik-lap/ Best regards, Krzysztof > > diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c > index 505789f91fdf..27d77600a820 100644 > --- a/drivers/spi/spi-s3c64xx.c > +++ b/drivers/spi/spi-s3c64xx.c > @@ -273,6 +273,7 @@ static void prepare_dma(struct s3c64xx_spi_dma_data *dma, > struct s3c64xx_spi_driver_data *sdd; > struct dma_slave_config config; > struct dma_async_tx_descriptor *desc; > + int ret; > > memset(&config, 0, sizeof(config)); > > @@ -296,11 +297,22 @@ 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->pdev->dev, "unable to prepare %s scatterlist", > + dma->direction == DMA_DEV_TO_MEM ? "rx" : "tx"); > + return; > + } > > desc->callback = s3c64xx_spi_dmacb; > desc->callback_param = dma; > > dma->cookie = dmaengine_submit(desc); > + ret = dma_submit_error(dma->cookie); > + if (ret) { > + dev_err(&sdd->pdev->dev, "dmaengine_submit() failed %d", ret); > + return; > + } > + > dma_async_issue_pending(dma->ch); > } > > -- > 2.26.2 >
It was <2020-08-19 śro 14:48>, when Krzysztof Kozlowski wrote: > On Wed, Aug 19, 2020 at 02:32:06PM +0200, Łukasz Stelmach wrote: >> Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com> >> --- >> drivers/spi/spi-s3c64xx.c | 12 ++++++++++++ >> 1 file changed, 12 insertions(+) > > Oh, come on, stop fixing the same local issue without fixing bigger > picture... or at least documenting why bigger picture does not have to be > fixed and simple 'return' is enough. > > That's the third, same fix for the same problem. > > https://lore.kernel.org/lkml/20190314064202.14864-1-kjlu@umn.edu/ > https://lore.kernel.org/lkml/20170207204520.h2eo3yn5kge56lk7@kozik-lap/ No wonder. There is a possible NULL dereference below. Now at least we know something about conditions that led to this. Should I drop the entire patch, or just the dmaengine_prep_slave_sg() part? >> diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c >> index 505789f91fdf..27d77600a820 100644 >> --- a/drivers/spi/spi-s3c64xx.c >> +++ b/drivers/spi/spi-s3c64xx.c >> @@ -273,6 +273,7 @@ static void prepare_dma(struct s3c64xx_spi_dma_data *dma, >> struct s3c64xx_spi_driver_data *sdd; >> struct dma_slave_config config; >> struct dma_async_tx_descriptor *desc; >> + int ret; >> >> memset(&config, 0, sizeof(config)); >> >> @@ -296,11 +297,22 @@ 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->pdev->dev, "unable to prepare %s scatterlist", >> + dma->direction == DMA_DEV_TO_MEM ? "rx" : "tx"); >> + return; >> + } >> >> desc->callback = s3c64xx_spi_dmacb; >> desc->callback_param = dma; >> >> dma->cookie = dmaengine_submit(desc); >> + ret = dma_submit_error(dma->cookie); >> + if (ret) { >> + dev_err(&sdd->pdev->dev, "dmaengine_submit() failed %d", ret); >> + return; >> + } >> + >> dma_async_issue_pending(dma->ch); >> } >> >> -- >> 2.26.2 >> > >
On Wed, Aug 19, 2020 at 05:41:43PM +0200, Lukasz Stelmach wrote: > It was <2020-08-19 śro 14:48>, when Krzysztof Kozlowski wrote: > > On Wed, Aug 19, 2020 at 02:32:06PM +0200, Łukasz Stelmach wrote: > >> Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com> > >> --- > >> drivers/spi/spi-s3c64xx.c | 12 ++++++++++++ > >> 1 file changed, 12 insertions(+) > > > > Oh, come on, stop fixing the same local issue without fixing bigger > > picture... or at least documenting why bigger picture does not have to be > > fixed and simple 'return' is enough. > > > > That's the third, same fix for the same problem. > > > > https://lore.kernel.org/lkml/20190314064202.14864-1-kjlu@umn.edu/ > > https://lore.kernel.org/lkml/20170207204520.h2eo3yn5kge56lk7@kozik-lap/ > > No wonder. There is a possible NULL dereference below. Now at least we > know something about conditions that led to this. > > Should I drop the entire patch, or just the dmaengine_prep_slave_sg() part? The best would be to really go through the call stack and handle the error properly. This means returning an error code and propagating it further. It is not a trivial change... Best regards, Krzysztof
diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c index 505789f91fdf..27d77600a820 100644 --- a/drivers/spi/spi-s3c64xx.c +++ b/drivers/spi/spi-s3c64xx.c @@ -273,6 +273,7 @@ static void prepare_dma(struct s3c64xx_spi_dma_data *dma, struct s3c64xx_spi_driver_data *sdd; struct dma_slave_config config; struct dma_async_tx_descriptor *desc; + int ret; memset(&config, 0, sizeof(config)); @@ -296,11 +297,22 @@ 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->pdev->dev, "unable to prepare %s scatterlist", + dma->direction == DMA_DEV_TO_MEM ? "rx" : "tx"); + return; + } desc->callback = s3c64xx_spi_dmacb; desc->callback_param = dma; dma->cookie = dmaengine_submit(desc); + ret = dma_submit_error(dma->cookie); + if (ret) { + dev_err(&sdd->pdev->dev, "dmaengine_submit() failed %d", ret); + return; + } + dma_async_issue_pending(dma->ch); }
Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com> --- drivers/spi/spi-s3c64xx.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)