Skip to content
/ linux Public

Commit bec21d9

Browse files
outman119gregkh
authored andcommitted
spi: amlogic-spisg: Fix memory leak in aml_spisg_probe()
[ Upstream commit b8db955 ] 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: cef9991 ("spi: Add Amlogic SPISG driver") Signed-off-by: Felix Gu <ustc.gu@gmail.com> Link: https://patch.msgid.link/20260308-spisg-v1-1-2cace5cafc24@gmail.com Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent f15e070 commit bec21d9

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

drivers/spi/spi-amlogic-spisg.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -729,9 +729,9 @@ static int aml_spisg_probe(struct platform_device *pdev)
729729
};
730730

731731
if (of_property_read_bool(dev->of_node, "spi-slave"))
732-
ctlr = spi_alloc_target(dev, sizeof(*spisg));
732+
ctlr = devm_spi_alloc_target(dev, sizeof(*spisg));
733733
else
734-
ctlr = spi_alloc_host(dev, sizeof(*spisg));
734+
ctlr = devm_spi_alloc_host(dev, sizeof(*spisg));
735735
if (!ctlr)
736736
return -ENOMEM;
737737

@@ -750,10 +750,8 @@ static int aml_spisg_probe(struct platform_device *pdev)
750750
return dev_err_probe(dev, PTR_ERR(spisg->map), "regmap init failed\n");
751751

752752
irq = platform_get_irq(pdev, 0);
753-
if (irq < 0) {
754-
ret = irq;
755-
goto out_controller;
756-
}
753+
if (irq < 0)
754+
return irq;
757755

758756
ret = device_reset_optional(dev);
759757
if (ret)
@@ -818,8 +816,6 @@ static int aml_spisg_probe(struct platform_device *pdev)
818816
if (spisg->core)
819817
clk_disable_unprepare(spisg->core);
820818
clk_disable_unprepare(spisg->pclk);
821-
out_controller:
822-
spi_controller_put(ctlr);
823819

824820
return ret;
825821
}

0 commit comments

Comments
 (0)