Skip to content

Commit

Permalink
gpiolib: Fix of_node inconsistency
Browse files Browse the repository at this point in the history
Some platforms are not setting of_node in the driver. On these platforms
defining gpio-reserved-ranges on device tree leads to kernel crash.

It is due to some parts of the gpio core relying on the driver to set up
of_node,while other parts do themselves.This inconsistent behaviour leads
to a crash.

gpiochip_add_data_with_key() calls gpiochip_init_valid_mask() with of_node
as NULL. of_gpiochip_add() fills "of_node" and calls
of_gpiochip_init_valid_mask().

The fix is to move the assignment to chip->of_node from of_gpiochip_add()
to gpiochip_add_data_with_key().

Signed-off-by: Biju Das <biju.das@bp.renesas.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Tested-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
  • Loading branch information
Biju Das authored and Linus Walleij committed Aug 10, 2018
1 parent f8ad8aa commit 6ff0497
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 0 additions & 3 deletions drivers/gpio/gpiolib-of.c
Original file line number Diff line number Diff line change
Expand Up @@ -620,9 +620,6 @@ int of_gpiochip_add(struct gpio_chip *chip)
{
int status;

if ((!chip->of_node) && (chip->parent))
chip->of_node = chip->parent->of_node;

if (!chip->of_node)
return 0;

Expand Down
2 changes: 2 additions & 0 deletions drivers/gpio/gpiolib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,8 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data,
/* If the gpiochip has an assigned OF node this takes precedence */
if (chip->of_node)
gdev->dev.of_node = chip->of_node;
else
chip->of_node = gdev->dev.of_node;
#endif

gdev->id = ida_simple_get(&gpio_ida, 0, 0, GFP_KERNEL);
Expand Down

0 comments on commit 6ff0497

Please sign in to comment.