Skip to contentSkip to conversation

gpio: it87: balance superio enter/exit calls in error path

PATCH Superseded Bartosz Golaszewski 3 participants 3 messages Dec 9, 2025 – Dec 10, 2025 GPIO

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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.

Fixes ef877a159072 ("gpio: it87: use new line value setter callbacks")
---
 drivers/gpio/gpio-it87.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpio/gpio-it87.c +1 -2
index 5d677bcfccf2..528ac1890613 100644
@@ -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
#1 lore raw
Quoted 17 lines · Bartosz Golaszewski

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.

Fixes ef877a159072 ("gpio: it87: use new line value setter callbacks")
---
 drivers/gpio/gpio-it87.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpio/gpio-it87.c +0 -0
index 5d677bcfccf2..528ac1890613 100644

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

#2 lore raw
Quoted 43 lines · Daniel Gibson
Quoted 17 lines · Bartosz Golaszewski

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.

Fixes ef877a159072 ("gpio: it87: use new line value setter callbacks")
---
 drivers/gpio/gpio-it87.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpio/gpio-it87.c +0 -0
index 5d677bcfccf2..528ac1890613 100644

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.

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 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

You're probably right, I don't really know this chip either. I will send a better version.

Bart