]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
spi: amlogic: spifc-a4: Fix DMA mapping error handling
authorFelix Gu <ustc.gu@gmail.com>
Thu, 5 Mar 2026 17:24:32 +0000 (01:24 +0800)
committerMark Brown <broonie@kernel.org>
Mon, 9 Mar 2026 12:29:28 +0000 (12:29 +0000)
Fix three bugs in aml_sfc_dma_buffer_setup() error paths:
1. Unnecessary goto: When the first DMA mapping (sfc->daddr) fails,
   nothing needs cleanup. Use direct return instead of goto.
2. Double-unmap bug: When info DMA mapping failed, the code would
   unmap sfc->daddr inline, then fall through to out_map_data which
   would unmap it again, causing a double-unmap.
3. Wrong unmap size: The out_map_info label used datalen instead of
   infolen when unmapping sfc->iaddr, which could lead to incorrect
   DMA sync behavior.

Fixes: 4670db6f32e9 ("spi: amlogic: add driver for Amlogic SPI Flash Controller")
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
Link: https://patch.msgid.link/20260306-spifc-a4-v1-1-f22c9965f64a@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-amlogic-spifc-a4.c

index 2aef528cfc1baee52b55ce597639bc67c546f4fc..3956869cfec119324982f84919ba9b0dda1efd22 100644 (file)
@@ -411,7 +411,7 @@ static int aml_sfc_dma_buffer_setup(struct aml_sfc *sfc, void *databuf,
        ret = dma_mapping_error(sfc->dev, sfc->daddr);
        if (ret) {
                dev_err(sfc->dev, "DMA mapping error\n");
-               goto out_map_data;
+               return ret;
        }
 
        cmd = CMD_DATA_ADDRL(sfc->daddr);
@@ -429,7 +429,6 @@ static int aml_sfc_dma_buffer_setup(struct aml_sfc *sfc, void *databuf,
                ret = dma_mapping_error(sfc->dev, sfc->iaddr);
                if (ret) {
                        dev_err(sfc->dev, "DMA mapping error\n");
-                       dma_unmap_single(sfc->dev, sfc->daddr, datalen, dir);
                        goto out_map_data;
                }
 
@@ -448,7 +447,7 @@ static int aml_sfc_dma_buffer_setup(struct aml_sfc *sfc, void *databuf,
        return 0;
 
 out_map_info:
-       dma_unmap_single(sfc->dev, sfc->iaddr, datalen, dir);
+       dma_unmap_single(sfc->dev, sfc->iaddr, infolen, dir);
 out_map_data:
        dma_unmap_single(sfc->dev, sfc->daddr, datalen, dir);