summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>2025-03-13 14:12:59 +0300
committerMark Brown <broonie@kernel.org>2025-03-17 02:34:08 +0300
commitc6d94963333d6377382f26a480e687492f5a9174 (patch)
treeb1318370d20b32d28a1aa9494198b3754d911b92
parent336a41c90c86b883aa06ed19f138eee19ddf9958 (diff)
downloadlinux-c6d94963333d6377382f26a480e687492f5a9174.tar.xz
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>
-rw-r--r--drivers/spi/spi-sg2044-nor.c15
1 files changed, 4 insertions, 11 deletions
diff --git a/drivers/spi/spi-sg2044-nor.c b/drivers/spi/spi-sg2044-nor.c
index 454153a63b42..95822f2fc521 100644
--- a/drivers/spi/spi-sg2044-nor.c
+++ b/drivers/spi/spi-sg2044-nor.c
@@ -425,6 +425,7 @@ static void sg2044_spifmc_init(struct sg2044_spifmc *spifmc)
static int sg2044_spifmc_probe(struct platform_device *pdev)
{
+ struct device *dev = &pdev->dev;
struct spi_controller *ctrl;
struct sg2044_spifmc *spifmc;
void __iomem *base;
@@ -435,7 +436,6 @@ static int sg2044_spifmc_probe(struct platform_device *pdev)
return -ENOMEM;
spifmc = spi_controller_get_devdata(ctrl);
- dev_set_drvdata(&pdev->dev, ctrl);
spifmc->clk = devm_clk_get_enabled(&pdev->dev, NULL);
if (IS_ERR(spifmc->clk))
@@ -457,14 +457,15 @@ static int sg2044_spifmc_probe(struct platform_device *pdev)
ctrl->mem_ops = &sg2044_spifmc_mem_ops;
ctrl->mode_bits = SPI_RX_DUAL | SPI_TX_DUAL | SPI_RX_QUAD | SPI_TX_QUAD;
- mutex_init(&spifmc->lock);
+ ret = devm_mutex_init(dev, &spifmc->lock);
+ if (ret)
+ return ret;
sg2044_spifmc_init(spifmc);
sg2044_spifmc_init_reg(spifmc);
ret = devm_spi_register_controller(&pdev->dev, ctrl);
if (ret) {
- mutex_destroy(&spifmc->lock);
dev_err(&pdev->dev, "spi_register_controller failed\n");
return ret;
}
@@ -472,13 +473,6 @@ static int sg2044_spifmc_probe(struct platform_device *pdev)
return 0;
}
-static void sg2044_spifmc_remove(struct platform_device *pdev)
-{
- struct sg2044_spifmc *spifmc = platform_get_drvdata(pdev);
-
- mutex_destroy(&spifmc->lock);
-}
-
static const struct of_device_id sg2044_spifmc_match[] = {
{ .compatible = "sophgo,sg2044-spifmc-nor" },
{ /* sentinel */ }
@@ -491,7 +485,6 @@ static struct platform_driver sg2044_nor_driver = {
.of_match_table = sg2044_spifmc_match,
},
.probe = sg2044_spifmc_probe,
- .remove = sg2044_spifmc_remove,
};
module_platform_driver(sg2044_nor_driver);