linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] spi: sg2044-nor: A couple of cleanups
@ 2025-03-13 11:12 Andy Shevchenko
  2025-03-13 11:12 ` [PATCH v2 1/2] spi: sg2044-nor: Fully convert to device managed resources Andy Shevchenko
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Andy Shevchenko @ 2025-03-13 11:12 UTC (permalink / raw)
  To: Longbin Li, Andy Shevchenko, linux-spi, linux-kernel; +Cc: Mark Brown

The driver has one ordering issue and one missed case for dev_err_probe().
Address that in this mini-series.

In v2:
- fixed obvious typo (LKP)

Andy Shevchenko (2):
  spi: sg2044-nor: Fully convert to device managed resources
  spi: sg2044-nor: Convert to dev_err_probe()

 drivers/spi/spi-sg2044-nor.c | 25 +++++++------------------
 1 file changed, 7 insertions(+), 18 deletions(-)

-- 
2.47.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/2] spi: sg2044-nor: Fully convert to device managed resources
  2025-03-13 11:12 [PATCH v2 0/2] spi: sg2044-nor: A couple of cleanups Andy Shevchenko
@ 2025-03-13 11:12 ` Andy Shevchenko
  2025-03-13 11:13 ` [PATCH v2 2/2] spi: sg2044-nor: Convert to dev_err_probe() Andy Shevchenko
  2025-03-17 20:17 ` [PATCH v2 0/2] spi: sg2044-nor: A couple of cleanups Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2025-03-13 11:12 UTC (permalink / raw)
  To: Longbin Li, Andy Shevchenko, linux-spi, linux-kernel; +Cc: Mark Brown

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>
---
 drivers/spi/spi-sg2044-nor.c | 15 ++++-----------
 1 file 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);
 
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] spi: sg2044-nor: Convert to dev_err_probe()
  2025-03-13 11:12 [PATCH v2 0/2] spi: sg2044-nor: A couple of cleanups Andy Shevchenko
  2025-03-13 11:12 ` [PATCH v2 1/2] spi: sg2044-nor: Fully convert to device managed resources Andy Shevchenko
@ 2025-03-13 11:13 ` Andy Shevchenko
  2025-03-17 20:17 ` [PATCH v2 0/2] spi: sg2044-nor: A couple of cleanups Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2025-03-13 11:13 UTC (permalink / raw)
  To: Longbin Li, Andy Shevchenko, linux-spi, linux-kernel; +Cc: Mark Brown

One of the cases in sg2044_spifmc_probe() may be converted to use
dev_err_probe(). Do it.

While at it, use local device pointer in all such calls and drop
unneeded __func__ parameter as dev_err_probe() is assumed to be called
only during probe phase.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/spi/spi-sg2044-nor.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/spi/spi-sg2044-nor.c b/drivers/spi/spi-sg2044-nor.c
index 95822f2fc521..d3582c84538e 100644
--- a/drivers/spi/spi-sg2044-nor.c
+++ b/drivers/spi/spi-sg2044-nor.c
@@ -439,9 +439,7 @@ static int sg2044_spifmc_probe(struct platform_device *pdev)
 
 	spifmc->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(spifmc->clk))
-		return dev_err_probe(&pdev->dev, PTR_ERR(spifmc->clk),
-				     "%s: Cannot get and enable AHB clock\n",
-				     __func__);
+		return dev_err_probe(dev, PTR_ERR(spifmc->clk), "Cannot get and enable AHB clock\n");
 
 	spifmc->dev = &pdev->dev;
 	spifmc->ctrl = ctrl;
@@ -465,10 +463,8 @@ static int sg2044_spifmc_probe(struct platform_device *pdev)
 	sg2044_spifmc_init_reg(spifmc);
 
 	ret = devm_spi_register_controller(&pdev->dev, ctrl);
-	if (ret) {
-		dev_err(&pdev->dev, "spi_register_controller failed\n");
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(dev, ret, "spi_register_controller failed\n");
 
 	return 0;
 }
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 0/2] spi: sg2044-nor: A couple of cleanups
  2025-03-13 11:12 [PATCH v2 0/2] spi: sg2044-nor: A couple of cleanups Andy Shevchenko
  2025-03-13 11:12 ` [PATCH v2 1/2] spi: sg2044-nor: Fully convert to device managed resources Andy Shevchenko
  2025-03-13 11:13 ` [PATCH v2 2/2] spi: sg2044-nor: Convert to dev_err_probe() Andy Shevchenko
@ 2025-03-17 20:17 ` Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2025-03-17 20:17 UTC (permalink / raw)
  To: Longbin Li, linux-spi, linux-kernel, Andy Shevchenko

On Thu, 13 Mar 2025 13:12:58 +0200, Andy Shevchenko wrote:
> The driver has one ordering issue and one missed case for dev_err_probe().
> Address that in this mini-series.
> 
> In v2:
> - fixed obvious typo (LKP)
> 
> Andy Shevchenko (2):
>   spi: sg2044-nor: Fully convert to device managed resources
>   spi: sg2044-nor: Convert to dev_err_probe()
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/2] spi: sg2044-nor: Fully convert to device managed resources
      commit: c6d94963333d6377382f26a480e687492f5a9174
[2/2] spi: sg2044-nor: Convert to dev_err_probe()
      commit: 085cf53d71b9406d646c9f3f24876a36a68ef4e9

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

end of thread, other threads:[~2025-03-17 20:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-13 11:12 [PATCH v2 0/2] spi: sg2044-nor: A couple of cleanups Andy Shevchenko
2025-03-13 11:12 ` [PATCH v2 1/2] spi: sg2044-nor: Fully convert to device managed resources Andy Shevchenko
2025-03-13 11:13 ` [PATCH v2 2/2] spi: sg2044-nor: Convert to dev_err_probe() Andy Shevchenko
2025-03-17 20:17 ` [PATCH v2 0/2] spi: sg2044-nor: A couple of cleanups Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).