Skip to content

Commit

Permalink
ACPI / gpio: avoid warning for gpio hogging code
Browse files Browse the repository at this point in the history
The newly added acpi_gpiochip_scan_gpios function produces a few harmless
warnings:

drivers/gpio/gpiolib-acpi.c: In function ‘acpi_gpiochip_add’:
drivers/gpio/gpiolib-acpi.c:925:7: error: ‘dflags’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
drivers/gpio/gpiolib-acpi.c:925:9: error: ‘lflags’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

The problem is that he compiler cannot know that a negative return value
from fwnode_property_read_u32_array() or acpi_gpiochip_pin_to_gpio_offset()
implies that the IS_ERR(gpio_desc) is true, as the value could in theory
be below -MAX_ERRNO.

The function already initializes its output values to zero, and moving
that intialization a little higher up ensures that we can never have
uninitialized data in the caller.

Fixes: c80f1ba ("ACPI / gpio: Add hogging support")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
  • Loading branch information
Arnd Bergmann authored and Linus Walleij committed Nov 9, 2016
1 parent e027503 commit c82064f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions drivers/gpio/gpiolib-acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,10 @@ static struct gpio_desc *acpi_gpiochip_parse_own_gpio(
u32 gpios[2];
int ret;

*lflags = 0;
*dflags = 0;
*name = NULL;

ret = fwnode_property_read_u32_array(fwnode, "gpios", gpios,
ARRAY_SIZE(gpios));
if (ret < 0)
Expand All @@ -879,10 +883,6 @@ static struct gpio_desc *acpi_gpiochip_parse_own_gpio(
if (IS_ERR(desc))
return desc;

*lflags = 0;
*dflags = 0;
*name = NULL;

if (gpios[1])
*lflags |= GPIO_ACTIVE_LOW;

Expand Down

0 comments on commit c82064f

Please sign in to comment.