Skip to contentSkip to conversation

spi: tegra: Fix a memory leak in tegra_slink_probe()

PATCH In review Felix Gu 3 participants 3 messages Feb 2

Subsystems (3)
lore
Share & tools
lore

Felix Gu

author
#0 lore raw

PATCH 1/1 spi: tegra: Fix a memory leak in tegra_slink_probe()

In tegra_slink_probe(), when platform_get_irq() fails, it directly returns from the function with an error code, which causes a memory leak.

Replace it with a goto label to ensure proper cleanup.

Fixes eb9913b511f1 ("spi: tegra: Fix missing IRQ check in tegra_slink_probe()")
---
 drivers/spi/spi-tegra20-slink.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/spi/spi-tegra20-slink.c +4 -2
index 7d6f3fe8b7e3..8c608abd6076 100644
@@ -1086,8 +1086,10 @@ static int tegra_slink_probe(struct platform_device *pdev)
 	reset_control_deassert(tspi->rst);
 
 	spi_irq = platform_get_irq(pdev, 0);
-	if (spi_irq < 0)
-		return spi_irq;
+	if (spi_irq < 0) {
+		ret = spi_irq;
+		goto exit_pm_put;
+	}
 	tspi->irq = spi_irq;
 	ret = request_threaded_irq(tspi->irq, tegra_slink_isr,
 				   tegra_slink_isr_thread, IRQF_ONESHOT,

---
base-commit: 4c87cdd0328495759f6e9f9f4e1e53ef8032a76f
change-id: 20260202-slink-a229f708611d

Best regards,

Signature · 1 line
Felix Gu <[email protected]>
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 30 lines · Felix Gu

In tegra_slink_probe(), when platform_get_irq() fails, it directly returns from the function with an error code, which causes a memory leak.

Replace it with a goto label to ensure proper cleanup.

Fixes eb9913b511f1 ("spi: tegra: Fix missing IRQ check in tegra_slink_probe()")
---
  drivers/spi/spi-tegra20-slink.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/spi/spi-tegra20-slink.c +4 -3
index 7d6f3fe8b7e3..8c608abd6076 100644
@@ -1086,8 +1086,10 @@ static int tegra_slink_probe(struct platform_device *pdev)
  	reset_control_deassert(tspi->rst);
 
  	spi_irq = platform_get_irq(pdev, 0);
-	if (spi_irq < 0)
-		return spi_irq;
+	if (spi_irq < 0) {
+		ret = spi_irq;
+		goto exit_pm_put;
+	}
  	tspi->irq = spi_irq;
  	ret = request_threaded_irq(tspi->irq, tegra_slink_isr,
  				   tegra_slink_isr_thread, IRQF_ONESHOT,
 
---
Quoted 2 lines

base-commit: 4c87cdd0328495759f6e9f9f4e1e53ef8032a76f
change-id: 20260202-slink-a229f708611d

We could get rid of this 'spi_irq' variable and just use 'ret', but that is another clean-up. Otherwise ...

Thanks
Jon

Signature · 1 line
nvpublic
maintainer
#2 lore raw
In reply to Felix Gu
Quoted 6 lines · Felix Gu

In tegra_slink_probe(), when platform_get_irq() fails, it directly returns from the function with an error code, which causes a memory leak.

Replace it with a goto label to ensure proper cleanup.

Applied to

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

Thanks!

[1/1] spi: tegra: Fix a memory leak in tegra_slink_probe()

      commit: 41d9a6795b95d6ea28439ac1e9ce8c95bbca20fc

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