Skip to contentSkip to conversation

net: rfkill: gpio: fix memory leak in probe error path

PATCH In review Johan Hovold 2 participants 2 messages Apr 26, 2018

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

PATCH 1/1 net: rfkill: gpio: fix memory leak in probe error path

Make sure to free the rfkill device in case registration fails during probe.

Fixes 5e7ca3937fbe ("net: rfkill: gpio: convert to resource managed allocation")
Cc stable <[email protected]> # 3.13
Cc Heikki Krogerus <[email protected]>
---
 net/rfkill/rfkill-gpio.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
net/rfkill/rfkill-gpio.c +6 -1
index 41bd496531d4..00192a996be0 100644
@@ -137,13 +137,18 @@ static int rfkill_gpio_probe(struct platform_device *pdev)
 
 	ret = rfkill_register(rfkill->rfkill_dev);
 	if (ret < 0)
-		return ret;
+		goto err_destroy;
 
 	platform_set_drvdata(pdev, rfkill);
 
 	dev_info(&pdev->dev, "%s device registered.\n", rfkill->name);
 
 	return 0;
+
+err_destroy:
+	rfkill_destroy(rfkill->rfkill_dev);
+
+	return ret;
 }
 
 static int rfkill_gpio_remove(struct platform_device *pdev)
Signature · 1 line
2.17.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Johan Hovold

Make sure to free the rfkill device in case registration fails during probe.

Fixes 5e7ca3937fbe ("net: rfkill: gpio: convert to resource managed allocation")
Cc stable <[email protected]> # 3.13
Cc Heikki Krogerus <[email protected]>

Good catch. FWIW:

Quoted 31 lines
---
 net/rfkill/rfkill-gpio.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
net/rfkill/rfkill-gpio.c +6 -1
index 41bd496531d4..00192a996be0 100644
@@ -137,13 +137,18 @@ static int rfkill_gpio_probe(struct platform_device *pdev)
 
 	ret = rfkill_register(rfkill->rfkill_dev);
 	if (ret < 0)
-		return ret;
+		goto err_destroy;
 
 	platform_set_drvdata(pdev, rfkill);
 
 	dev_info(&pdev->dev, "%s device registered.\n", rfkill->name);
 
 	return 0;
+
+err_destroy:
+	rfkill_destroy(rfkill->rfkill_dev);
+
+	return ret;
 }
 
 static int rfkill_gpio_remove(struct platform_device *pdev)
Signature · 1 line
2.17.0
Signature · 1 line
heikki