Skip to contentSkip to conversation

spi: balance remove-path teardown in three drivers

PATCH In review Guangshuo Li 3 participants 6 messages Sep 24 – Oct 5

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover spi: balance remove-path teardown in three drivers

Several SPI drivers establish resources or runtime-PM state during probe but do not perform the matching teardown after successful removal.

Add the missing unmap or runtime-PM cleanup in each driver's remove path, following the cleanup already used by its probe error paths.

Guangshuo Li (3):
spi: fsl: unmap immr_spi_cs on remove
spi: rockchip-sfc: Clean up runtime PM on remove
spi: bcm63xx-hsspi: Disable runtime PM on remove

 drivers/spi/spi-bcm63xx-hsspi.c | 1 +
 drivers/spi/spi-fsl-spi.c       | 8 ++++++++
 drivers/spi/spi-rockchip-sfc.c  | 6 ++++++
 3 files changed, 15 insertions(+)

base-commit: f03c39de3a1307371a4032757cd1732e91087c7d

Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/3 spi: fsl: unmap immr_spi_cs on remove

of_fsl_spi_remove() does not unmap pinfo->immr_spi_cs after a successful probe when CONFIG_FSL_SOC is enabled and fsl,spisel_boot causes of_fsl_spi_probe() to map it with ioremap(). The probe error path already performs the matching iounmap().

Retrieve pinfo from the platform data and call iounmap() when pinfo->immr_spi_cs is present, pairing normal removal with the mapping established by of_fsl_spi_probe().

Fixes 0f0581b24bd0 ("spi: fsl: Convert to use CS GPIO descriptors")
---
 drivers/spi/spi-fsl-spi.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/spi/spi-fsl-spi.c +8 -0
index e45816ef7b65..665902703973 100644
@@ -702,10 +702,18 @@ static void of_fsl_spi_remove(struct platform_device *ofdev)
 {
 	struct spi_controller *host = platform_get_drvdata(ofdev);
 	struct mpc8xxx_spi *mpc8xxx_spi = spi_controller_get_devdata(host);
+#if IS_ENABLED(CONFIG_FSL_SOC)
+	struct fsl_spi_platform_data *pdata = dev_get_platdata(&ofdev->dev);
+	struct mpc8xxx_spi_probe_info *pinfo = to_of_pinfo(pdata);
+#endif
 
 	spi_unregister_controller(host);
 
 	fsl_spi_cpm_free(mpc8xxx_spi);
+#if IS_ENABLED(CONFIG_FSL_SOC)
+	if (pinfo->immr_spi_cs)
+		iounmap(pinfo->immr_spi_cs);
+#endif
 }
 
 static struct platform_driver of_fsl_spi_driver = {
Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/3 spi: rockchip-sfc: Clean up runtime PM on remove

In reply to Guangshuo Li

rockchip_sfc_probe() enables runtime PM and autosuspend before registering the controller. After a successful probe, rockchip_sfc_remove() tears down the controller and clocks without undoing that runtime PM setup.

The probe error path resumes the device, drops the temporary usage count, disables runtime PM, marks the device suspended, and stops using autosuspend before disabling the clocks. The remove path lacks this matching cleanup.

Mirror the existing error-path sequence in rockchip_sfc_remove() before disabling the clocks.

Fixes 8011709906d0 ("spi: rockchip-sfc: Support pm ops")
---
 drivers/spi/spi-rockchip-sfc.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/spi/spi-rockchip-sfc.c +6 -0
index 662a994da60b..6e1c7d6318bb 100644
@@ -747,6 +747,12 @@ static void rockchip_sfc_remove(struct platform_device *pdev)
 			 DMA_BIDIRECTIONAL);
 	free_pages((unsigned long)sfc->buffer, get_order(sfc->max_iosize));
 
+	pm_runtime_get_sync(&pdev->dev);
+	pm_runtime_put_noidle(&pdev->dev);
+	pm_runtime_disable(&pdev->dev);
+	pm_runtime_set_suspended(&pdev->dev);
+	pm_runtime_dont_use_autosuspend(&pdev->dev);
+
 	clk_disable_unprepare(sfc->clk);
 	clk_disable_unprepare(sfc->hclk);
 }
Signature · 1 line
2.43.0
#3 lore raw

Re: [PATCH 2/3] spi: rockchip-sfc: Clean up runtime PM on remove

Hi Guangshuo

Quoted 4 lines · Guangshuo Li

rockchip_sfc_probe() enables runtime PM and autosuspend before registering the controller. After a successful probe, rockchip_sfc_remove() tears down the controller and clocks without undoing that runtime PM setup.

Quoted 8 lines

The probe error path resumes the device, drops the temporary usage count, disables runtime PM, marks the device suspended, and stops using autosuspend before disabling the clocks. The remove path lacks this matching cleanup.

Mirror the existing error-path sequence in rockchip_sfc_remove() before disabling the clocks.

Thanks for this patch. However, it was fixed, see:
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=34e32e9ade58e32daf933974c9b697d066fc5aaa

Quoted 13 lines
Fixes 8011709906d0 ("spi: rockchip-sfc: Support pm ops")
---
  drivers/spi/spi-rockchip-sfc.c | 6 ++++++
  1 file changed, 6 insertions(+)
drivers/spi/spi-rockchip-sfc.c +0 -0
index 662a994da60b..6e1c7d6318bb 100644
@@ -747,6 +747,12 @@ static void rockchip_sfc_remove(struct platform_device *pdev)
  			 DMA_BIDIRECTIONAL);
  	free_pages((unsigned long)sfc->buffer, get_order(sfc->max_iosize));

drivers/spi/spi-rockchip-sfc.c static void rockchip_sfc_remove(struct platform_device *pdev) · line 758

Quoted 10 lines
drivers/spi/spi-rockchip-sfc.c +6 -0
 
+	pm_runtime_get_sync(&pdev->dev);
+	pm_runtime_put_noidle(&pdev->dev);
+	pm_runtime_disable(&pdev->dev);
+	pm_runtime_set_suspended(&pdev->dev);
+	pm_runtime_dont_use_autosuspend(&pdev->dev);
+
  	clk_disable_unprepare(sfc->clk);
  	clk_disable_unprepare(sfc->hclk);
  }

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

#4 lore raw

PATCH 3/3 spi: bcm63xx-hsspi: Disable runtime PM on remove

In reply to Guangshuo Li

bcm63xx_hsspi_probe() enables runtime PM before creating the sysfs
group, but bcm63xx_hsspi_remove() does not perform the matching
pm_runtime_disable() after a successful probe.

The probe error paths already disable runtime PM when sysfs group creation or controller registration fails.

Add pm_runtime_disable() to the remove path after removing the sysfs group to balance pm_runtime_enable() from bcm63xx_hsspi_probe().

Fixes fb8695e3749e ("spi: bcm63xx-hsspi: fix pm_runtime")
---
 drivers/spi/spi-bcm63xx-hsspi.c | 1 +
 1 file changed, 1 insertion(+)
drivers/spi/spi-bcm63xx-hsspi.c +1 -0
index 25f169a2a81d..80bf02bc324a 100644
@@ -882,6 +882,7 @@ static void bcm63xx_hsspi_remove(struct platform_device *pdev)
 	/* reset the hardware and block queue progress */
 	__raw_writel(0, bs->regs + HSSPI_INT_MASK_REG);
 	sysfs_remove_group(&pdev->dev.kobj, &bcm63xx_hsspi_group);
+	pm_runtime_disable(&pdev->dev);
 }
 
 static int bcm63xx_hsspi_suspend(struct device *dev)
Signature · 1 line
2.43.0
maintainer
#5 lore raw

Re: (subset) [PATCH 0/3] spi: balance remove-path teardown in three drivers

In reply to Guangshuo Li
Quoted 9 lines · Guangshuo Li

spi: balance remove-path teardown in three drivers

Several SPI drivers establish resources or runtime-PM state during probe but do not perform the matching teardown after successful removal.

Add the missing unmap or runtime-PM cleanup in each driver's remove path, following the cleanup already used by its probe error paths.

[...]

Applied to

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

Thanks!

[1/3] spi: fsl: unmap immr_spi_cs on remove

      https://git.kernel.org/broonie/spi/c/af1d882d421d
[3/3] spi: bcm63xx-hsspi: Disable runtime PM on remove
      https://git.kernel.org/broonie/spi/c/38232bd3cea7

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