Skip to content

Commit

Permalink
gpiolib: allocate memory atomically with a spinlock held
Browse files Browse the repository at this point in the history
We will eventually switch to protecting the GPIO descriptors with a mutex
but until then, we need to allocate memory for the label copy atomically
while we're holding the global spinlock.

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/linux-gpio/62588146-eed6-42f7-ba26-160226b109fe@moroto.mountain/T/#u
Fixes: f8d05e2 ("gpiolib: remove gpiochip_is_requested()")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
  • Loading branch information
Bartosz Golaszewski committed Dec 15, 2023
1 parent d22f93c commit 0a10d10
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion drivers/gpio/gpiolib.c
Original file line number Diff line number Diff line change
Expand Up @@ -2399,7 +2399,15 @@ char *gpiochip_dup_line_label(struct gpio_chip *gc, unsigned int offset)
if (!test_bit(FLAG_REQUESTED, &desc->flags))
return NULL;

label = kstrdup(desc->label, GFP_KERNEL);
/*
* FIXME: Once we mark gpiod_direction_input/output() and
* gpiod_get_direction() with might_sleep(), we'll be able to protect
* the GPIO descriptors with mutex (while value setting operations will
* become lockless).
*
* Until this happens, this allocation needs to be atomic.
*/
label = kstrdup(desc->label, GFP_ATOMIC);
if (!label)
return ERR_PTR(-ENOMEM);

Expand Down

0 comments on commit 0a10d10

Please sign in to comment.