[PATCH 05/12] gpio: it87: use new line value setter callbacks

Bartosz Golaszewski posted 12 patches 7 months, 4 weeks ago
[PATCH 05/12] gpio: it87: use new line value setter callbacks
Posted by Bartosz Golaszewski 7 months, 4 weeks ago
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

struct gpio_chip now has callbacks for setting line values that return
an integer, allowing to indicate failures. Convert the driver to using
them.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 drivers/gpio/gpio-it87.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/gpio/gpio-it87.c b/drivers/gpio/gpio-it87.c
index f332341fd4c8..d8184b527bac 100644
--- a/drivers/gpio/gpio-it87.c
+++ b/drivers/gpio/gpio-it87.c
@@ -213,8 +213,7 @@ static int it87_gpio_direction_in(struct gpio_chip *chip, unsigned gpio_num)
 	return rc;
 }
 
-static void it87_gpio_set(struct gpio_chip *chip,
-			  unsigned gpio_num, int val)
+static int it87_gpio_set(struct gpio_chip *chip, unsigned int gpio_num, int val)
 {
 	u8 mask, curr_vals;
 	u16 reg;
@@ -228,6 +227,8 @@ static void it87_gpio_set(struct gpio_chip *chip,
 		outb(curr_vals | mask, reg);
 	else
 		outb(curr_vals & ~mask, reg);
+
+	return 0;
 }
 
 static int it87_gpio_direction_out(struct gpio_chip *chip,
@@ -249,7 +250,9 @@ static int it87_gpio_direction_out(struct gpio_chip *chip,
 	/* set the output enable bit */
 	superio_set_mask(mask, group + it87_gpio->output_base);
 
-	it87_gpio_set(chip, gpio_num, val);
+	rc = it87_gpio_set(chip, gpio_num, val);
+	if (rc)
+		goto exit;
 
 	superio_exit();
 
@@ -264,7 +267,7 @@ static const struct gpio_chip it87_template_chip = {
 	.request		= it87_gpio_request,
 	.get			= it87_gpio_get,
 	.direction_input	= it87_gpio_direction_in,
-	.set			= it87_gpio_set,
+	.set_rv			= it87_gpio_set,
 	.direction_output	= it87_gpio_direction_out,
 	.base			= -1
 };

-- 
2.45.2
Re: [PATCH 05/12] gpio: it87: use new line value setter callbacks
Posted by Daniel Gibson 1 week, 4 days ago
Hi,
I got one nitpick/question about this, see below

On 4/23/25 09:15, Bartosz Golaszewski wrote:
> @@ -249,7 +250,9 @@ static int it87_gpio_direction_out(struct gpio_chip *chip,
>  	/* set the output enable bit */
>  	superio_set_mask(mask, group + it87_gpio->output_base);
>  
> -	it87_gpio_set(chip, gpio_num, val);
> +	rc = it87_gpio_set(chip, gpio_num, val);
> +	if (rc)
> +		goto exit;
>  >  	superio_exit();

Are you sure that superio_exit() should be skipped (with goto exit) in
case it87_gpio_set() fails?
After all, superio_enter() above (not visible here) succeeded,
only the it87_gpio_set() call failed.

Of course this is kinda academic because currently it87_gpio_set()
always returns 0, but if it ever doesn't, this might become a bug?

Cheers,
Daniel
Re: [PATCH 05/12] gpio: it87: use new line value setter callbacks
Posted by Bartosz Golaszewski 1 week, 3 days ago
On Sun, 7 Dec 2025 05:55:15 +0100, Daniel Gibson <daniel@gibson.sh> said:
> Hi,
> I got one nitpick/question about this, see below
>
> On 4/23/25 09:15, Bartosz Golaszewski wrote:
>> @@ -249,7 +250,9 @@ static int it87_gpio_direction_out(struct gpio_chip *chip,
>>  	/* set the output enable bit */
>>  	superio_set_mask(mask, group + it87_gpio->output_base);
>>
>> -	it87_gpio_set(chip, gpio_num, val);
>> +	rc = it87_gpio_set(chip, gpio_num, val);
>> +	if (rc)
>> +		goto exit;
>>  >  	superio_exit();
>
> Are you sure that superio_exit() should be skipped (with goto exit) in
> case it87_gpio_set() fails?
> After all, superio_enter() above (not visible here) succeeded,
> only the it87_gpio_set() call failed.
>
> Of course this is kinda academic because currently it87_gpio_set()
> always returns 0, but if it ever doesn't, this might become a bug?
>

Thanks for bringing it to my attention, you're probably right and thats's
just an unintentional omission on my part. Do you want to send a patch that
will fix it or do you prefer me to do it?

Bart
Re: [PATCH 05/12] gpio: it87: use new line value setter callbacks
Posted by Daniel Gibson 1 week, 3 days ago
On 12/8/25 05:48, Bartosz Golaszewski wrote:
> 
> Thanks for bringing it to my attention, you're probably right and thats's
> just an unintentional omission on my part. Do you want to send a patch that
> will fix it or do you prefer me to do it?
> 
> Bart

Thanks for the quick reply!

I'd prefer if you do it, I'm not too familiar with the kernel workflow.

Cheers,
Daniel