[PATCH] can: softing_cs: fix memleak on registration failure

Subsystems: can network drivers, the rest

STALE1747d LANDED

Landed in mainline as ced4913efb0a on 2022-01-08.

2 messages, 2 authors, 2021-12-22 · open the first message on its own page

[PATCH] can: softing_cs: fix memleak on registration failure

From: Johan Hovold <johan@kernel.org>
Date: 2021-12-22 10:49:06

In case device registration fails during probe, the driver state and the
embedded platform device structure needs to be freed using
platform_device_put() to properly free all resources (e.g. the device
name).

Fixes: 0a0b7a5f7a04 ("can: add driver for Softing card")
Cc: stable@vger.kernel.org      # 2.6.38
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/net/can/softing/softing_cs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/can/softing/softing_cs.c b/drivers/net/can/softing/softing_cs.c
index 2e93ee792373..e5c939b63fa6 100644
--- a/drivers/net/can/softing/softing_cs.c
+++ b/drivers/net/can/softing/softing_cs.c
@@ -293,7 +293,7 @@ static int softingcs_probe(struct pcmcia_device *pcmcia)
 	return 0;
 
 platform_failed:
-	kfree(dev);
+	platform_device_put(pdev);
 mem_failed:
 pcmcia_bad:
 pcmcia_failed:
-- 
2.32.0

Re: [PATCH] can: softing_cs: fix memleak on registration failure

From: Greg KH <gregkh@linuxfoundation.org>
Date: 2021-12-22 11:05:27

On Wed, Dec 22, 2021 at 11:48:43AM +0100, Johan Hovold wrote:
quoted hunk
In case device registration fails during probe, the driver state and the
embedded platform device structure needs to be freed using
platform_device_put() to properly free all resources (e.g. the device
name).

Fixes: 0a0b7a5f7a04 ("can: add driver for Softing card")
Cc: stable@vger.kernel.org      # 2.6.38
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/net/can/softing/softing_cs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/can/softing/softing_cs.c b/drivers/net/can/softing/softing_cs.c
index 2e93ee792373..e5c939b63fa6 100644
--- a/drivers/net/can/softing/softing_cs.c
+++ b/drivers/net/can/softing/softing_cs.c
@@ -293,7 +293,7 @@ static int softingcs_probe(struct pcmcia_device *pcmcia)
 	return 0;
 
 platform_failed:
-	kfree(dev);
+	platform_device_put(pdev);
 mem_failed:
 pcmcia_bad:
 pcmcia_failed:
-- 
2.32.0
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help