Skip to content

Commit 49b326c

Browse files
IsaacJTgregkh
authored andcommitted
serial: sc16is7xx: setup GPIO controller later in probe
[ Upstream commit c8f71b4 ] The GPIO controller component of the sc16is7xx driver is setup too early, which can result in a race condition where another device tries to utilise the GPIO lines before the sc16is7xx device has finished initialising. This issue manifests itself as an Oops when the GPIO lines are configured: Unable to handle kernel read from unreadable memory at virtual address ... pc : sc16is7xx_gpio_direction_output+0x68/0x108 [sc16is7xx] lr : sc16is7xx_gpio_direction_output+0x4c/0x108 [sc16is7xx] ... Call trace: sc16is7xx_gpio_direction_output+0x68/0x108 [sc16is7xx] gpiod_direction_output_raw_commit+0x64/0x318 gpiod_direction_output+0xb0/0x170 create_gpio_led+0xec/0x198 gpio_led_probe+0x16c/0x4f0 platform_drv_probe+0x5c/0xb0 really_probe+0xe8/0x448 driver_probe_device+0xe8/0x138 __device_attach_driver+0x94/0x118 bus_for_each_drv+0x8c/0xe0 __device_attach+0x100/0x1b8 device_initial_probe+0x28/0x38 bus_probe_device+0xa4/0xb0 deferred_probe_work_func+0x90/0xe0 process_one_work+0x1c4/0x480 worker_thread+0x54/0x430 kthread+0x138/0x150 ret_from_fork+0x10/0x1c This patch moves the setup of the GPIO controller functions to later in the probe function, ensuring the sc16is7xx device has already finished initialising by the time other devices try to make use of the GPIO lines. The error handling has also been reordered to reflect the new initialisation order. Co-developed-by: Wen-chien Jesse Sung <[email protected]> Signed-off-by: Wen-chien Jesse Sung <[email protected]> Signed-off-by: Isaac True <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 45083b8 commit 49b326c

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

drivers/tty/serial/sc16is7xx.c

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,25 +1245,6 @@ static int sc16is7xx_probe(struct device *dev,
12451245
}
12461246
sched_set_fifo(s->kworker_task);
12471247

1248-
#ifdef CONFIG_GPIOLIB
1249-
if (devtype->nr_gpio) {
1250-
/* Setup GPIO cotroller */
1251-
s->gpio.owner = THIS_MODULE;
1252-
s->gpio.parent = dev;
1253-
s->gpio.label = dev_name(dev);
1254-
s->gpio.direction_input = sc16is7xx_gpio_direction_input;
1255-
s->gpio.get = sc16is7xx_gpio_get;
1256-
s->gpio.direction_output = sc16is7xx_gpio_direction_output;
1257-
s->gpio.set = sc16is7xx_gpio_set;
1258-
s->gpio.base = -1;
1259-
s->gpio.ngpio = devtype->nr_gpio;
1260-
s->gpio.can_sleep = 1;
1261-
ret = gpiochip_add_data(&s->gpio, s);
1262-
if (ret)
1263-
goto out_thread;
1264-
}
1265-
#endif
1266-
12671248
/* reset device, purging any pending irq / data */
12681249
regmap_write(s->regmap, SC16IS7XX_IOCONTROL_REG << SC16IS7XX_REG_SHIFT,
12691250
SC16IS7XX_IOCONTROL_SRESET_BIT);
@@ -1329,6 +1310,25 @@ static int sc16is7xx_probe(struct device *dev,
13291310
s->p[u].irda_mode = true;
13301311
}
13311312

1313+
#ifdef CONFIG_GPIOLIB
1314+
if (devtype->nr_gpio) {
1315+
/* Setup GPIO cotroller */
1316+
s->gpio.owner = THIS_MODULE;
1317+
s->gpio.parent = dev;
1318+
s->gpio.label = dev_name(dev);
1319+
s->gpio.direction_input = sc16is7xx_gpio_direction_input;
1320+
s->gpio.get = sc16is7xx_gpio_get;
1321+
s->gpio.direction_output = sc16is7xx_gpio_direction_output;
1322+
s->gpio.set = sc16is7xx_gpio_set;
1323+
s->gpio.base = -1;
1324+
s->gpio.ngpio = devtype->nr_gpio;
1325+
s->gpio.can_sleep = 1;
1326+
ret = gpiochip_add_data(&s->gpio, s);
1327+
if (ret)
1328+
goto out_thread;
1329+
}
1330+
#endif
1331+
13321332
/*
13331333
* Setup interrupt. We first try to acquire the IRQ line as level IRQ.
13341334
* If that succeeds, we can allow sharing the interrupt as well.
@@ -1348,18 +1348,19 @@ static int sc16is7xx_probe(struct device *dev,
13481348
if (!ret)
13491349
return 0;
13501350

1351-
out_ports:
1352-
for (i--; i >= 0; i--) {
1353-
uart_remove_one_port(&sc16is7xx_uart, &s->p[i].port);
1354-
clear_bit(s->p[i].port.line, &sc16is7xx_lines);
1355-
}
1356-
13571351
#ifdef CONFIG_GPIOLIB
13581352
if (devtype->nr_gpio)
13591353
gpiochip_remove(&s->gpio);
13601354

13611355
out_thread:
13621356
#endif
1357+
1358+
out_ports:
1359+
for (i--; i >= 0; i--) {
1360+
uart_remove_one_port(&sc16is7xx_uart, &s->p[i].port);
1361+
clear_bit(s->p[i].port.line, &sc16is7xx_lines);
1362+
}
1363+
13631364
kthread_stop(s->kworker_task);
13641365

13651366
out_clk:

0 commit comments

Comments
 (0)