Skip to content

Commit 7b99b5a

Browse files
prabhakarladBartosz Golaszewski
authored and
Bartosz Golaszewski
committed
gpiolib: Fix potential NULL pointer dereference in gpiod_get_label()
In `gpiod_get_label()`, it is possible that `srcu_dereference_check()` may return a NULL pointer, leading to a scenario where `label->str` is accessed without verifying if `label` itself is NULL. This patch adds a proper NULL check for `label` before accessing `label->str`. The check for `label->str != NULL` is removed because `label->str` can never be NULL if `label` is not NULL. This fixes the issue where the label name was being printed as `(efault)` when dumping the sysfs GPIO file when `label == NULL`. Fixes: 5a646e0 ("gpiolib: Return label, if set, for IRQ only line") Fixes: a86d276 ("gpiolib: fix the speed of descriptor label setting with SRCU") Signed-off-by: Lad Prabhakar <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent 5a431e5 commit 7b99b5a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/gpio/gpiolib.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ const char *gpiod_get_label(struct gpio_desc *desc)
114114
srcu_read_lock_held(&desc->gdev->desc_srcu));
115115

116116
if (test_bit(FLAG_USED_AS_IRQ, &flags))
117-
return label->str ?: "interrupt";
117+
return label ? label->str : "interrupt";
118118

119119
if (!test_bit(FLAG_REQUESTED, &flags))
120120
return NULL;
121121

122-
return label->str;
122+
return label ? label->str : NULL;
123123
}
124124

125125
static void desc_free_label(struct rcu_head *rh)

0 commit comments

Comments
 (0)