Skip to content

Commit b3b9596

Browse files
author
Bartosz Golaszewski
committed
gpio: cdev: check for NULL labels when sanitizing them for irqs
We need to take into account that a line's consumer label may be NULL and not try to kstrdup() it in that case but rather pass the NULL pointer up the stack to the interrupt request function. To that end: let make_irq_label() return NULL as a valid return value and use ERR_PTR() instead to signal an allocation failure to callers. Cc: [email protected] Fixes: b344908 ("gpio: cdev: sanitize the label before requesting the interrupt") Reported-by: Linux Kernel Functional Testing <[email protected]> Closes: https://lore.kernel.org/lkml/[email protected]/ Signed-off-by: Bartosz Golaszewski <[email protected]> Tested-by: Anders Roxell <[email protected]>
1 parent e8acd2d commit b3b9596

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

drivers/gpio/gpiolib-cdev.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,16 @@ static u32 gpio_v2_line_config_debounce_period(struct gpio_v2_line_config *lc,
10851085

10861086
static inline char *make_irq_label(const char *orig)
10871087
{
1088-
return kstrdup_and_replace(orig, '/', ':', GFP_KERNEL);
1088+
char *new;
1089+
1090+
if (!orig)
1091+
return NULL;
1092+
1093+
new = kstrdup_and_replace(orig, '/', ':', GFP_KERNEL);
1094+
if (!new)
1095+
return ERR_PTR(-ENOMEM);
1096+
1097+
return new;
10891098
}
10901099

10911100
static inline void free_irq_label(const char *label)
@@ -1158,8 +1167,8 @@ static int edge_detector_setup(struct line *line,
11581167
irqflags |= IRQF_ONESHOT;
11591168

11601169
label = make_irq_label(line->req->label);
1161-
if (!label)
1162-
return -ENOMEM;
1170+
if (IS_ERR(label))
1171+
return PTR_ERR(label);
11631172

11641173
/* Request a thread to read the events */
11651174
ret = request_threaded_irq(irq, edge_irq_handler, edge_irq_thread,
@@ -2217,8 +2226,8 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
22172226
goto out_free_le;
22182227

22192228
label = make_irq_label(le->label);
2220-
if (!label) {
2221-
ret = -ENOMEM;
2229+
if (IS_ERR(label)) {
2230+
ret = PTR_ERR(label);
22222231
goto out_free_le;
22232232
}
22242233

0 commit comments

Comments
 (0)