Skip to content

Commit e546427

Browse files
Marek VasutBartosz Golaszewski
authored andcommitted
gpio: mxc: Protect GPIO irqchip RMW with bgpio spinlock
The driver currently performs register read-modify-write without locking in its irqchip part, this could lead to a race condition when configuring interrupt mode setting. Add the missing bgpio spinlock lock/unlock around the register read-modify-write. Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Marc Zyngier <maz@kernel.org> Fixes: 07bd1a6 ("MXC arch: Add gpio support for the whole platform") Signed-off-by: Marek Vasut <marex@denx.de> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
1 parent 5dc4c99 commit e546427

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

drivers/gpio/gpio-mxc.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/module.h>
1919
#include <linux/platform_device.h>
2020
#include <linux/slab.h>
21+
#include <linux/spinlock.h>
2122
#include <linux/syscore_ops.h>
2223
#include <linux/gpio/driver.h>
2324
#include <linux/of.h>
@@ -159,6 +160,7 @@ static int gpio_set_irq_type(struct irq_data *d, u32 type)
159160
{
160161
struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
161162
struct mxc_gpio_port *port = gc->private;
163+
unsigned long flags;
162164
u32 bit, val;
163165
u32 gpio_idx = d->hwirq;
164166
int edge;
@@ -197,6 +199,8 @@ static int gpio_set_irq_type(struct irq_data *d, u32 type)
197199
return -EINVAL;
198200
}
199201

202+
raw_spin_lock_irqsave(&port->gc.bgpio_lock, flags);
203+
200204
if (GPIO_EDGE_SEL >= 0) {
201205
val = readl(port->base + GPIO_EDGE_SEL);
202206
if (edge == GPIO_INT_BOTH_EDGES)
@@ -217,15 +221,20 @@ static int gpio_set_irq_type(struct irq_data *d, u32 type)
217221
writel(1 << gpio_idx, port->base + GPIO_ISR);
218222
port->pad_type[gpio_idx] = type;
219223

224+
raw_spin_unlock_irqrestore(&port->gc.bgpio_lock, flags);
225+
220226
return 0;
221227
}
222228

223229
static void mxc_flip_edge(struct mxc_gpio_port *port, u32 gpio)
224230
{
225231
void __iomem *reg = port->base;
232+
unsigned long flags;
226233
u32 bit, val;
227234
int edge;
228235

236+
raw_spin_lock_irqsave(&port->gc.bgpio_lock, flags);
237+
229238
reg += GPIO_ICR1 + ((gpio & 0x10) >> 2); /* lower or upper register */
230239
bit = gpio & 0xf;
231240
val = readl(reg);
@@ -243,6 +252,8 @@ static void mxc_flip_edge(struct mxc_gpio_port *port, u32 gpio)
243252
return;
244253
}
245254
writel(val | (edge << (bit << 1)), reg);
255+
256+
raw_spin_unlock_irqrestore(&port->gc.bgpio_lock, flags);
246257
}
247258

248259
/* handle 32 interrupts in one status register */

0 commit comments

Comments
 (0)