* [PATCH] gpiolib: allocate memory atomically with a spinlock held
@ 2023-12-12 10:55 Bartosz Golaszewski
2023-12-12 12:32 ` Linus Walleij
2023-12-15 15:43 ` Bartosz Golaszewski
0 siblings, 2 replies; 3+ messages in thread
From: Bartosz Golaszewski @ 2023-12-12 10:55 UTC (permalink / raw)
To: Linus Walleij, Andy Shevchenko, Kent Gibson
Cc: linux-gpio, linux-kernel, Bartosz Golaszewski, Dan Carpenter
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
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>
---
drivers/gpio/gpiolib.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 4e190be75dc2..6efe44570333 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -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);
--
2.40.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] gpiolib: allocate memory atomically with a spinlock held
2023-12-12 10:55 [PATCH] gpiolib: allocate memory atomically with a spinlock held Bartosz Golaszewski
@ 2023-12-12 12:32 ` Linus Walleij
2023-12-15 15:43 ` Bartosz Golaszewski
1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2023-12-12 12:32 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Andy Shevchenko, Kent Gibson, linux-gpio, linux-kernel,
Bartosz Golaszewski, Dan Carpenter
On Tue, Dec 12, 2023 at 11:55 AM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> 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>
Makes sense.
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] gpiolib: allocate memory atomically with a spinlock held
2023-12-12 10:55 [PATCH] gpiolib: allocate memory atomically with a spinlock held Bartosz Golaszewski
2023-12-12 12:32 ` Linus Walleij
@ 2023-12-15 15:43 ` Bartosz Golaszewski
1 sibling, 0 replies; 3+ messages in thread
From: Bartosz Golaszewski @ 2023-12-15 15:43 UTC (permalink / raw)
To: Linus Walleij, Andy Shevchenko, Kent Gibson
Cc: linux-gpio, linux-kernel, Bartosz Golaszewski, Dan Carpenter
On Tue, Dec 12, 2023 at 11:55 AM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
>
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> 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>
> ---
> drivers/gpio/gpiolib.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 4e190be75dc2..6efe44570333 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -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);
>
> --
> 2.40.1
>
Patch applied.
Bart
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-12-15 15:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-12 10:55 [PATCH] gpiolib: allocate memory atomically with a spinlock held Bartosz Golaszewski
2023-12-12 12:32 ` Linus Walleij
2023-12-15 15:43 ` Bartosz Golaszewski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox