All of lore.kernel.org
 help / color / mirror / Atom feed
* [bug report] power: supply: generic-adc-battery: Use GPIO descriptors
@ 2020-12-04 14:51 Dan Carpenter
  2020-12-09 10:00 ` Linus Walleij
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2020-12-04 14:51 UTC (permalink / raw)
  To: linus.walleij; +Cc: linux-pm

Hello Linus Walleij,

The patch b0327ffb133f: "power: supply: generic-adc-battery: Use GPIO
descriptors" from Oct 30, 2020, leads to the following static checker
warning:

	drivers/power/supply/generic-adc-battery.c:97 gab_charge_finished()
	warn: signedness bug returning '(-4095)'

drivers/power/supply/generic-adc-battery.c
    93  static bool gab_charge_finished(struct gab *adc_bat)
    94  {
    95          if (!adc_bat->charge_finished)
    96                  return false;
    97          return gpiod_get_value(adc_bat->charge_finished);

The gpiod_get_value() can return negative error codes so it's not
necessarily clear if that should translate to a true as it does now or
to a false...

    98  }

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [bug report] power: supply: generic-adc-battery: Use GPIO descriptors
  2020-12-04 14:51 [bug report] power: supply: generic-adc-battery: Use GPIO descriptors Dan Carpenter
@ 2020-12-09 10:00 ` Linus Walleij
  0 siblings, 0 replies; 2+ messages in thread
From: Linus Walleij @ 2020-12-09 10:00 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Linux PM list

On Fri, Dec 4, 2020 at 3:53 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:

> The patch b0327ffb133f: "power: supply: generic-adc-battery: Use GPIO
> descriptors" from Oct 30, 2020, leads to the following static checker
> warning:
>
>         drivers/power/supply/generic-adc-battery.c:97 gab_charge_finished()
>         warn: signedness bug returning '(-4095)'
>
> drivers/power/supply/generic-adc-battery.c
>     93  static bool gab_charge_finished(struct gab *adc_bat)
>     94  {
>     95          if (!adc_bat->charge_finished)
>     96                  return false;
>     97          return gpiod_get_value(adc_bat->charge_finished);
>
> The gpiod_get_value() can return negative error codes so it's not
> necessarily clear if that should translate to a true as it does now or
> to a false...

It *can* do that but in 9999 cases out of 10000 it does not. Mostly
because it just boils down to readin a register and masking a bit
which does not fail. This only happens in the rare circumstance that
the GPIO is on some slow bus that lost contact with the bridged
device (such as an I2C or SPI chip).

I agree it is not a perfect (in the mathematical sense) API but
in most cases the odd case of this call returning negative is
ignored and there are thousands of in-kernel users.

If this is a real problem I would rather turn the call into a bool
and ignore errors on the few that care to test for them than trying
to augment all sites using this call to handle negative
return codes.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-12-09 10:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-04 14:51 [bug report] power: supply: generic-adc-battery: Use GPIO descriptors Dan Carpenter
2020-12-09 10:00 ` Linus Walleij

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.