spi: sn-f-ospi: two small fixes
cover spi: sn-f-ospi: two small fixes
---
Felix Gu (2):
spi: sn-f-ospi: Fix resource leak in f_ospi_probe()
spi: sn-f-ospi: Use devm_mutex_init() to simplify code
drivers/spi/spi-sn-f-ospi.c | 42 ++++++++++-------------------------------- 1 file changed, 10 insertions(+), 32 deletions(-)
---
base-commit: 8e5a478b6d6a5bb0a3d52147862b15e4d826af19
change-id: 20260318-sn-f-12fe303c41ca
Best regards,
Signature · 1 line
Felix Gu <[email protected]>
PATCH 1/2 spi: sn-f-ospi: Fix resource leak in f_ospi_probe()
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.
--- drivers/spi/spi-sn-f-ospi.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-)
drivers/spi/spi-sn-f-ospi.c +5 -12
@@ -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; }
Signature · 1 line
2.43.0
PATCH 2/2 spi: sn-f-ospi: Use devm_mutex_init() to simplify code
In reply to Felix GuSwitch 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.
--- drivers/spi/spi-sn-f-ospi.c | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-)
drivers/spi/spi-sn-f-ospi.c +5 -20
@@ -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);
Signature · 1 line
2.43.0
Mark Brown
maintainerQuoted 1 line · Felix Gu
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