Skip to content

Commit ba5c5ef

Browse files
author
Bartosz Golaszewski
committed
gpio: initialize descriptor SRCU structure before adding OF-based chips
In certain situations we may end up taking the GPIO descriptor SRCU read lock in of_gpiochip_add() before the SRCU struct is initialized. Move the initialization before the call to of_gpiochip_add(). Fixes: be711ca ("gpio: add SRCU infrastructure to struct gpio_desc") Fixes: 1f2bcb8 ("gpio: protect the descriptor label with SRCU") Reported-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/oe-lkp/[email protected] Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent 5e62844 commit ba5c5ef

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

drivers/gpio/gpiolib.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -991,18 +991,14 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
991991
if (ret)
992992
goto err_cleanup_gdev_srcu;
993993

994-
ret = of_gpiochip_add(gc);
995-
if (ret)
996-
goto err_free_gpiochip_mask;
997-
998994
for (i = 0; i < gc->ngpio; i++) {
999995
struct gpio_desc *desc = &gdev->descs[i];
1000996

1001997
ret = init_srcu_struct(&desc->srcu);
1002998
if (ret) {
1003999
for (j = 0; j < i; j++)
10041000
cleanup_srcu_struct(&gdev->descs[j].srcu);
1005-
goto err_remove_of_chip;
1001+
goto err_free_gpiochip_mask;
10061002
}
10071003

10081004
if (gc->get_direction && gpiochip_line_is_valid(gc, i)) {
@@ -1014,10 +1010,14 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
10141010
}
10151011
}
10161012

1017-
ret = gpiochip_add_pin_ranges(gc);
1013+
ret = of_gpiochip_add(gc);
10181014
if (ret)
10191015
goto err_cleanup_desc_srcu;
10201016

1017+
ret = gpiochip_add_pin_ranges(gc);
1018+
if (ret)
1019+
goto err_remove_of_chip;
1020+
10211021
acpi_gpiochip_add(gc);
10221022

10231023
machine_gpiochip_add(gc);
@@ -1055,12 +1055,12 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
10551055
gpiochip_irqchip_free_valid_mask(gc);
10561056
err_remove_acpi_chip:
10571057
acpi_gpiochip_remove(gc);
1058-
err_cleanup_desc_srcu:
1059-
for (i = 0; i < gdev->ngpio; i++)
1060-
cleanup_srcu_struct(&gdev->descs[i].srcu);
10611058
err_remove_of_chip:
10621059
gpiochip_free_hogs(gc);
10631060
of_gpiochip_remove(gc);
1061+
err_cleanup_desc_srcu:
1062+
for (i = 0; i < gdev->ngpio; i++)
1063+
cleanup_srcu_struct(&gdev->descs[i].srcu);
10641064
err_free_gpiochip_mask:
10651065
gpiochip_remove_pin_ranges(gc);
10661066
gpiochip_free_valid_mask(gc);

0 commit comments

Comments
 (0)