Skip to content

Commit c6d9496

Browse files
andy-shevbroonie
authored andcommitted
spi: sg2044-nor: Fully convert to device managed resources
The driver has a wrong order of the cleaning up the resources, i.e. it first will destroy the mutex and only then free the SPI which might still use it. Fix this by switching to devm_mutex_init(). Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://patch.msgid.link/20250313111423.322775-2-andriy.shevchenko@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 336a41c commit c6d9496

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

drivers/spi/spi-sg2044-nor.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ static void sg2044_spifmc_init(struct sg2044_spifmc *spifmc)
425425

426426
static int sg2044_spifmc_probe(struct platform_device *pdev)
427427
{
428+
struct device *dev = &pdev->dev;
428429
struct spi_controller *ctrl;
429430
struct sg2044_spifmc *spifmc;
430431
void __iomem *base;
@@ -435,7 +436,6 @@ static int sg2044_spifmc_probe(struct platform_device *pdev)
435436
return -ENOMEM;
436437

437438
spifmc = spi_controller_get_devdata(ctrl);
438-
dev_set_drvdata(&pdev->dev, ctrl);
439439

440440
spifmc->clk = devm_clk_get_enabled(&pdev->dev, NULL);
441441
if (IS_ERR(spifmc->clk))
@@ -457,28 +457,22 @@ static int sg2044_spifmc_probe(struct platform_device *pdev)
457457
ctrl->mem_ops = &sg2044_spifmc_mem_ops;
458458
ctrl->mode_bits = SPI_RX_DUAL | SPI_TX_DUAL | SPI_RX_QUAD | SPI_TX_QUAD;
459459

460-
mutex_init(&spifmc->lock);
460+
ret = devm_mutex_init(dev, &spifmc->lock);
461+
if (ret)
462+
return ret;
461463

462464
sg2044_spifmc_init(spifmc);
463465
sg2044_spifmc_init_reg(spifmc);
464466

465467
ret = devm_spi_register_controller(&pdev->dev, ctrl);
466468
if (ret) {
467-
mutex_destroy(&spifmc->lock);
468469
dev_err(&pdev->dev, "spi_register_controller failed\n");
469470
return ret;
470471
}
471472

472473
return 0;
473474
}
474475

475-
static void sg2044_spifmc_remove(struct platform_device *pdev)
476-
{
477-
struct sg2044_spifmc *spifmc = platform_get_drvdata(pdev);
478-
479-
mutex_destroy(&spifmc->lock);
480-
}
481-
482476
static const struct of_device_id sg2044_spifmc_match[] = {
483477
{ .compatible = "sophgo,sg2044-spifmc-nor" },
484478
{ /* sentinel */ }
@@ -491,7 +485,6 @@ static struct platform_driver sg2044_nor_driver = {
491485
.of_match_table = sg2044_spifmc_match,
492486
},
493487
.probe = sg2044_spifmc_probe,
494-
.remove = sg2044_spifmc_remove,
495488
};
496489
module_platform_driver(sg2044_nor_driver);
497490

0 commit comments

Comments
 (0)