linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] mtd: rawnand: Fix dma_map_sg error check
@ 2022-08-25  7:53 Jack Wang
  2022-08-25  7:53 ` [PATCH 1/2] mtd: rawnand: stm32_fmc2: " Jack Wang
  2022-08-25  7:53 ` [PATCH 2/2] mtd: rawnand: marvell: Fix error handle regarding dma_map_sg Jack Wang
  0 siblings, 2 replies; 4+ messages in thread
From: Jack Wang @ 2022-08-25  7:53 UTC (permalink / raw)
  To: miquel.raynal, linux-mtd

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 mtd subsystem.

Thanks!

[1] https://lore.kernel.org/linux-rdma/20220818105355.110344-1-haris.iqbal@ionos.com/T/#t

Jack Wang (2):
  mtd: rawnand: stm32_fmc2: Fix dma_map_sg error check
  mtd: rawnand: marvell: Fix error handle regarding dma_map_sg

 drivers/mtd/nand/raw/marvell_nand.c    | 8 +++++++-
 drivers/mtd/nand/raw/stm32_fmc2_nand.c | 8 +++++---
 2 files changed, 12 insertions(+), 4 deletions(-)

-- 
2.34.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] mtd: rawnand: stm32_fmc2: Fix dma_map_sg error check
  2022-08-25  7:53 [PATCH 0/2] mtd: rawnand: Fix dma_map_sg error check Jack Wang
@ 2022-08-25  7:53 ` Jack Wang
  2022-09-19 16:00   ` Miquel Raynal
  2022-08-25  7:53 ` [PATCH 2/2] mtd: rawnand: marvell: Fix error handle regarding dma_map_sg Jack Wang
  1 sibling, 1 reply; 4+ messages in thread
From: Jack Wang @ 2022-08-25  7:53 UTC (permalink / raw)
  To: miquel.raynal, linux-mtd
  Cc: Richard Weinberger, Vignesh Raghavendra, Maxime Coquelin,
	Alexandre Torgue, Philipp Zabel, Christophe Kerello, Cai Huoqing,
	linux-stm32, linux-arm-kernel, linux-kernel

dma_map_sg return 0 on error, in case of error return -EIO.

Cc: Miquel Raynal <miquel.raynal@bootlin.com>
Cc: Richard Weinberger <richard@nod.at>
Cc: Vignesh Raghavendra <vigneshr@ti.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: Philipp Zabel <p.zabel@pengutronix.de>
Cc: Christophe Kerello <christophe.kerello@foss.st.com>
Cc: Cai Huoqing <cai.huoqing@linux.dev>
Cc: linux-mtd@lists.infradead.org
Cc: linux-stm32@st-md-mailman.stormreply.com
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Fixes: 2cd457f328c1 ("mtd: rawnand: stm32_fmc2: add STM32 FMC2 NAND flash controller driver")
Signed-off-by: Jack Wang <jinpu.wang@ionos.com>
---
 drivers/mtd/nand/raw/stm32_fmc2_nand.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/nand/raw/stm32_fmc2_nand.c b/drivers/mtd/nand/raw/stm32_fmc2_nand.c
index 87c1c7dd97eb..a0c825af19fa 100644
--- a/drivers/mtd/nand/raw/stm32_fmc2_nand.c
+++ b/drivers/mtd/nand/raw/stm32_fmc2_nand.c
@@ -862,8 +862,8 @@ static int stm32_fmc2_nfc_xfer(struct nand_chip *chip, const u8 *buf,
 
 	ret = dma_map_sg(nfc->dev, nfc->dma_data_sg.sgl,
 			 eccsteps, dma_data_dir);
-	if (ret < 0)
-		return ret;
+	if (!ret)
+		return -EIO;
 
 	desc_data = dmaengine_prep_slave_sg(dma_ch, nfc->dma_data_sg.sgl,
 					    eccsteps, dma_transfer_dir,
@@ -893,8 +893,10 @@ static int stm32_fmc2_nfc_xfer(struct nand_chip *chip, const u8 *buf,
 
 		ret = dma_map_sg(nfc->dev, nfc->dma_ecc_sg.sgl,
 				 eccsteps, dma_data_dir);
-		if (ret < 0)
+		if (!ret) {
+			ret = -EIO;
 			goto err_unmap_data;
+		}
 
 		desc_ecc = dmaengine_prep_slave_sg(nfc->dma_ecc_ch,
 						   nfc->dma_ecc_sg.sgl,
-- 
2.34.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] mtd: rawnand: marvell: Fix error handle regarding dma_map_sg
  2022-08-25  7:53 [PATCH 0/2] mtd: rawnand: Fix dma_map_sg error check Jack Wang
  2022-08-25  7:53 ` [PATCH 1/2] mtd: rawnand: stm32_fmc2: " Jack Wang
@ 2022-08-25  7:53 ` Jack Wang
  1 sibling, 0 replies; 4+ messages in thread
From: Jack Wang @ 2022-08-25  7:53 UTC (permalink / raw)
  To: miquel.raynal, linux-mtd
  Cc: Richard Weinberger, Vignesh Raghavendra, Maxime Coquelin,
	Alexandre Torgue, Philipp Zabel, Christophe Kerello, Cai Huoqing,
	linux-stm32, linux-arm-kernel, linux-kernel

dma_map_sg return 0 on error, in case of error return -ENXIO,
also add the dma_unmap_sg as rollback on the following error.

Cc: Miquel Raynal <miquel.raynal@bootlin.com>
Cc: Richard Weinberger <richard@nod.at>
Cc: Vignesh Raghavendra <vigneshr@ti.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: Philipp Zabel <p.zabel@pengutronix.de>
Cc: Christophe Kerello <christophe.kerello@foss.st.com>
Cc: Cai Huoqing <cai.huoqing@linux.dev>
Cc: linux-mtd@lists.infradead.org
Cc: linux-stm32@st-md-mailman.stormreply.com
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Fixes: 02f26ecf8c77 ("mtd: nand: add reworked Marvell NAND controller driver")
Signed-off-by: Jack Wang <jinpu.wang@ionos.com>
---
 drivers/mtd/nand/raw/marvell_nand.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/raw/marvell_nand.c b/drivers/mtd/nand/raw/marvell_nand.c
index 2455a581fd70..d9f2f1d0b5ef 100644
--- a/drivers/mtd/nand/raw/marvell_nand.c
+++ b/drivers/mtd/nand/raw/marvell_nand.c
@@ -865,13 +865,19 @@ static int marvell_nfc_xfer_data_dma(struct marvell_nfc *nfc,
 	marvell_nfc_enable_dma(nfc);
 	/* Prepare the DMA transfer */
 	sg_init_one(&sg, nfc->dma_buf, dma_len);
-	dma_map_sg(nfc->dma_chan->device->dev, &sg, 1, direction);
+	ret = dma_map_sg(nfc->dma_chan->device->dev, &sg, 1, direction);
+	if (!ret) {
+		dev_err(nfc->dev, "Could not map DMA S/G list\n");
+		return -ENXIO;
+	}
+
 	tx = dmaengine_prep_slave_sg(nfc->dma_chan, &sg, 1,
 				     direction == DMA_FROM_DEVICE ?
 				     DMA_DEV_TO_MEM : DMA_MEM_TO_DEV,
 				     DMA_PREP_INTERRUPT);
 	if (!tx) {
 		dev_err(nfc->dev, "Could not prepare DMA S/G list\n");
+		dma_unmap_sg(nfc->dma_chan->device->dev, &sg, 1, direction);
 		return -ENXIO;
 	}
 
-- 
2.34.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] mtd: rawnand: stm32_fmc2: Fix dma_map_sg error check
  2022-08-25  7:53 ` [PATCH 1/2] mtd: rawnand: stm32_fmc2: " Jack Wang
@ 2022-09-19 16:00   ` Miquel Raynal
  0 siblings, 0 replies; 4+ messages in thread
From: Miquel Raynal @ 2022-09-19 16:00 UTC (permalink / raw)
  To: Jack Wang
  Cc: linux-mtd, Richard Weinberger, Vignesh Raghavendra,
	Maxime Coquelin, Alexandre Torgue, Philipp Zabel,
	Christophe Kerello, Cai Huoqing, linux-stm32, linux-arm-kernel,
	linux-kernel

Hi Jack,

jinpu.wang@ionos.com wrote on Thu, 25 Aug 2022 09:53:37 +0200:

> dma_map_sg return 0 on error, in case of error return -EIO.
> 
> Cc: Miquel Raynal <miquel.raynal@bootlin.com>
> Cc: Richard Weinberger <richard@nod.at>
> Cc: Vignesh Raghavendra <vigneshr@ti.com>
> Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
> Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
> Cc: Philipp Zabel <p.zabel@pengutronix.de>
> Cc: Christophe Kerello <christophe.kerello@foss.st.com>
> Cc: Cai Huoqing <cai.huoqing@linux.dev>
> Cc: linux-mtd@lists.infradead.org
> Cc: linux-stm32@st-md-mailman.stormreply.com
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-kernel@vger.kernel.org
> Fixes: 2cd457f328c1 ("mtd: rawnand: stm32_fmc2: add STM32 FMC2 NAND flash controller driver")
> Signed-off-by: Jack Wang <jinpu.wang@ionos.com>

I'll apply this series so I need to re-add Christophe's tag sent on the
patch alone (which is identical as far as I see):

Reviewed-by: Christophe Kerello <christophe.kerello@foss.st.com>

> ---
>  drivers/mtd/nand/raw/stm32_fmc2_nand.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/mtd/nand/raw/stm32_fmc2_nand.c b/drivers/mtd/nand/raw/stm32_fmc2_nand.c
> index 87c1c7dd97eb..a0c825af19fa 100644
> --- a/drivers/mtd/nand/raw/stm32_fmc2_nand.c
> +++ b/drivers/mtd/nand/raw/stm32_fmc2_nand.c
> @@ -862,8 +862,8 @@ static int stm32_fmc2_nfc_xfer(struct nand_chip *chip, const u8 *buf,
>  
>  	ret = dma_map_sg(nfc->dev, nfc->dma_data_sg.sgl,
>  			 eccsteps, dma_data_dir);
> -	if (ret < 0)
> -		return ret;
> +	if (!ret)
> +		return -EIO;
>  
>  	desc_data = dmaengine_prep_slave_sg(dma_ch, nfc->dma_data_sg.sgl,
>  					    eccsteps, dma_transfer_dir,
> @@ -893,8 +893,10 @@ static int stm32_fmc2_nfc_xfer(struct nand_chip *chip, const u8 *buf,
>  
>  		ret = dma_map_sg(nfc->dev, nfc->dma_ecc_sg.sgl,
>  				 eccsteps, dma_data_dir);
> -		if (ret < 0)
> +		if (!ret) {
> +			ret = -EIO;
>  			goto err_unmap_data;
> +		}
>  
>  		desc_ecc = dmaengine_prep_slave_sg(nfc->dma_ecc_ch,
>  						   nfc->dma_ecc_sg.sgl,


Thanks,
Miquèl

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-09-19 16:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-25  7:53 [PATCH 0/2] mtd: rawnand: Fix dma_map_sg error check Jack Wang
2022-08-25  7:53 ` [PATCH 1/2] mtd: rawnand: stm32_fmc2: " Jack Wang
2022-09-19 16:00   ` Miquel Raynal
2022-08-25  7:53 ` [PATCH 2/2] mtd: rawnand: marvell: Fix error handle regarding dma_map_sg Jack Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).