mirror of https://lore.kernel.org/linux-amlogic/
 help / color / mirror / Atom feed
* [PATCH] spi: amlogic: spifc-a4: Fix DMA mapping error handling
@ 2026-03-05 17:24 Felix Gu
  2026-03-06  1:42 ` Xianwei Zhao
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Felix Gu @ 2026-03-05 17:24 UTC (permalink / raw)
  To: Liang Yang, Feng Chen, Xianwei Zhao, Mark Brown
  Cc: linux-amlogic, linux-spi, linux-kernel, Felix Gu

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>
---
 drivers/spi/spi-amlogic-spifc-a4.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/spi/spi-amlogic-spifc-a4.c b/drivers/spi/spi-amlogic-spifc-a4.c
index 2aef528cfc1b..3956869cfec1 100644
--- a/drivers/spi/spi-amlogic-spifc-a4.c
+++ b/drivers/spi/spi-amlogic-spifc-a4.c
@@ -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);
 

---
base-commit: 3f9cd19e764b782706dbaacc69e502099cb014ba
change-id: 20260306-spifc-a4-d40f84506d6a

Best regards,
-- 
Felix Gu <ustc.gu@gmail.com>


_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] spi: amlogic: spifc-a4: Fix DMA mapping error handling
  2026-03-05 17:24 [PATCH] spi: amlogic: spifc-a4: Fix DMA mapping error handling Felix Gu
@ 2026-03-06  1:42 ` Xianwei Zhao
  2026-03-06 10:05 ` Markus Elfring
  2026-03-09 19:06 ` Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Xianwei Zhao @ 2026-03-06  1:42 UTC (permalink / raw)
  To: Felix Gu, Liang Yang, Feng Chen, Mark Brown
  Cc: linux-amlogic, linux-spi, linux-kernel



On 2026/3/6 01:24, Felix Gu wrote:
> 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>
> ---
>   drivers/spi/spi-amlogic-spifc-a4.c | 5 ++---
>   1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/spi/spi-amlogic-spifc-a4.c b/drivers/spi/spi-amlogic-spifc-a4.c
> index 2aef528cfc1b..3956869cfec1 100644
> --- a/drivers/spi/spi-amlogic-spifc-a4.c
> +++ b/drivers/spi/spi-amlogic-spifc-a4.c
> @@ -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);
> 
> 

Reviewed-by: Xianwei Zhao <xianwei.zhao@amlogic.com>

> ---
> base-commit: 3f9cd19e764b782706dbaacc69e502099cb014ba
> change-id: 20260306-spifc-a4-d40f84506d6a
> 
> Best regards,
> --
> Felix Gu<ustc.gu@gmail.com>

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] spi: amlogic: spifc-a4: Fix DMA mapping error handling
  2026-03-05 17:24 [PATCH] spi: amlogic: spifc-a4: Fix DMA mapping error handling Felix Gu
  2026-03-06  1:42 ` Xianwei Zhao
@ 2026-03-06 10:05 ` Markus Elfring
  2026-03-09 19:06 ` Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2026-03-06 10:05 UTC (permalink / raw)
  To: Felix Gu, linux-spi, linux-amlogic
  Cc: LKML, kernel-janitors, Feng Chen, Liang Yang, Mark Brown, Xianwei Zhao

> Fix three bugs in aml_sfc_dma_buffer_setup() error paths:
…

Please split desired adjustments into safer update steps.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v7.0-rc2#n81

Regards,
Markus

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] spi: amlogic: spifc-a4: Fix DMA mapping error handling
  2026-03-05 17:24 [PATCH] spi: amlogic: spifc-a4: Fix DMA mapping error handling Felix Gu
  2026-03-06  1:42 ` Xianwei Zhao
  2026-03-06 10:05 ` Markus Elfring
@ 2026-03-09 19:06 ` Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2026-03-09 19:06 UTC (permalink / raw)
  To: Liang Yang, Feng Chen, Xianwei Zhao, Felix Gu
  Cc: linux-amlogic, linux-spi, linux-kernel

On Fri, 06 Mar 2026 01:24:32 +0800, Felix Gu wrote:
> 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.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/1] spi: amlogic: spifc-a4: Fix DMA mapping error handling
      commit: b20b437666e1cb26a7c499d1664e8f2a0ac67000

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark


_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-03-09 19:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-05 17:24 [PATCH] spi: amlogic: spifc-a4: Fix DMA mapping error handling Felix Gu
2026-03-06  1:42 ` Xianwei Zhao
2026-03-06 10:05 ` Markus Elfring
2026-03-09 19:06 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®