summaryrefslogtreecommitdiff
path: root/drivers/gpio/gpiolib-cdev.c
diff options
context:
space:
mode:
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>2024-01-05 19:08:36 +0300
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>2024-02-12 12:50:40 +0300
commit1f2bcb8c8ccdf9dc2e46f7986e1e22408506a6d6 (patch)
treeaeace51dfc6b2e69e1fd3ac751f73faf6f64d57b /drivers/gpio/gpiolib-cdev.c
parentbe711caa87c5c81d5dc00b244cac3a0b775adb18 (diff)
downloadlinux-1f2bcb8c8ccdf9dc2e46f7986e1e22408506a6d6.tar.xz
gpio: protect the descriptor label with SRCU
In order to ensure that the label is not freed while it's being accessed, let's protect it with SRCU and synchronize it everytime it's changed. Let's modify desc_set_label() to manage the memory used for the label as it can only be freed once synchronize_srcu() returns. 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>
Diffstat (limited to 'drivers/gpio/gpiolib-cdev.c')
-rw-r--r--drivers/gpio/gpiolib-cdev.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
index 2c0a0700762d..75f4912339a6 100644
--- a/drivers/gpio/gpiolib-cdev.c
+++ b/drivers/gpio/gpiolib-cdev.c
@@ -2297,6 +2297,7 @@ static void gpio_desc_to_lineinfo(struct gpio_desc *desc,
{
struct gpio_chip *gc = desc->gdev->chip;
unsigned long dflags;
+ const char *label;
memset(info, 0, sizeof(*info));
info->offset = gpio_chip_hwgpio(desc);
@@ -2305,9 +2306,12 @@ static void gpio_desc_to_lineinfo(struct gpio_desc *desc,
if (desc->name)
strscpy(info->name, desc->name, sizeof(info->name));
- if (gpiod_get_label(desc))
- strscpy(info->consumer, gpiod_get_label(desc),
- sizeof(info->consumer));
+ scoped_guard(srcu, &desc->srcu) {
+ label = gpiod_get_label(desc);
+ if (label)
+ strscpy(info->consumer, label,
+ sizeof(info->consumer));
+ }
dflags = READ_ONCE(desc->flags);
}