Skip to content

Commit

Permalink
gpio: of: assign and read the hog pointer atomically
Browse files Browse the repository at this point in the history
The device nodes representing GPIO hogs cannot be deleted without
unregistering the GPIO chip so there's no need to serialize their access.
However we must ensure that users can get the right address so write and
read it atomically.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  • Loading branch information
Bartosz Golaszewski committed Feb 12, 2024
1 parent e348544 commit 8ce6fd8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions drivers/gpio/gpiolib-of.c
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ static int of_gpiochip_add_hog(struct gpio_chip *chip, struct device_node *hog)
return ret;

#ifdef CONFIG_OF_DYNAMIC
desc->hog = hog;
WRITE_ONCE(desc->hog, hog);
#endif
}

Expand Down Expand Up @@ -849,7 +849,7 @@ static void of_gpiochip_remove_hog(struct gpio_chip *chip,
struct gpio_desc *desc;

for_each_gpio_desc_with_flag(chip, desc, FLAG_IS_HOGGED)
if (desc->hog == hog)
if (READ_ONCE(desc->hog) == hog)
gpiochip_free_own_desc(desc);
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/gpio/gpiolib.c
Original file line number Diff line number Diff line change
Expand Up @@ -2330,7 +2330,7 @@ static bool gpiod_free_commit(struct gpio_desc *desc)
clear_bit(FLAG_EDGE_FALLING, &desc->flags);
clear_bit(FLAG_IS_HOGGED, &desc->flags);
#ifdef CONFIG_OF_DYNAMIC
desc->hog = NULL;
WRITE_ONCE(desc->hog, NULL);
#endif
ret = true;
}
Expand Down

0 comments on commit 8ce6fd8

Please sign in to comment.