linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] spi: imx: Fix cleanup in remove and convert to .remove_new()
@ 2023-03-06  6:57 Uwe Kleine-König
  2023-03-06  6:57 ` [PATCH 1/2] spi: imx: Don't skip cleanup in remove's error path Uwe Kleine-König
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Uwe Kleine-König @ 2023-03-06  6:57 UTC (permalink / raw)
  To: Mark Brown, Shawn Guo, Sascha Hauer, Stefan Agner
  Cc: Uwe Kleine-König, Pengutronix Kernel Team, Fabio Estevam,
	NXP Linux Team, linux-spi, linux-arm-kernel, linux-kernel

From: Uwe Kleine-König <uwe@kleine-koenig.org>

Hello,

this small series converts the spi-imx driver to .remove_new(). The
motivation for this tree-wide effort are drivers that don't properly
cleanup and return an error code. This is broken as this results in
resource leaks. The spi-imx driver is such a driver. The idea is that if
the remove callback returns void it's obvious that an early error return
is wrong.

Best regards
Uwe

Uwe Kleine-König (2):
  spi: imx: Don't skip cleanup in remove's error path
  spi: imx: Convert to platform remove callback returning void

 drivers/spi/spi-imx.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)


base-commit: b01fe98d34f3bed944a93bd8119fed80c856fad8
-- 
2.39.1


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

* [PATCH 1/2] spi: imx: Don't skip cleanup in remove's error path
  2023-03-06  6:57 [PATCH 0/2] spi: imx: Fix cleanup in remove and convert to .remove_new() Uwe Kleine-König
@ 2023-03-06  6:57 ` Uwe Kleine-König
  2023-03-06  6:57 ` [PATCH 2/2] spi: imx: Convert to platform remove callback returning void Uwe Kleine-König
  2023-03-20 18:50 ` [PATCH 0/2] spi: imx: Fix cleanup in remove and convert to .remove_new() Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Uwe Kleine-König @ 2023-03-06  6:57 UTC (permalink / raw)
  To: Mark Brown, Shawn Guo, Sascha Hauer, Stefan Agner
  Cc: Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team,
	linux-spi, linux-arm-kernel, linux-kernel

Returning early in a platform driver's remove callback is wrong. In this
case the dma resources are not released in the error path. this is never
retried later and so this is a permanent leak. To fix this, only skip
hardware disabling if waking the device fails.

Fixes: d593574aff0a ("spi: imx: do not access registers while clocks disabled")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/spi/spi-imx.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index e4ccd0c329d0..6c9c87cd14ca 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -1856,13 +1856,11 @@ static int spi_imx_remove(struct platform_device *pdev)
 
 	spi_unregister_controller(controller);
 
-	ret = pm_runtime_resume_and_get(spi_imx->dev);
-	if (ret < 0) {
-		dev_err(spi_imx->dev, "failed to enable clock\n");
-		return ret;
-	}
-
-	writel(0, spi_imx->base + MXC_CSPICTRL);
+	ret = pm_runtime_get_sync(spi_imx->dev);
+	if (ret >= 0)
+		writel(0, spi_imx->base + MXC_CSPICTRL);
+	else
+		dev_warn(spi_imx->dev, "failed to enable clock, skip hw disable\n");
 
 	pm_runtime_dont_use_autosuspend(spi_imx->dev);
 	pm_runtime_put_sync(spi_imx->dev);
-- 
2.39.1


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

* [PATCH 2/2] spi: imx: Convert to platform remove callback returning void
  2023-03-06  6:57 [PATCH 0/2] spi: imx: Fix cleanup in remove and convert to .remove_new() Uwe Kleine-König
  2023-03-06  6:57 ` [PATCH 1/2] spi: imx: Don't skip cleanup in remove's error path Uwe Kleine-König
@ 2023-03-06  6:57 ` Uwe Kleine-König
  2023-03-20 18:50 ` [PATCH 0/2] spi: imx: Fix cleanup in remove and convert to .remove_new() Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Uwe Kleine-König @ 2023-03-06  6:57 UTC (permalink / raw)
  To: Mark Brown, Shawn Guo, Sascha Hauer
  Cc: Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team,
	linux-spi, linux-arm-kernel, linux-kernel

The .remove() callback for a platform driver returns an int which makes
many driver authors wrongly assume it's possible to do error handling by
returning an error code. However the value returned is (mostly) ignored
and this typically results in resource leaks. To improve here there is a
quest to make the remove callback return void. In the first step of this
quest all drivers are converted to .remove_new() which already returns
void.

Trivially convert this driver from always returning zero in the remove
callback to the void returning variant.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/spi/spi-imx.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index 6c9c87cd14ca..f128fb296d49 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -1848,7 +1848,7 @@ static int spi_imx_probe(struct platform_device *pdev)
 	return ret;
 }
 
-static int spi_imx_remove(struct platform_device *pdev)
+static void spi_imx_remove(struct platform_device *pdev)
 {
 	struct spi_controller *controller = platform_get_drvdata(pdev);
 	struct spi_imx_data *spi_imx = spi_controller_get_devdata(controller);
@@ -1867,8 +1867,6 @@ static int spi_imx_remove(struct platform_device *pdev)
 	pm_runtime_disable(spi_imx->dev);
 
 	spi_imx_sdma_exit(spi_imx);
-
-	return 0;
 }
 
 static int __maybe_unused spi_imx_runtime_resume(struct device *dev)
@@ -1930,7 +1928,7 @@ static struct platform_driver spi_imx_driver = {
 		   .pm = &imx_spi_pm,
 	},
 	.probe = spi_imx_probe,
-	.remove = spi_imx_remove,
+	.remove_new = spi_imx_remove,
 };
 module_platform_driver(spi_imx_driver);
 
-- 
2.39.1


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

* Re: [PATCH 0/2] spi: imx: Fix cleanup in remove and convert to .remove_new()
  2023-03-06  6:57 [PATCH 0/2] spi: imx: Fix cleanup in remove and convert to .remove_new() Uwe Kleine-König
  2023-03-06  6:57 ` [PATCH 1/2] spi: imx: Don't skip cleanup in remove's error path Uwe Kleine-König
  2023-03-06  6:57 ` [PATCH 2/2] spi: imx: Convert to platform remove callback returning void Uwe Kleine-König
@ 2023-03-20 18:50 ` Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2023-03-20 18:50 UTC (permalink / raw)
  To: Shawn Guo, Sascha Hauer, Stefan Agner, Uwe Kleine-König
  Cc: Uwe Kleine-König, Pengutronix Kernel Team, Fabio Estevam,
	NXP Linux Team, linux-spi, linux-arm-kernel, linux-kernel

On Mon, 06 Mar 2023 07:57:31 +0100, Uwe Kleine-König wrote:
> this small series converts the spi-imx driver to .remove_new(). The
> motivation for this tree-wide effort are drivers that don't properly
> cleanup and return an error code. This is broken as this results in
> resource leaks. The spi-imx driver is such a driver. The idea is that if
> the remove callback returns void it's obvious that an early error return
> is wrong.
> 
> [...]

Applied to

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

Thanks!

[1/2] spi: imx: Don't skip cleanup in remove's error path
      commit: 11951c9e3f364d7ae3b568a0e52c8335d43066b5
[2/2] spi: imx: Convert to platform remove callback returning void
      commit: 423e548127223d597bb65a149ebcb3c50ea08846

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:[~2023-03-20 18:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-06  6:57 [PATCH 0/2] spi: imx: Fix cleanup in remove and convert to .remove_new() Uwe Kleine-König
2023-03-06  6:57 ` [PATCH 1/2] spi: imx: Don't skip cleanup in remove's error path Uwe Kleine-König
2023-03-06  6:57 ` [PATCH 2/2] spi: imx: Convert to platform remove callback returning void Uwe Kleine-König
2023-03-20 18:50 ` [PATCH 0/2] spi: imx: Fix cleanup in remove and convert to .remove_new() 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).