diff mbox series

[-next,3/6] spi: omap-uwire: Switch to use devm_spi_alloc_master()

Message ID 20220920134819.2981033-4-yangyingliang@huawei.com (mailing list archive)
State New, archived
Headers show
Series spi: Switch to use devm_spi_alloc_master() in some drivers | expand

Commit Message

Yang Yingliang Sept. 20, 2022, 1:48 p.m. UTC
Switch to use devm_spi_alloc_master() to simpify error path.

Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/spi/spi-omap-uwire.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

Lukas Wunner Sept. 23, 2022, 5:06 a.m. UTC | #1
On Tue, Sep 20, 2022 at 09:48:16PM +0800, Yang Yingliang wrote:
> @@ -476,7 +474,6 @@ static int uwire_probe(struct platform_device *pdev)
>  	if (IS_ERR(uwire->ck)) {
>  		status = PTR_ERR(uwire->ck);
>  		dev_dbg(&pdev->dev, "no functional clock?\n");
> -		spi_master_put(master);
>  		return status;
>  	}
>  	clk_prepare_enable(uwire->ck);

Change this hunk to return PTR_ERR(uwire->ck) directly without
assigning to status first.

> @@ -518,6 +515,7 @@ static int uwire_remove(struct platform_device *pdev)
>  
>  	spi_bitbang_stop(&uwire->bitbang);
>  	uwire_off(uwire);
> +	spi_master_put(uwire->bitbang.master);
>  	return 0;
>  }
>  

No, drop this hunk, it results in a use-after-free.

Thanks,

Lukas
diff mbox series

Patch

diff --git a/drivers/spi/spi-omap-uwire.c b/drivers/spi/spi-omap-uwire.c
index 29198e6815b2..f1e66f758d45 100644
--- a/drivers/spi/spi-omap-uwire.c
+++ b/drivers/spi/spi-omap-uwire.c
@@ -448,7 +448,6 @@  static void uwire_off(struct uwire_spi *uwire)
 {
 	uwire_write_reg(UWIRE_SR3, 0);
 	clk_disable_unprepare(uwire->ck);
-	spi_master_put(uwire->bitbang.master);
 }
 
 static int uwire_probe(struct platform_device *pdev)
@@ -457,7 +456,7 @@  static int uwire_probe(struct platform_device *pdev)
 	struct uwire_spi	*uwire;
 	int			status;
 
-	master = spi_alloc_master(&pdev->dev, sizeof(*uwire));
+	master = devm_spi_alloc_master(&pdev->dev, sizeof(*uwire));
 	if (!master)
 		return -ENODEV;
 
@@ -466,7 +465,6 @@  static int uwire_probe(struct platform_device *pdev)
 	uwire_base = devm_ioremap(&pdev->dev, UWIRE_BASE_PHYS, UWIRE_IO_SIZE);
 	if (!uwire_base) {
 		dev_dbg(&pdev->dev, "can't ioremap UWIRE\n");
-		spi_master_put(master);
 		return -ENOMEM;
 	}
 
@@ -476,7 +474,6 @@  static int uwire_probe(struct platform_device *pdev)
 	if (IS_ERR(uwire->ck)) {
 		status = PTR_ERR(uwire->ck);
 		dev_dbg(&pdev->dev, "no functional clock?\n");
-		spi_master_put(master);
 		return status;
 	}
 	clk_prepare_enable(uwire->ck);
@@ -518,6 +515,7 @@  static int uwire_remove(struct platform_device *pdev)
 
 	spi_bitbang_stop(&uwire->bitbang);
 	uwire_off(uwire);
+	spi_master_put(uwire->bitbang.master);
 	return 0;
 }