Skip to content

Commit 2e69af1

Browse files
committed
Merge tag 'gpio-fixes-for-v6.9-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux
Pull gpio fixes from Bartosz Golaszewski: - make sure GPIO devices are registered with the subsystem before trying to return them to a caller of gpio_device_find() - fix two issues with incorrect sanitization of the interrupt labels * tag 'gpio-fixes-for-v6.9-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux: gpio: cdev: fix missed label sanitizing in debounce_setup() gpio: cdev: check for NULL labels when sanitizing them for irqs gpiolib: Fix triggering "kobject: 'gpiochipX' is not initialized, yet" kobject_get() errors
2 parents 4c3fc34 + 8309234 commit 2e69af1

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

drivers/gpio/gpiolib-cdev.c

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,25 @@ static u32 line_event_id(int level)
728728
GPIO_V2_LINE_EVENT_FALLING_EDGE;
729729
}
730730

731+
static inline char *make_irq_label(const char *orig)
732+
{
733+
char *new;
734+
735+
if (!orig)
736+
return NULL;
737+
738+
new = kstrdup_and_replace(orig, '/', ':', GFP_KERNEL);
739+
if (!new)
740+
return ERR_PTR(-ENOMEM);
741+
742+
return new;
743+
}
744+
745+
static inline void free_irq_label(const char *label)
746+
{
747+
kfree(label);
748+
}
749+
731750
#ifdef CONFIG_HTE
732751

733752
static enum hte_return process_hw_ts_thread(void *p)
@@ -1015,6 +1034,7 @@ static int debounce_setup(struct line *line, unsigned int debounce_period_us)
10151034
{
10161035
unsigned long irqflags;
10171036
int ret, level, irq;
1037+
char *label;
10181038

10191039
/* try hardware */
10201040
ret = gpiod_set_debounce(line->desc, debounce_period_us);
@@ -1037,11 +1057,17 @@ static int debounce_setup(struct line *line, unsigned int debounce_period_us)
10371057
if (irq < 0)
10381058
return -ENXIO;
10391059

1060+
label = make_irq_label(line->req->label);
1061+
if (IS_ERR(label))
1062+
return -ENOMEM;
1063+
10401064
irqflags = IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING;
10411065
ret = request_irq(irq, debounce_irq_handler, irqflags,
1042-
line->req->label, line);
1043-
if (ret)
1066+
label, line);
1067+
if (ret) {
1068+
free_irq_label(label);
10441069
return ret;
1070+
}
10451071
line->irq = irq;
10461072
} else {
10471073
ret = hte_edge_setup(line, GPIO_V2_LINE_FLAG_EDGE_BOTH);
@@ -1083,16 +1109,6 @@ static u32 gpio_v2_line_config_debounce_period(struct gpio_v2_line_config *lc,
10831109
return 0;
10841110
}
10851111

1086-
static inline char *make_irq_label(const char *orig)
1087-
{
1088-
return kstrdup_and_replace(orig, '/', ':', GFP_KERNEL);
1089-
}
1090-
1091-
static inline void free_irq_label(const char *label)
1092-
{
1093-
kfree(label);
1094-
}
1095-
10961112
static void edge_detector_stop(struct line *line)
10971113
{
10981114
if (line->irq) {
@@ -1158,8 +1174,8 @@ static int edge_detector_setup(struct line *line,
11581174
irqflags |= IRQF_ONESHOT;
11591175

11601176
label = make_irq_label(line->req->label);
1161-
if (!label)
1162-
return -ENOMEM;
1177+
if (IS_ERR(label))
1178+
return PTR_ERR(label);
11631179

11641180
/* Request a thread to read the events */
11651181
ret = request_threaded_irq(irq, edge_irq_handler, edge_irq_thread,
@@ -2217,8 +2233,8 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
22172233
goto out_free_le;
22182234

22192235
label = make_irq_label(le->label);
2220-
if (!label) {
2221-
ret = -ENOMEM;
2236+
if (IS_ERR(label)) {
2237+
ret = PTR_ERR(label);
22222238
goto out_free_le;
22232239
}
22242240

drivers/gpio/gpiolib.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,9 @@ struct gpio_device *gpio_device_find(const void *data,
11751175

11761176
list_for_each_entry_srcu(gdev, &gpio_devices, list,
11771177
srcu_read_lock_held(&gpio_devices_srcu)) {
1178+
if (!device_is_registered(&gdev->dev))
1179+
continue;
1180+
11781181
guard(srcu)(&gdev->srcu);
11791182

11801183
gc = srcu_dereference(gdev->chip, &gdev->srcu);

0 commit comments

Comments
 (0)