Skip to contentSkip to conversation

mtd: rawnand: lpc32xx_slc: fix GPIO descriptor leak on probe error and remove

PATCH Applied Haotian Zhang 4 participants 7 messages Oct 28, 2025 – Nov 4, 2025

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

PATCH 1/1 mtd: rawnand: lpc32xx_slc: fix GPIO descriptor leak on probe error and remove

The driver calls gpiod_get_optional() in the probe function but never calls gpiod_put() in the remove function or in the probe error path. This leads to a GPIO descriptor resource leak. The lpc32xx_mlc.c driver in the same directory handles this correctly by calling gpiod_put() on both paths.

Add gpiod_put() in the remove function and in the probe error path to fix the resource leak.

Fixes 6b923db2867c ("mtd: rawnand: lpc32xx_slc: switch to using gpiod API")
---
 drivers/mtd/nand/raw/lpc32xx_slc.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/mtd/nand/raw/lpc32xx_slc.c +2 -0
index b54d76547ffb..fea3705a2138 100644
@@ -937,6 +937,7 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
 	dma_release_channel(host->dma_chan);
 enable_wp:
 	lpc32xx_wp_enable(host);
+	gpiod_put(host->wp_gpio);
 
 	return res;
 }
@@ -962,6 +963,7 @@ static void lpc32xx_nand_remove(struct platform_device *pdev)
 	writel(tmp, SLC_CTRL(host->io_base));
 
 	lpc32xx_wp_enable(host);
+	gpiod_put(host->wp_gpio);
 }
 
 static int lpc32xx_nand_resume(struct platform_device *pdev)
Signature · 1 line
2.50.1.windows.1
maintainer Applied
#1 lore raw
Quoted 10 lines · Haotian Zhang

The driver calls gpiod_get_optional() in the probe function but never calls gpiod_put() in the remove function or in the probe error path. This leads to a GPIO descriptor resource leak. The lpc32xx_mlc.c driver in the same directory handles this correctly by calling gpiod_put() on both paths.

Add gpiod_put() in the remove function and in the probe error path to fix the resource leak.

[...]

Applied to nand/next, thanks!

[1/1] mtd: rawnand: lpc32xx_slc: fix GPIO descriptor leak on probe error and remove

      commit: 3ae23f77b6a0cd53b557ac69c98312f7be22f081

Patche(s) should be available on mtd/linux.git and will be part of the next PR (provided that no robot complains by then).

Kind regards,
Miquèl

#2 lore raw
In reply to Haotian Zhang
Quoted 11 lines · Haotian Zhang

The driver calls gpiod_get_optional() in the probe function but never calls gpiod_put() in the remove function or in the probe error path. This leads to a GPIO descriptor resource leak. The lpc32xx_mlc.c driver in the same directory handles this correctly by calling gpiod_put() on both paths.

Add gpiod_put() in the remove function and in the probe error path to fix the resource leak.

Fixes 6b923db2867c ("mtd: rawnand: lpc32xx_slc: switch to using gpiod API")

The problem is well identified, thank you for the fix.

Quoted 17 lines
---
  drivers/mtd/nand/raw/lpc32xx_slc.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/mtd/nand/raw/lpc32xx_slc.c +1 -0
index b54d76547ffb..fea3705a2138 100644
@@ -937,6 +937,7 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
  	dma_release_channel(host->dma_chan);
  enable_wp:
  	lpc32xx_wp_enable(host);
+	gpiod_put(host->wp_gpio);
 
  	return res;
  }

drivers/mtd/nand/raw/lpc32xx_slc.c static void lpc32xx_nand_remove(struct platform_device *pdev) · line 969

Quoted 7 lines
drivers/mtd/nand/raw/lpc32xx_slc.c +1 -0
@@ -962,6 +963,7 @@ static void lpc32xx_nand_remove(struct platform_device *pdev)
  	writel(tmp, SLC_CTRL(host->io_base));
 
  	lpc32xx_wp_enable(host);
+	gpiod_put(host->wp_gpio);
  }
 
  static int lpc32xx_nand_resume(struct platform_device *pdev)

The fix can be greatly improved though, I kindly ask you to send v2 by switching from gpiod_get_optional() to resource managed devm_gpiod_get_optional().

Thank you in advance.

Signature · 6 lines
Best wishes,
Vladimir

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
maintainer
#3 lore raw

Hello,

Quoted 31 lines · Vladimir Zapolskiy
Quoted 10 lines · Haotian Zhang

The driver calls gpiod_get_optional() in the probe function but never calls gpiod_put() in the remove function or in the probe error path. This leads to a GPIO descriptor resource leak. The lpc32xx_mlc.c driver in the same directory handles this correctly by calling gpiod_put() on both paths.
Add gpiod_put() in the remove function and in the probe error path to fix the resource leak.

Fixes 6b923db2867c ("mtd: rawnand: lpc32xx_slc: switch to using gpiod

API")

The problem is well identified, thank you for the fix.

Quoted 17 lines
---
  drivers/mtd/nand/raw/lpc32xx_slc.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/mtd/nand/raw/lpc32xx_slc.c +1 -0
index b54d76547ffb..fea3705a2138 100644
@@ -937,6 +937,7 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
  	dma_release_channel(host->dma_chan);
  enable_wp:
  	lpc32xx_wp_enable(host);
+	gpiod_put(host->wp_gpio);
    	return res;
  }
@@ -962,6 +963,7 @@ static void lpc32xx_nand_remove(struct platform_device *pdev)
  	writel(tmp, SLC_CTRL(host->io_base));
Quoted 8 lines

drivers/mtd/nand/raw/lpc32xx_slc.c static void lpc32xx_nand_remove(struct platform_device *pdev) · line 969

Quoted 4 lines
drivers/mtd/nand/raw/lpc32xx_slc.c +1 -0
    	lpc32xx_wp_enable(host);
+	gpiod_put(host->wp_gpio);
  }
    static int lpc32xx_nand_resume(struct platform_device *pdev)

The fix can be greatly improved though, I kindly ask you to send v2 by switching from gpiod_get_optional() to resource managed devm_gpiod_get_optional().

I've already applied this fix, however I will welcome a follow-up patch.

Thanks,
Miquèl

#4 lore raw

PATCH v2 1/1 mtd: rawnand: lpc32xx_slc: fix GPIO descriptor leak

In reply to Haotian Zhang

The driver calls gpiod_get_optional() in the probe function but never calls gpiod_put() in the remove function or in the probe error path. This leads to a GPIO descriptor resource leak. The lpc32xx_mlc.c driver in the same directory handles this correctly by calling gpiod_put() on both paths.

Switch to devm_gpiod_get_optional() to automatically manage GPIO descriptor resource.

Fixes 6b923db2867c ("mtd: rawnand: lpc32xx_slc: switch to using gpiod API")

Suggested by: Vladimir Zapolskiy <[email protected]>

---
Changes in v2:
-Switch to devm_gpiod_get_optional()

---
 drivers/mtd/nand/raw/lpc32xx_slc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/lpc32xx_slc.c +1 -1
index b54d76547ffb..3ca30e7dce33 100644
@@ -854,7 +854,7 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
 	}
 
 	/* Start with WP disabled, if available */
-	host->wp_gpio = gpiod_get_optional(&pdev->dev, NULL, GPIOD_OUT_LOW);
+	host->wp_gpio = devm_gpiod_get_optional(&pdev->dev, NULL, GPIOD_OUT_LOW);
 	res = PTR_ERR_OR_ZERO(host->wp_gpio);
 	if (res) {
 		if (res != -EPROBE_DEFER)
Signature · 1 line
2.50.1.windows.1
maintainer
#5 lore raw

Re: [PATCH v2] mtd: rawnand: lpc32xx_slc: fix GPIO descriptor leak

Hi,

drivers/mtd/nand/raw/lpc32xx_slc.c static int lpc32xx_nand_probe(struct platform_device *pdev) · line 858

Quoted 11 lines
drivers/mtd/nand/raw/lpc32xx_slc.c +1 -1
index b54d76547ffb..3ca30e7dce33 100644
@@ -854,7 +854,7 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
 	}
 
 	/* Start with WP disabled, if available */
-	host->wp_gpio = gpiod_get_optional(&pdev->dev, NULL, GPIOD_OUT_LOW);
+	host->wp_gpio = devm_gpiod_get_optional(&pdev->dev, NULL,
 	GPIOD_OUT_LOW);

Please send an update on top the previous patch which I already applied.

Thanks,
Miquèl

#6 lore raw

Re: [PATCH v2] mtd: rawnand: lpc32xx_slc: fix GPIO descriptor leak

In reply to Haotian Zhang
Quoted 2 lines

The driver calls gpiod_get_optional() in the probe function but never calls gpiod_put() in the remove function or in the probe

…

You may occasionally put more than 63 characters into text lines of such a change description.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.18-rc4#n658

Regards,
Markus