Linux GPIO subsystem development
 help / color / mirror / Atom feed
* [PATCH v2] gpio: sloppy-logic-analyzer: Fix memory leak in gpio_la_poll_probe()
@ 2026-07-15  7:53 Abdun Nihaal
  2026-07-15  8:28 ` Wolfram Sang
  0 siblings, 1 reply; 2+ messages in thread
From: Abdun Nihaal @ 2026-07-15  7:53 UTC (permalink / raw)
  To: wsa+renesas; +Cc: Abdun Nihaal, linusw, brgl, linux-gpio, linux-kernel

The memory allocated for priv->blob.data is not freed in the error paths
that follow the fops_buf_size_set() call in gpio_la_poll_probe(), as
well as in the remove function. Fix that by using device managed action
to free the memory on remove.

Fixes: 7828b7bbbf20 ("gpio: add sloppy logic analyzer using polling")
Signed-off-by: Abdun Nihaal <nihaal@cse.iitm.ac.in>
---
Compile tested only. Issue found using static analysis.

v1->v2:
- Remove the return code check of fops_buf_size_set() to avoid
  confusion, since if that function fails, there is no memory leak.

Link to v1: https://lore.kernel.org/linux-gpio/20260710064838.153528-1-nihaal@cse.iitm.ac.in/

 drivers/gpio/gpio-sloppy-logic-analyzer.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/gpio/gpio-sloppy-logic-analyzer.c b/drivers/gpio/gpio-sloppy-logic-analyzer.c
index 2bbd308ca08e..aa23b5779802 100644
--- a/drivers/gpio/gpio-sloppy-logic-analyzer.c
+++ b/drivers/gpio/gpio-sloppy-logic-analyzer.c
@@ -160,6 +160,13 @@ static int fops_buf_size_get(void *data, u64 *val)
 	return 0;
 }
 
+static void fops_buf_release(void *data)
+{
+	struct gpio_la_poll_priv *priv = data;
+
+	vfree(priv->blob.data);
+}
+
 static int fops_buf_size_set(void *data, u64 val)
 {
 	struct gpio_la_poll_priv *priv = data;
@@ -238,6 +245,9 @@ static int gpio_la_poll_probe(struct platform_device *pdev)
 		return ret;
 
 	fops_buf_size_set(priv, GPIO_LA_DEFAULT_BUF_SIZE);
+	ret = devm_add_action_or_reset(dev, fops_buf_release, priv);
+	if (ret)
+		return ret;
 
 	priv->descs = devm_gpiod_get_array(dev, "probe", GPIOD_IN);
 	if (IS_ERR(priv->descs))
-- 
2.43.0


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

* Re: [PATCH v2] gpio: sloppy-logic-analyzer: Fix memory leak in gpio_la_poll_probe()
  2026-07-15  7:53 [PATCH v2] gpio: sloppy-logic-analyzer: Fix memory leak in gpio_la_poll_probe() Abdun Nihaal
@ 2026-07-15  8:28 ` Wolfram Sang
  0 siblings, 0 replies; 2+ messages in thread
From: Wolfram Sang @ 2026-07-15  8:28 UTC (permalink / raw)
  To: Abdun Nihaal; +Cc: linusw, brgl, linux-gpio, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 549 bytes --]

On Wed, Jul 15, 2026 at 01:23:08PM +0530, Abdun Nihaal wrote:
> The memory allocated for priv->blob.data is not freed in the error paths
> that follow the fops_buf_size_set() call in gpio_la_poll_probe(), as
> well as in the remove function. Fix that by using device managed action
> to free the memory on remove.
> 
> Fixes: 7828b7bbbf20 ("gpio: add sloppy logic analyzer using polling")
> Signed-off-by: Abdun Nihaal <nihaal@cse.iitm.ac.in>

Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

Thank you for tackling this!


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

end of thread, other threads:[~2026-07-15  8:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-15  7:53 [PATCH v2] gpio: sloppy-logic-analyzer: Fix memory leak in gpio_la_poll_probe() Abdun Nihaal
2026-07-15  8:28 ` Wolfram Sang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox