diff mbox series

[2/2] spi: sun4i: Fix memory leak on device removal

Message ID tencent_E465261B2BB2C1EBAF5C19912B9F19B7E107@qq.com (mailing list archive)
State New, archived
Headers show
Series spi: sunxi: Fix memory leak on device removal | expand

Commit Message

Woody Zhang Oct. 2, 2023, 6:29 a.m. UTC
Call spi_master_put to free the spi_master structure on device removal
and driver detachment.

Signed-off-by: Woody Zhang <woodylab@foxmail.com>
---
 drivers/spi/spi-sun4i.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Mark Brown Oct. 2, 2023, 1:02 p.m. UTC | #1
On Mon, Oct 02, 2023 at 02:29:59PM +0800, Woody Zhang wrote:

> Call spi_master_put to free the spi_master structure on device removal
> and driver detachment.

>  static void sun4i_spi_remove(struct platform_device *pdev)
>  {
> +	struct spi_master *master = dev_get_drvdata(&pdev->dev);
> +
>  	pm_runtime_force_suspend(&pdev->dev);
> +	spi_master_put(master);
>  }

This is just obviously buggy, it doesn't match the registration at all.
diff mbox series

Patch

diff --git a/drivers/spi/spi-sun4i.c b/drivers/spi/spi-sun4i.c
index b8947265d329..ba5690039f72 100644
--- a/drivers/spi/spi-sun4i.c
+++ b/drivers/spi/spi-sun4i.c
@@ -518,7 +518,10 @@  static int sun4i_spi_probe(struct platform_device *pdev)
 
 static void sun4i_spi_remove(struct platform_device *pdev)
 {
+	struct spi_master *master = dev_get_drvdata(&pdev->dev);
+
 	pm_runtime_force_suspend(&pdev->dev);
+	spi_master_put(master);
 }
 
 static const struct of_device_id sun4i_spi_match[] = {