* [PATCH v1 1/1] gpio: merrifield: Protect irq_ack() and gpio_set() by lock
@ 2016-07-11 10:06 Andy Shevchenko
2016-07-11 12:22 ` Linus Walleij
0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2016-07-11 10:06 UTC (permalink / raw)
To: linux-gpio, Linus Walleij, Mika Westerberg, David Cohen; +Cc: Andy Shevchenko
There is a potential race when two threads do the writes to the same register
in parallel.
Prevent out of order in such case by protecting I/O access by spin lock.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/gpio/gpio-merrifield.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/drivers/gpio/gpio-merrifield.c b/drivers/gpio/gpio-merrifield.c
index 11066f6..45b5127 100644
--- a/drivers/gpio/gpio-merrifield.c
+++ b/drivers/gpio/gpio-merrifield.c
@@ -105,7 +105,11 @@ static int mrfld_gpio_get(struct gpio_chip *chip, unsigned int offset)
static void mrfld_gpio_set(struct gpio_chip *chip, unsigned int offset,
int value)
{
+ struct mrfld_gpio *priv = gpiochip_get_data(chip);
void __iomem *gpsr, *gpcr;
+ unsigned long flags;
+
+ raw_spin_lock_irqsave(&priv->lock, flags);
if (value) {
gpsr = gpio_reg(chip, offset, GPSR);
@@ -114,6 +118,8 @@ static void mrfld_gpio_set(struct gpio_chip *chip, unsigned int offset,
gpcr = gpio_reg(chip, offset, GPCR);
writel(BIT(offset % 32), gpcr);
}
+
+ raw_spin_unlock_irqrestore(&priv->lock, flags);
}
static int mrfld_gpio_direction_input(struct gpio_chip *chip,
@@ -160,8 +166,13 @@ static void mrfld_irq_ack(struct irq_data *d)
struct mrfld_gpio *priv = irq_data_get_irq_chip_data(d);
u32 gpio = irqd_to_hwirq(d);
void __iomem *gisr = gpio_reg(&priv->chip, gpio, GISR);
+ unsigned long flags;
+
+ raw_spin_lock_irqsave(&priv->lock, flags);
writel(BIT(gpio % 32), gisr);
+
+ raw_spin_unlock_irqrestore(&priv->lock, flags);
}
static void mrfld_irq_unmask_mask(struct irq_data *d, bool unmask)
--
2.8.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v1 1/1] gpio: merrifield: Protect irq_ack() and gpio_set() by lock
2016-07-11 10:06 [PATCH v1 1/1] gpio: merrifield: Protect irq_ack() and gpio_set() by lock Andy Shevchenko
@ 2016-07-11 12:22 ` Linus Walleij
2016-07-11 12:57 ` Andy Shevchenko
0 siblings, 1 reply; 3+ messages in thread
From: Linus Walleij @ 2016-07-11 12:22 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: linux-gpio@vger.kernel.org, Mika Westerberg, David Cohen
On Mon, Jul 11, 2016 at 12:06 PM, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
> There is a potential race when two threads do the writes to the same register
> in parallel.
>
> Prevent out of order in such case by protecting I/O access by spin lock.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Patch applied.
May I convince you to send a patch adding yourself as maintainer
for this driver in the MAINTAINERS file?
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v1 1/1] gpio: merrifield: Protect irq_ack() and gpio_set() by lock
2016-07-11 12:22 ` Linus Walleij
@ 2016-07-11 12:57 ` Andy Shevchenko
0 siblings, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2016-07-11 12:57 UTC (permalink / raw)
To: Linus Walleij; +Cc: linux-gpio@vger.kernel.org, Mika Westerberg, David Cohen
On Mon, 2016-07-11 at 14:22 +0200, Linus Walleij wrote:
> On Mon, Jul 11, 2016 at 12:06 PM, Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
>
> > There is a potential race when two threads do the writes to the same
> > register
> > in parallel.
> >
> > Prevent out of order in such case by protecting I/O access by spin
> > lock.
> >
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>
> Patch applied.
>
> May I convince you to send a patch adding yourself as maintainer
> for this driver in the MAINTAINERS file?
NP.
And pinctrl perhaps?
--
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-07-11 12:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-11 10:06 [PATCH v1 1/1] gpio: merrifield: Protect irq_ack() and gpio_set() by lock Andy Shevchenko
2016-07-11 12:22 ` Linus Walleij
2016-07-11 12:57 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).