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

gpiolib: allocate memory atomically with a spinlock held

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: f8d05e276b45 ("gpiolib: remove gpiochip_is_requested()")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

+9 -1
+9 -1
drivers/gpio/gpiolib.c
··· 2399 2399 if (!test_bit(FLAG_REQUESTED, &desc->flags)) 2400 2400 return NULL; 2401 2401 2402 - label = kstrdup(desc->label, GFP_KERNEL); 2402 + /* 2403 + * FIXME: Once we mark gpiod_direction_input/output() and 2404 + * gpiod_get_direction() with might_sleep(), we'll be able to protect 2405 + * the GPIO descriptors with mutex (while value setting operations will 2406 + * become lockless). 2407 + * 2408 + * Until this happens, this allocation needs to be atomic. 2409 + */ 2410 + label = kstrdup(desc->label, GFP_ATOMIC); 2403 2411 if (!label) 2404 2412 return ERR_PTR(-ENOMEM); 2405 2413