mirror of https://lore.kernel.org/linux-amlogic/
 help / color / mirror / Atom feed
* [PATCH] spi: amlogic-spisg: Fix memory leak in aml_spisg_probe()
@ 2026-03-08  6:49 Felix Gu
  2026-03-15 23:59 ` Mark Brown
  2026-03-16 17:52 ` Mark Brown
  0 siblings, 2 replies; 3+ messages in thread
From: Felix Gu @ 2026-03-08  6:49 UTC (permalink / raw)
  To: Sunny Luo, Xianwei Zhao, Mark Brown
  Cc: linux-amlogic, linux-spi, linux-kernel, Felix Gu

In aml_spisg_probe(), ctlr is allocated by
spi_alloc_target()/spi_alloc_host(), but fails to call
spi_controller_put() in several error paths. This leads
to a memory leak whenever the driver fails to probe after
the initial allocation.

Convert to use devm_spi_alloc_host()/devm_spi_alloc_target()
to fix the memory leak.

Fixes: cef9991e04ae ("spi: Add Amlogic SPISG driver")
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
 drivers/spi/spi-amlogic-spisg.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/spi/spi-amlogic-spisg.c b/drivers/spi/spi-amlogic-spisg.c
index 1509df2b17ae..9d568e385f05 100644
--- a/drivers/spi/spi-amlogic-spisg.c
+++ b/drivers/spi/spi-amlogic-spisg.c
@@ -729,9 +729,9 @@ static int aml_spisg_probe(struct platform_device *pdev)
 	};
 
 	if (of_property_read_bool(dev->of_node, "spi-slave"))
-		ctlr = spi_alloc_target(dev, sizeof(*spisg));
+		ctlr = devm_spi_alloc_target(dev, sizeof(*spisg));
 	else
-		ctlr = spi_alloc_host(dev, sizeof(*spisg));
+		ctlr = devm_spi_alloc_host(dev, sizeof(*spisg));
 	if (!ctlr)
 		return -ENOMEM;
 
@@ -750,10 +750,8 @@ static int aml_spisg_probe(struct platform_device *pdev)
 		return dev_err_probe(dev, PTR_ERR(spisg->map), "regmap init failed\n");
 
 	irq = platform_get_irq(pdev, 0);
-	if (irq < 0) {
-		ret = irq;
-		goto out_controller;
-	}
+	if (irq < 0)
+		return irq;
 
 	ret = device_reset_optional(dev);
 	if (ret)
@@ -817,8 +815,6 @@ static int aml_spisg_probe(struct platform_device *pdev)
 	if (spisg->core)
 		clk_disable_unprepare(spisg->core);
 	clk_disable_unprepare(spisg->pclk);
-out_controller:
-	spi_controller_put(ctlr);
 
 	return ret;
 }

---
base-commit: a0ae2a256046c0c5d3778d1a194ff2e171f16e5f
change-id: 20260306-spisg-535c7e9d9763

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] 3+ messages in thread

* Re: [PATCH] spi: amlogic-spisg: Fix memory leak in aml_spisg_probe()
  2026-03-08  6:49 [PATCH] spi: amlogic-spisg: Fix memory leak in aml_spisg_probe() Felix Gu
@ 2026-03-15 23:59 ` Mark Brown
  2026-03-16 17:52 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2026-03-15 23:59 UTC (permalink / raw)
  To: Sunny Luo, Xianwei Zhao, Felix Gu; +Cc: linux-amlogic, linux-spi, linux-kernel

On Sun, 08 Mar 2026 14:49:21 +0800, Felix Gu wrote:
> spi: amlogic-spisg: Fix memory leak in aml_spisg_probe()

Applied to

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

Thanks!

[1/1] spi: amlogic-spisg: Fix memory leak in aml_spisg_probe()
      https://git.kernel.org/broonie/spi/c/b8db95529979

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] 3+ messages in thread

* Re: [PATCH] spi: amlogic-spisg: Fix memory leak in aml_spisg_probe()
  2026-03-08  6:49 [PATCH] spi: amlogic-spisg: Fix memory leak in aml_spisg_probe() Felix Gu
  2026-03-15 23:59 ` Mark Brown
@ 2026-03-16 17:52 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2026-03-16 17:52 UTC (permalink / raw)
  To: Sunny Luo, Xianwei Zhao, Felix Gu; +Cc: linux-amlogic, linux-spi, linux-kernel

On Sun, 08 Mar 2026 14:49:21 +0800, Felix Gu wrote:
> In aml_spisg_probe(), ctlr is allocated by
> spi_alloc_target()/spi_alloc_host(), but fails to call
> spi_controller_put() in several error paths. This leads
> to a memory leak whenever the driver fails to probe after
> the initial allocation.
> 
> Convert to use devm_spi_alloc_host()/devm_spi_alloc_target()
> to fix the memory leak.
> 
> [...]

Applied to

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

Thanks!

[1/1] spi: amlogic-spisg: Fix memory leak in aml_spisg_probe()
      https://git.kernel.org/broonie/misc/c/b8db95529979

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] 3+ messages in thread

end of thread, other threads:[~2026-03-16 17:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-08  6:49 [PATCH] spi: amlogic-spisg: Fix memory leak in aml_spisg_probe() Felix Gu
2026-03-15 23:59 ` Mark Brown
2026-03-16 17:52 ` 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®