Skip to content

Commit 4d68f2c

Browse files
johankorsmb49
authored andcommitted
gpio: vf610: add locking to gpio direction functions
BugLink: https://bugs.launchpad.net/bugs/2107437 [ Upstream commit 4e667a1 ] Add locking to `vf610_gpio_direction_input|output()` functions. Without this locking, a race condition exists between concurrent calls to these functions, potentially leading to incorrect GPIO direction settings. To verify the correctness of this fix, a `trylock` patch was applied, where after a couple of reboots the race was confirmed. I.e., one user had to wait before acquiring the lock. With this patch the race has not been encountered. It's worth mentioning that any type of debugging (printing, tracing, etc.) would "resolve"/hide the issue. Fixes: 659d8a6 ("gpio: vf610: add imx7ulp support") Signed-off-by: Johan Korsnes <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Reviewed-by: Haibo Chen <[email protected]> Cc: Bartosz Golaszewski <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bartosz Golaszewski <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Noah Wager <[email protected]> Signed-off-by: Stefan Bader <[email protected]>
1 parent e49b2d6 commit 4d68f2c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/gpio/gpio-vf610.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ struct vf610_gpio_port {
3636
struct clk *clk_port;
3737
struct clk *clk_gpio;
3838
int irq;
39+
spinlock_t lock; /* protect gpio direction registers */
3940
};
4041

4142
#define GPIO_PDOR 0x00
@@ -124,6 +125,7 @@ static int vf610_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
124125
u32 val;
125126

126127
if (port->sdata->have_paddr) {
128+
guard(spinlock_irqsave)(&port->lock);
127129
val = vf610_gpio_readl(port->gpio_base + GPIO_PDDR);
128130
val &= ~mask;
129131
vf610_gpio_writel(val, port->gpio_base + GPIO_PDDR);
@@ -142,6 +144,7 @@ static int vf610_gpio_direction_output(struct gpio_chip *chip, unsigned gpio,
142144
vf610_gpio_set(chip, gpio, value);
143145

144146
if (port->sdata->have_paddr) {
147+
guard(spinlock_irqsave)(&port->lock);
145148
val = vf610_gpio_readl(port->gpio_base + GPIO_PDDR);
146149
val |= mask;
147150
vf610_gpio_writel(val, port->gpio_base + GPIO_PDDR);
@@ -284,6 +287,7 @@ static int vf610_gpio_probe(struct platform_device *pdev)
284287
return -ENOMEM;
285288

286289
port->sdata = device_get_match_data(dev);
290+
spin_lock_init(&port->lock);
287291

288292
dual_base = port->sdata->have_dual_base;
289293

0 commit comments

Comments
 (0)