Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 88523a61558a ("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>

authored by

Thomas Fourier and committed by
Jens Axboe
8e1fab9c 5a593def

+17 -10
+17 -10
drivers/block/mtip32xx/mtip32xx.c
··· 2040 2040 * @dir Direction (read or write) 2041 2041 * 2042 2042 * return value 2043 - * None 2043 + * 0 The IO completed successfully. 2044 + * -ENOMEM The DMA mapping failed. 2044 2045 */ 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) 2048 2049 { 2049 2050 struct mtip_cmd_hdr *hdr = 2050 2051 dd->port->command_list + sizeof(struct mtip_cmd_hdr) * rq->tag; ··· 2057 2056 unsigned int nents; 2058 2057 2059 2058 /* Map the scatter list for DMA access */ 2060 - nents = blk_rq_map_sg(rq, command->sg); 2061 - nents = dma_map_sg(&dd->pdev->dev, command->sg, nents, dma_dir); 2059 + command->scatter_ents = blk_rq_map_sg(rq, command->sg); 2060 + nents = dma_map_sg(&dd->pdev->dev, command->sg, 2061 + command->scatter_ents, dma_dir); 2062 + if (!nents) 2063 + return -ENOMEM; 2064 + 2062 2065 2063 2066 prefetch(&port->flags); 2064 - 2065 - command->scatter_ents = nents; 2066 2067 2067 2068 /* 2068 2069 * The number of retries for this command before it is ··· 2115 2112 if (unlikely(port->flags & MTIP_PF_PAUSE_IO)) { 2116 2113 set_bit(rq->tag, port->cmds_to_issue); 2117 2114 set_bit(MTIP_PF_ISSUE_CMDS_BIT, &port->flags); 2118 - return; 2115 + return 0; 2119 2116 } 2120 2117 2121 2118 /* Issue the command to the hardware */ 2122 2119 mtip_issue_ncq_command(port, rq->tag); 2120 + 2121 + return 0; 2123 2122 } 2124 2123 2125 2124 /* ··· 3320 3315 3321 3316 blk_mq_start_request(rq); 3322 3317 3323 - mtip_hw_submit_io(dd, rq, cmd, hctx); 3318 + if (mtip_hw_submit_io(dd, rq, cmd, hctx)) 3319 + return BLK_STS_IOERR; 3320 + 3324 3321 return BLK_STS_OK; 3325 3322 } 3326 3323