Skip to content

Commit b20b437

Browse files
outman119broonie
authored andcommitted
spi: amlogic: spifc-a4: Fix DMA mapping error handling
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: 4670db6 ("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>
1 parent 1f318b9 commit b20b437

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

drivers/spi/spi-amlogic-spifc-a4.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ static int aml_sfc_dma_buffer_setup(struct aml_sfc *sfc, void *databuf,
411411
ret = dma_mapping_error(sfc->dev, sfc->daddr);
412412
if (ret) {
413413
dev_err(sfc->dev, "DMA mapping error\n");
414-
goto out_map_data;
414+
return ret;
415415
}
416416

417417
cmd = CMD_DATA_ADDRL(sfc->daddr);
@@ -429,7 +429,6 @@ static int aml_sfc_dma_buffer_setup(struct aml_sfc *sfc, void *databuf,
429429
ret = dma_mapping_error(sfc->dev, sfc->iaddr);
430430
if (ret) {
431431
dev_err(sfc->dev, "DMA mapping error\n");
432-
dma_unmap_single(sfc->dev, sfc->daddr, datalen, dir);
433432
goto out_map_data;
434433
}
435434

@@ -448,7 +447,7 @@ static int aml_sfc_dma_buffer_setup(struct aml_sfc *sfc, void *databuf,
448447
return 0;
449448

450449
out_map_info:
451-
dma_unmap_single(sfc->dev, sfc->iaddr, datalen, dir);
450+
dma_unmap_single(sfc->dev, sfc->iaddr, infolen, dir);
452451
out_map_data:
453452
dma_unmap_single(sfc->dev, sfc->daddr, datalen, dir);
454453

0 commit comments

Comments
 (0)