Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpiolib: Fix of_node inconsistency

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>

authored by

Biju Das and committed by
Linus Walleij
6ff04974 f8ad8aa5

+2 -3
-3
drivers/gpio/gpiolib-of.c
··· 620 620 { 621 621 int status; 622 622 623 - if ((!chip->of_node) && (chip->parent)) 624 - chip->of_node = chip->parent->of_node; 625 - 626 623 if (!chip->of_node) 627 624 return 0; 628 625
+2
drivers/gpio/gpiolib.c
··· 1262 1262 /* If the gpiochip has an assigned OF node this takes precedence */ 1263 1263 if (chip->of_node) 1264 1264 gdev->dev.of_node = chip->of_node; 1265 + else 1266 + chip->of_node = gdev->dev.of_node; 1265 1267 #endif 1266 1268 1267 1269 gdev->id = ida_simple_get(&gpio_ida, 0, 0, GFP_KERNEL);