* [PATCH 1/2] spi: sn-f-ospi: Fix resource leak in f_ospi_probe()
2026-03-18 16:12 [PATCH 0/2] spi: sn-f-ospi: two small fixes Felix Gu
@ 2026-03-18 16:12 ` Felix Gu
2026-03-18 16:12 ` [PATCH 2/2] spi: sn-f-ospi: Use devm_mutex_init() to simplify code Felix Gu
2026-03-23 14:52 ` [PATCH 0/2] spi: sn-f-ospi: two small fixes Mark Brown
2 siblings, 0 replies; 4+ messages in thread
From: Felix Gu @ 2026-03-18 16:12 UTC (permalink / raw)
To: Mark Brown, Kunihiko Hayashi; +Cc: linux-spi, linux-kernel, Felix Gu
In f_ospi_probe(), when num_cs validation fails, it returns without
calling spi_controller_put() on the SPI controller, which causes a
resource leak.
Use devm_spi_alloc_host() instead of spi_alloc_host() to ensure the
SPI controller is properly freed when probe fails.
Fixes: 1b74dd64c861 ("spi: Add Socionext F_OSPI SPI flash controller driver")
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
drivers/spi/spi-sn-f-ospi.c | 17 +++++------------
1 file changed, 5 insertions(+), 12 deletions(-)
diff --git a/drivers/spi/spi-sn-f-ospi.c b/drivers/spi/spi-sn-f-ospi.c
index bfcc140df810..1f554aa7ca27 100644
--- a/drivers/spi/spi-sn-f-ospi.c
+++ b/drivers/spi/spi-sn-f-ospi.c
@@ -612,7 +612,7 @@ static int f_ospi_probe(struct platform_device *pdev)
u32 num_cs = OSPI_NUM_CS;
int ret;
- ctlr = spi_alloc_host(dev, sizeof(*ospi));
+ ctlr = devm_spi_alloc_host(dev, sizeof(*ospi));
if (!ctlr)
return -ENOMEM;
@@ -635,16 +635,12 @@ static int f_ospi_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, ospi);
ospi->base = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(ospi->base)) {
- ret = PTR_ERR(ospi->base);
- goto err_put_ctlr;
- }
+ if (IS_ERR(ospi->base))
+ return PTR_ERR(ospi->base);
ospi->clk = devm_clk_get_enabled(dev, NULL);
- if (IS_ERR(ospi->clk)) {
- ret = PTR_ERR(ospi->clk);
- goto err_put_ctlr;
- }
+ if (IS_ERR(ospi->clk))
+ return PTR_ERR(ospi->clk);
mutex_init(&ospi->mlock);
@@ -661,9 +657,6 @@ static int f_ospi_probe(struct platform_device *pdev)
err_destroy_mutex:
mutex_destroy(&ospi->mlock);
-err_put_ctlr:
- spi_controller_put(ctlr);
-
return ret;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 2/2] spi: sn-f-ospi: Use devm_mutex_init() to simplify code
2026-03-18 16:12 [PATCH 0/2] spi: sn-f-ospi: two small fixes Felix Gu
2026-03-18 16:12 ` [PATCH 1/2] spi: sn-f-ospi: Fix resource leak in f_ospi_probe() Felix Gu
@ 2026-03-18 16:12 ` Felix Gu
2026-03-23 14:52 ` [PATCH 0/2] spi: sn-f-ospi: two small fixes Mark Brown
2 siblings, 0 replies; 4+ messages in thread
From: Felix Gu @ 2026-03-18 16:12 UTC (permalink / raw)
To: Mark Brown, Kunihiko Hayashi; +Cc: linux-spi, linux-kernel, Felix Gu
Switch to devm_mutex_init() to handle mutex destruction automatically.
This simplifies the error paths in probe() and removes the need for an
explicit mutex_destroy() in remove() callback.
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
drivers/spi/spi-sn-f-ospi.c | 25 +++++--------------------
1 file changed, 5 insertions(+), 20 deletions(-)
diff --git a/drivers/spi/spi-sn-f-ospi.c b/drivers/spi/spi-sn-f-ospi.c
index 1f554aa7ca27..3c61c799723b 100644
--- a/drivers/spi/spi-sn-f-ospi.c
+++ b/drivers/spi/spi-sn-f-ospi.c
@@ -642,29 +642,15 @@ static int f_ospi_probe(struct platform_device *pdev)
if (IS_ERR(ospi->clk))
return PTR_ERR(ospi->clk);
- mutex_init(&ospi->mlock);
-
- ret = f_ospi_init(ospi);
+ ret = devm_mutex_init(dev, &ospi->mlock);
if (ret)
- goto err_destroy_mutex;
+ return ret;
- ret = devm_spi_register_controller(dev, ctlr);
+ ret = f_ospi_init(ospi);
if (ret)
- goto err_destroy_mutex;
-
- return 0;
-
-err_destroy_mutex:
- mutex_destroy(&ospi->mlock);
-
- return ret;
-}
-
-static void f_ospi_remove(struct platform_device *pdev)
-{
- struct f_ospi *ospi = platform_get_drvdata(pdev);
+ return ret;
- mutex_destroy(&ospi->mlock);
+ return devm_spi_register_controller(dev, ctlr);
}
static const struct of_device_id f_ospi_dt_ids[] = {
@@ -679,7 +665,6 @@ static struct platform_driver f_ospi_driver = {
.of_match_table = f_ospi_dt_ids,
},
.probe = f_ospi_probe,
- .remove = f_ospi_remove,
};
module_platform_driver(f_ospi_driver);
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH 0/2] spi: sn-f-ospi: two small fixes
2026-03-18 16:12 [PATCH 0/2] spi: sn-f-ospi: two small fixes Felix Gu
2026-03-18 16:12 ` [PATCH 1/2] spi: sn-f-ospi: Fix resource leak in f_ospi_probe() Felix Gu
2026-03-18 16:12 ` [PATCH 2/2] spi: sn-f-ospi: Use devm_mutex_init() to simplify code Felix Gu
@ 2026-03-23 14:52 ` Mark Brown
2 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2026-03-23 14:52 UTC (permalink / raw)
To: Kunihiko Hayashi, Felix Gu; +Cc: linux-spi, linux-kernel
On Thu, 19 Mar 2026 00:12:33 +0800, Felix Gu wrote:
> spi: sn-f-ospi: two small fixes
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-7.0
Thanks!
[1/2] spi: sn-f-ospi: Fix resource leak in f_ospi_probe()
https://git.kernel.org/broonie/spi/c/ef3d549e1deb
[2/2] spi: sn-f-ospi: Use devm_mutex_init() to simplify code
https://git.kernel.org/broonie/spi/c/a42c9b8b0c00
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
^ permalink raw reply [flat|nested] 4+ messages in thread