mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-12-28 06:44:36 -05:00
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: 88523a6155 ("block: Add driver for Micron RealSSD pcie flash cards")
Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20250627121123.203731-2-fourier.thomas@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
committed by
Jens Axboe
parent
5a593def8b
commit
8e1fab9ccc
@@ -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,13 +2057,15 @@ 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;
|
||||
|
||||
/*
|
||||
* The number of retries for this command before it is
|
||||
* reported as a failure to the upper layers.
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user