Skip to contentSkip to conversation

gpio: sim: fix a memory leak

PATCH In review Bartosz Golaszewski 2 participants 4 messages Feb 16, 2023 – Feb 17, 2023 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: sim: fix a memory leak

Fix an inverted logic bug in gpio_sim_remove_hogs() that leads to GPIO hog structures never being freed.

Fixes cb8c474e79be ("gpio: sim: new testing module")
---
 drivers/gpio/gpio-sim.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-sim.c +1 -1
index 60514bc5454f..9e3893b19e4f 100644
@@ -736,7 +736,7 @@ static void gpio_sim_remove_hogs(struct gpio_sim_device *dev)
 
 	gpiod_remove_hogs(dev->hogs);
 
-	for (hog = dev->hogs; !hog->chip_label; hog++) {
+	for (hog = dev->hogs; hog->chip_label; hog++) {
 		kfree(hog->chip_label);
 		kfree(hog->line_name);
 	}
Signature · 1 line
2.37.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Bartosz Golaszewski

Fix an inverted logic bug in gpio_sim_remove_hogs() that leads to GPIO hog structures never being freed.

Ha-ha, I stared to this code, and in the head I was "okay, this loop is until chip_label is *not* NULL, so should be fine".

At the same time, "! is hard to process", see for example 2754435d4c82 ("ACPI / battery: get rid of negations in conditions") which I had suggested.

P.S. But my patch I mentioned looks also good to have, no?

Quoted 23 lines
Fixes cb8c474e79be ("gpio: sim: new testing module")
---
 drivers/gpio/gpio-sim.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-sim.c +1 -1
index 60514bc5454f..9e3893b19e4f 100644
@@ -736,7 +736,7 @@ static void gpio_sim_remove_hogs(struct gpio_sim_device *dev)
 
 	gpiod_remove_hogs(dev->hogs);
 
-	for (hog = dev->hogs; !hog->chip_label; hog++) {
+	for (hog = dev->hogs; hog->chip_label; hog++) {
 		kfree(hog->chip_label);
 		kfree(hog->line_name);
 	}
Signature · 1 line
2.37.2
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 8 lines · Andy Shevchenko
Quoted 2 lines · Bartosz Golaszewski

Fix an inverted logic bug in gpio_sim_remove_hogs() that leads to GPIO hog structures never being freed.

Ha-ha, I stared to this code, and in the head I was "okay, this loop is until chip_label is *not* NULL, so should be fine".

Quoted 8 lines

At the same time, "! is hard to process", see for example 2754435d4c82 ("ACPI / battery: get rid of negations in conditions") which I had suggested.

P.S. But my patch I mentioned looks also good to have, no?

I don't think it matters. In fact - I'm not sure if the order was accidental or not anymore. :( If you want to discuss it further - please resend it as a regular patch on the list.

Bart

#3 lore raw
In reply to Bartosz Golaszewski
Quoted 25 lines · Bartosz Golaszewski

Fix an inverted logic bug in gpio_sim_remove_hogs() that leads to GPIO hog structures never being freed.

Fixes cb8c474e79be ("gpio: sim: new testing module")
---
 drivers/gpio/gpio-sim.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-sim.c +1 -2
index 60514bc5454f..9e3893b19e4f 100644
@@ -736,7 +736,7 @@ static void gpio_sim_remove_hogs(struct gpio_sim_device *dev)
 
        gpiod_remove_hogs(dev->hogs);
 
-       for (hog = dev->hogs; !hog->chip_label; hog++) {
+       for (hog = dev->hogs; hog->chip_label; hog++) {
                kfree(hog->chip_label);
                kfree(hog->line_name);
        }
--
Quoted 2 lines

2.37.2

Applied and fixed the email address used.

Bart