public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block: mtip32xx: Fix usage of dma_map_sg()
@ 2025-06-27 12:11 Thomas Fourier
  2025-06-27 14:08 ` Andy Shevchenko
  2025-07-08 18:00 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Thomas Fourier @ 2025-06-27 12:11 UTC (permalink / raw)
  Cc: Thomas Fourier, Jens Axboe, Philipp Stanner, Anuj Gupta,
	Andy Shevchenko, Al Viro, Li Zetao, Asai Thambi S P, Sam Bradshaw,
	linux-block, linux-kernel

The dma_map_sg() can fail and, in case of failure, returns 0.  If it
fails, mtip_hw_submit_io() returns an error.

The dma_unmap_sg() requires the nents parameter to be the same as the
one passed to dma_map_sg(). This patch saves the nents in
command->scatter_ents.

Fixes: 88523a61558a ("block: Add driver for Micron RealSSD pcie flash cards")
Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com>
---
 drivers/block/mtip32xx/mtip32xx.c | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/drivers/block/mtip32xx/mtip32xx.c b/drivers/block/mtip32xx/mtip32xx.c
index 66ce6b81c7d9..8fc7761397bd 100644
--- a/drivers/block/mtip32xx/mtip32xx.c
+++ b/drivers/block/mtip32xx/mtip32xx.c
@@ -2040,11 +2040,12 @@ static int mtip_hw_ioctl(struct driver_data *dd, unsigned int cmd,
  * @dir      Direction (read or write)
  *
  * return value
- *	None
+ *	0	The IO completed successfully.
+ *	-ENOMEM	The DMA mapping failed.
  */
-static void mtip_hw_submit_io(struct driver_data *dd, struct request *rq,
-			      struct mtip_cmd *command,
-			      struct blk_mq_hw_ctx *hctx)
+static int mtip_hw_submit_io(struct driver_data *dd, struct request *rq,
+			     struct mtip_cmd *command,
+			     struct blk_mq_hw_ctx *hctx)
 {
 	struct mtip_cmd_hdr *hdr =
 		dd->port->command_list + sizeof(struct mtip_cmd_hdr) * rq->tag;
@@ -2056,12 +2057,14 @@ static void mtip_hw_submit_io(struct driver_data *dd, struct request *rq,
 	unsigned int nents;
 
 	/* Map the scatter list for DMA access */
-	nents = blk_rq_map_sg(rq, command->sg);
-	nents = dma_map_sg(&dd->pdev->dev, command->sg, nents, dma_dir);
+	command->scatter_ents = blk_rq_map_sg(rq, command->sg);
+	nents = dma_map_sg(&dd->pdev->dev, command->sg,
+			   command->scatter_ents, dma_dir);
+	if (!nents)
+		return -ENOMEM;
 
-	prefetch(&port->flags);
 
-	command->scatter_ents = nents;
+	prefetch(&port->flags);
 
 	/*
 	 * The number of retries for this command before it is
@@ -2112,11 +2115,13 @@ static void mtip_hw_submit_io(struct driver_data *dd, struct request *rq,
 	if (unlikely(port->flags & MTIP_PF_PAUSE_IO)) {
 		set_bit(rq->tag, port->cmds_to_issue);
 		set_bit(MTIP_PF_ISSUE_CMDS_BIT, &port->flags);
-		return;
+		return 0;
 	}
 
 	/* Issue the command to the hardware */
 	mtip_issue_ncq_command(port, rq->tag);
+
+	return 0;
 }
 
 /*
@@ -3315,7 +3320,9 @@ static blk_status_t mtip_queue_rq(struct blk_mq_hw_ctx *hctx,
 
 	blk_mq_start_request(rq);
 
-	mtip_hw_submit_io(dd, rq, cmd, hctx);
+	if (mtip_hw_submit_io(dd, rq, cmd, hctx))
+		return BLK_STS_IOERR;
+
 	return BLK_STS_OK;
 }
 
-- 
2.43.0


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

* Re: [PATCH] block: mtip32xx: Fix usage of dma_map_sg()
  2025-06-27 12:11 [PATCH] block: mtip32xx: Fix usage of dma_map_sg() Thomas Fourier
@ 2025-06-27 14:08 ` Andy Shevchenko
  2025-07-08 18:00 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2025-06-27 14:08 UTC (permalink / raw)
  To: Thomas Fourier
  Cc: Jens Axboe, Philipp Stanner, Anuj Gupta, Al Viro, Li Zetao,
	Asai Thambi S P, Sam Bradshaw, linux-block, linux-kernel

On Fri, Jun 27, 2025 at 02:11:19PM +0200, Thomas Fourier wrote:
> The dma_map_sg() can fail and, in case of failure, returns 0.  If it
> fails, mtip_hw_submit_io() returns an error.
> 
> The dma_unmap_sg() requires the nents parameter to be the same as the
> one passed to dma_map_sg(). This patch saves the nents in
> command->scatter_ents.

I don't know why I'm in Cc list here, but FWIW,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
with a caveat that I am not an expert at all in these areas. Code
just look okay and doing sane things.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH] block: mtip32xx: Fix usage of dma_map_sg()
  2025-06-27 12:11 [PATCH] block: mtip32xx: Fix usage of dma_map_sg() Thomas Fourier
  2025-06-27 14:08 ` Andy Shevchenko
@ 2025-07-08 18:00 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2025-07-08 18:00 UTC (permalink / raw)
  To: Thomas Fourier
  Cc: Philipp Stanner, Anuj Gupta, Andy Shevchenko, Al Viro, Li Zetao,
	Asai Thambi S P, Sam Bradshaw, linux-block, linux-kernel


On Fri, 27 Jun 2025 14:11:19 +0200, Thomas Fourier wrote:
> The dma_map_sg() can fail and, in case of failure, returns 0.  If it
> fails, mtip_hw_submit_io() returns an error.
> 
> The dma_unmap_sg() requires the nents parameter to be the same as the
> one passed to dma_map_sg(). This patch saves the nents in
> command->scatter_ents.
> 
> [...]

Applied, thanks!

[1/1] block: mtip32xx: Fix usage of dma_map_sg()
      commit: 8e1fab9cccc7b806b0cffdceabb09b310b83b553

Best regards,
-- 
Jens Axboe




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

end of thread, other threads:[~2025-07-08 18:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-27 12:11 [PATCH] block: mtip32xx: Fix usage of dma_map_sg() Thomas Fourier
2025-06-27 14:08 ` Andy Shevchenko
2025-07-08 18:00 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox