diff mbox series

gpio: sim: fix a memory leak

Message ID 20230216141555.116219-1-brgl@bgdev.pl
State New
Headers show
Series gpio: sim: fix a memory leak | expand

Commit Message

Bartosz Golaszewski Feb. 16, 2023, 2:15 p.m. UTC
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")
Reported-by: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr>
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
 drivers/gpio/gpio-sim.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Bartosz Golaszewski Feb. 16, 2023, 2:49 p.m. UTC | #1
On Thu, Feb 16, 2023 at 3:42 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Thu, Feb 16, 2023 at 03:15:55PM +0100, Bartosz Golaszewski wrote:
> > 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.
>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>
> 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
Bartosz Golaszewski Feb. 17, 2023, 11:05 a.m. UTC | #2
On Thu, Feb 16, 2023 at 3:16 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
>
> 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")
> Reported-by: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr>
> Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
> ---
>  drivers/gpio/gpio-sim.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c
> index 60514bc5454f..9e3893b19e4f 100644
> --- a/drivers/gpio/gpio-sim.c
> +++ b/drivers/gpio/gpio-sim.c
> @@ -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);
>         }
> --
> 2.37.2
>

Applied and fixed the email address used.

Bart
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c
index 60514bc5454f..9e3893b19e4f 100644
--- a/drivers/gpio/gpio-sim.c
+++ b/drivers/gpio/gpio-sim.c
@@ -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);
 	}