gpio: it87: balance superio enter/exit calls in error path
PATCH 1/1 gpio: it87: balance superio enter/exit calls in error path
We always call superio_enter() in it87_gpio_direction_out() but only call superio_exit() if the call to it87_gpio_set() succeeds. Move the label to balance the calls in error path as well.
--- drivers/gpio/gpio-it87.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpio/gpio-it87.c +1 -2
@@ -254,9 +254,8 @@ static int it87_gpio_direction_out(struct gpio_chip *chip,if (rc) goto exit; -superio_exit (); - exit: +superio_exit ();spin_unlock (&it87_gpio->lock);return rc; }
Signature · 1 line
2.51.0
Quoted 17 lines · Bartosz Golaszewski
We always call
superio_enter()init87_gpio_direction_out()but only callsuperio_exit()if the call toit87_gpio_set()succeeds. Move the label to balance the calls in error path as well.Fixes ef877a159072 ("gpio: it87: use new line value setter callbacks")Reported-by Daniel Gibson <[email protected]>Signed-off-by Bartosz Golaszewski <[email protected]>--- drivers/gpio/gpio-it87.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/gpio/gpio-it87.c +0
-0
drivers/gpio/gpio-it87.c static int it87_gpio_direction_out(struct gpio_chip *chip, · line 261
Quoted 10 lines
drivers/gpio/gpio-it87.c +1
-2@@ -254,9 +254,8 @@ static int it87_gpio_direction_out(struct gpio_chip *chip,if (rc) goto exit; -superio_exit (); - exit: +superio_exit ();spin_unlock (&it87_gpio->lock);return rc; }
Moving this after exit: means that superio_exit() is also called if superio_enter() failed, a few lines above this patch:
rc = superio_enter(); if (rc) goto exit;
I don't know if this is really wrong, but it looks fishy and this code behaved differently for years - in contrast to the change to skip superio_exit() if it87_gpio_set() failed, which is very recent, introduced when the return type of it87_gpio_set() was changed from void to int.
Probably (again, I don't know if this is actually wrong, I'm not that familiar with how this chip works) superio_exit() should remain above exit: and if(rc) goto exit; after rc = it87_gpio_set(chip, gpio_num, val); should be removed, so:
- if superio_enter() fails, its error code is returned, but superio_exit() is *not* called
- the it87_gpio_set(chip, gpio_num, val); return code is returned by it87_gpio_direction_out() no matter if it succeeds or fails, but in either case superio_exit() is called
Cheers,
Daniel
Bartosz Golaszewski
maintainerQuoted 43 lines · Daniel Gibson
Quoted 17 lines · Bartosz Golaszewski
We always call
superio_enter()init87_gpio_direction_out()but only callsuperio_exit()if the call toit87_gpio_set()succeeds. Move the label to balance the calls in error path as well.Fixes ef877a159072 ("gpio: it87: use new line value setter callbacks")Reported-by Daniel Gibson <[email protected]>Signed-off-by Bartosz Golaszewski <[email protected]>--- drivers/gpio/gpio-it87.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/gpio/gpio-it87.c +0
-0drivers/gpio/gpio-it87.c static int it87_gpio_direction_out(struct gpio_chip *chip, · line 261
Quoted 10 lines
drivers/gpio/gpio-it87.c +1
-2@@ -254,9 +254,8 @@ static int it87_gpio_direction_out(struct gpio_chip *chip,if (rc) goto exit; -superio_exit (); - exit: +superio_exit ();spin_unlock (&it87_gpio->lock);return rc; }Moving this after exit: means that
superio_exit()is also called ifsuperio_enter()failed, a few lines above this patch:rc = superio_enter(); if (rc) goto exit;I don't know if this is really wrong, but it looks fishy and this code behaved differently for years - in contrast to the change to skip
superio_exit()ifit87_gpio_set()failed, which is very recent, introduced when the return type ofit87_gpio_set()was changed from void to int.
Quoted 10 lines
Probably (again, I don't know if this is actually wrong, I'm not that familiar with how this chip works)
superio_exit()should remain aboveexit:andif(rc) goto exit;afterrc = it87_gpio_set(chip, gpio_num, val);should be removed, so:
- ifsuperio_enter()fails, its error code is returned, butsuperio_exit()is *not* called
- theit87_gpio_set(chip, gpio_num, val); return code is returned byit87_gpio_direction_out()no matter if it succeeds or fails, but in either casesuperio_exit()is called
You're probably right, I don't really know this chip either. I will send a better version.
Bart