mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-28 21:33:52 +00:00
gpio: cdev: check for NULL labels when sanitizing them for irqs
commitb3b9596459
upstream. 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: stable@vger.kernel.org Fixes:b34490879b
("gpio: cdev: sanitize the label before requesting the interrupt") Reported-by: Linux Kernel Functional Testing <lkft@linaro.org> Closes: https://lore.kernel.org/lkml/20240402093534.212283-1-naresh.kamboju@linaro.org/ Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Tested-by: Anders Roxell <anders.roxell@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
63bd08629a
commit
d9f0804ab0
1 changed files with 14 additions and 5 deletions
|
@ -1012,7 +1012,16 @@ static u32 gpio_v2_line_config_debounce_period(struct gpio_v2_line_config *lc,
|
||||||
|
|
||||||
static inline char *make_irq_label(const char *orig)
|
static inline char *make_irq_label(const char *orig)
|
||||||
{
|
{
|
||||||
return kstrdup_and_replace(orig, '/', ':', GFP_KERNEL);
|
char *new;
|
||||||
|
|
||||||
|
if (!orig)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
new = kstrdup_and_replace(orig, '/', ':', GFP_KERNEL);
|
||||||
|
if (!new)
|
||||||
|
return ERR_PTR(-ENOMEM);
|
||||||
|
|
||||||
|
return new;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void free_irq_label(const char *label)
|
static inline void free_irq_label(const char *label)
|
||||||
|
@ -1086,8 +1095,8 @@ static int edge_detector_setup(struct line *line,
|
||||||
irqflags |= IRQF_ONESHOT;
|
irqflags |= IRQF_ONESHOT;
|
||||||
|
|
||||||
label = make_irq_label(line->req->label);
|
label = make_irq_label(line->req->label);
|
||||||
if (!label)
|
if (IS_ERR(label))
|
||||||
return -ENOMEM;
|
return PTR_ERR(label);
|
||||||
|
|
||||||
/* Request a thread to read the events */
|
/* Request a thread to read the events */
|
||||||
ret = request_threaded_irq(irq, edge_irq_handler, edge_irq_thread,
|
ret = request_threaded_irq(irq, edge_irq_handler, edge_irq_thread,
|
||||||
|
@ -2194,8 +2203,8 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
|
||||||
goto out_free_le;
|
goto out_free_le;
|
||||||
|
|
||||||
label = make_irq_label(le->label);
|
label = make_irq_label(le->label);
|
||||||
if (!label) {
|
if (IS_ERR(label)) {
|
||||||
ret = -ENOMEM;
|
ret = PTR_ERR(label);
|
||||||
goto out_free_le;
|
goto out_free_le;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue