Skip to contentSkip to conversation

gpio: mockup: Fix potential resource leakage when register a chip

PATCH In review Andy Shevchenko 2 participants 2 messages Sep 20, 2022

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

PATCH 1/1 gpio: mockup: Fix potential resource leakage when register a chip

If creation of software node fails, the locally allocated string array is left unfreed. Free it on error path.

Fixes 6fda593f3082 ("gpio: mockup: Convert to use software nodes")
---
 drivers/gpio/gpio-mockup.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpio/gpio-mockup.c +3 -1
index a2e505a7545c..d6e42159fe44 100644
@@ -533,8 +533,10 @@ static int __init gpio_mockup_register_chip(int idx)
 	}
 
 	fwnode = fwnode_create_software_node(properties, NULL);
-	if (IS_ERR(fwnode))
+	if (IS_ERR(fwnode)) {
+		kfree_strarray(line_names, ngpio);
 		return PTR_ERR(fwnode);
+	}
 
 	pdevinfo.name = "gpio-mockup";
 	pdevinfo.id = idx;
Signature · 1 line
2.35.1
#1 lore raw
Quoted 27 lines · Andy Shevchenko

If creation of software node fails, the locally allocated string array is left unfreed. Free it on error path.

Fixes 6fda593f3082 ("gpio: mockup: Convert to use software nodes")
---
 drivers/gpio/gpio-mockup.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpio/gpio-mockup.c +3 -2
index a2e505a7545c..d6e42159fe44 100644
@@ -533,8 +533,10 @@ static int __init gpio_mockup_register_chip(int idx)
        }
 
        fwnode = fwnode_create_software_node(properties, NULL);
-       if (IS_ERR(fwnode))
+       if (IS_ERR(fwnode)) {
+               kfree_strarray(line_names, ngpio);
                return PTR_ERR(fwnode);
+       }
 
        pdevinfo.name = "gpio-mockup";
        pdevinfo.id = idx;
--
Quoted 2 lines

2.35.1

Queued for fixes.

Bart