Skip to content

Commit 8e1fab9

Browse files
Thomas-fourieraxboe
authored andcommitted
block: mtip32xx: Fix usage of dma_map_sg()
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: 88523a6 ("block: Add driver for Micron RealSSD pcie flash cards") Signed-off-by: Thomas Fourier <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 5a593de commit 8e1fab9

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

drivers/block/mtip32xx/mtip32xx.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,11 +2040,12 @@ static int mtip_hw_ioctl(struct driver_data *dd, unsigned int cmd,
20402040
* @dir Direction (read or write)
20412041
*
20422042
* return value
2043-
* None
2043+
* 0 The IO completed successfully.
2044+
* -ENOMEM The DMA mapping failed.
20442045
*/
2045-
static void mtip_hw_submit_io(struct driver_data *dd, struct request *rq,
2046-
struct mtip_cmd *command,
2047-
struct blk_mq_hw_ctx *hctx)
2046+
static int mtip_hw_submit_io(struct driver_data *dd, struct request *rq,
2047+
struct mtip_cmd *command,
2048+
struct blk_mq_hw_ctx *hctx)
20482049
{
20492050
struct mtip_cmd_hdr *hdr =
20502051
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,
20562057
unsigned int nents;
20572058

20582059
/* Map the scatter list for DMA access */
2059-
nents = blk_rq_map_sg(rq, command->sg);
2060-
nents = dma_map_sg(&dd->pdev->dev, command->sg, nents, dma_dir);
2060+
command->scatter_ents = blk_rq_map_sg(rq, command->sg);
2061+
nents = dma_map_sg(&dd->pdev->dev, command->sg,
2062+
command->scatter_ents, dma_dir);
2063+
if (!nents)
2064+
return -ENOMEM;
20612065

2062-
prefetch(&port->flags);
20632066

2064-
command->scatter_ents = nents;
2067+
prefetch(&port->flags);
20652068

20662069
/*
20672070
* 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,
21122115
if (unlikely(port->flags & MTIP_PF_PAUSE_IO)) {
21132116
set_bit(rq->tag, port->cmds_to_issue);
21142117
set_bit(MTIP_PF_ISSUE_CMDS_BIT, &port->flags);
2115-
return;
2118+
return 0;
21162119
}
21172120

21182121
/* Issue the command to the hardware */
21192122
mtip_issue_ncq_command(port, rq->tag);
2123+
2124+
return 0;
21202125
}
21212126

21222127
/*
@@ -3315,7 +3320,9 @@ static blk_status_t mtip_queue_rq(struct blk_mq_hw_ctx *hctx,
33153320

33163321
blk_mq_start_request(rq);
33173322

3318-
mtip_hw_submit_io(dd, rq, cmd, hctx);
3323+
if (mtip_hw_submit_io(dd, rq, cmd, hctx))
3324+
return BLK_STS_IOERR;
3325+
33193326
return BLK_STS_OK;
33203327
}
33213328

0 commit comments

Comments
 (0)