Linux GPIO subsystem development
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: linux-gpio@vger.kernel.org,
	Linus Walleij <linus.walleij@linaro.org>,
	Marc Zyngier <maz@kernel.org>,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	Loic Poulain <loic.poulain@linaro.org>,
	NXP Linux Team <linux-imx@nxp.com>, Peng Fan <peng.fan@nxp.com>,
	Shawn Guo <shawnguo@kernel.org>
Subject: Re: [PATCH v7 1/2] gpio: mxc: Protect GPIO irqchip RMW with bgpio spinlock
Date: Mon, 16 Jan 2023 11:22:03 +0100	[thread overview]
Message-ID: <fcaa6629-7f1d-9c31-16cd-613cd48d6675@denx.de> (raw)
In-Reply-To: <CAMRc=McBELorc-+rq1L9JcVYDJrcds2L_AGR2vwy1Vt19UgBKQ@mail.gmail.com>

On 1/16/23 10:55, Bartosz Golaszewski wrote:
> On Mon, Jan 16, 2023 at 10:50 AM Marek Vasut <marex@denx.de> wrote:
>>
>> 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: 07bd1a6cc7cbb ("MXC arch: Add gpio support for the whole platform")
>> Signed-off-by: Marek Vasut <marex@denx.de>
>> ---
>> Cc: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>> Cc: Linus Walleij <linus.walleij@linaro.org>
>> Cc: Loic Poulain <loic.poulain@linaro.org>
>> Cc: Marc Zyngier <maz@kernel.org>
>> Cc: NXP Linux Team <linux-imx@nxp.com>
>> Cc: Peng Fan <peng.fan@nxp.com>
>> Cc: Shawn Guo <shawnguo@kernel.org>
>> ---
>> V3: New patch
>> V4: Include linux/spinlock.h
>> V5: Use raw_spinlock per 3c938cc5cebcb ("gpio: use raw spinlock for gpio chip shadowed data")
>> V6: No change
>> V7: Rebase on current next-20230116
>> ---
>>   drivers/gpio/gpio-mxc.c | 11 +++++++++++
>>   1 file changed, 11 insertions(+)
>>
>> diff --git a/drivers/gpio/gpio-mxc.c b/drivers/gpio/gpio-mxc.c
>> index d5626c572d24e..2d9d498727f10 100644
>> --- a/drivers/gpio/gpio-mxc.c
>> +++ b/drivers/gpio/gpio-mxc.c
>> @@ -18,6 +18,7 @@
>>   #include <linux/module.h>
>>   #include <linux/platform_device.h>
>>   #include <linux/slab.h>
>> +#include <linux/spinlock.h>
>>   #include <linux/syscore_ops.h>
>>   #include <linux/gpio/driver.h>
>>   #include <linux/of.h>
>> @@ -159,6 +160,7 @@ static int gpio_set_irq_type(struct irq_data *d, u32 type)
>>   {
>>          struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
>>          struct mxc_gpio_port *port = gc->private;
>> +       unsigned long flags;
>>          u32 bit, val;
>>          u32 gpio_idx = d->hwirq;
>>          int edge;
>> @@ -197,6 +199,8 @@ static int gpio_set_irq_type(struct irq_data *d, u32 type)
>>                  return -EINVAL;
>>          }
>>
>> +       raw_spin_lock_irqsave(&port->gc.bgpio_lock, flags);
>> +
>>          if (GPIO_EDGE_SEL >= 0) {
>>                  val = readl(port->base + GPIO_EDGE_SEL);
>>                  if (edge == GPIO_INT_BOTH_EDGES)
>> @@ -217,15 +221,20 @@ static int gpio_set_irq_type(struct irq_data *d, u32 type)
>>          writel(1 << gpio_idx, port->base + GPIO_ISR);
>>          port->pad_type[gpio_idx] = type;
>>
>> +       raw_spin_unlock_irqrestore(&port->gc.bgpio_lock, flags);
>> +
>>          return 0;
>>   }
>>
>>   static void mxc_flip_edge(struct mxc_gpio_port *port, u32 gpio)
>>   {
>>          void __iomem *reg = port->base;
>> +       unsigned long flags;
>>          u32 bit, val;
>>          int edge;
>>
>> +       raw_spin_lock_irqsave(&port->gc.bgpio_lock, flags);
>> +
>>          reg += GPIO_ICR1 + ((gpio & 0x10) >> 2); /* lower or upper register */
>>          bit = gpio & 0xf;
>>          val = readl(reg);
>> @@ -243,6 +252,8 @@ static void mxc_flip_edge(struct mxc_gpio_port *port, u32 gpio)
>>                  return;
>>          }
>>          writel(val | (edge << (bit << 1)), reg);
>> +
>> +       raw_spin_unlock_irqrestore(&port->gc.bgpio_lock, flags);
>>   }
>>
>>   /* handle 32 interrupts in one status register */
>> --
>> 2.39.0
>>
> 
> Both now applied, thanks and sorry again.

Thanks !

      reply	other threads:[~2023-01-16 10:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-16  9:49 [PATCH v7 1/2] gpio: mxc: Protect GPIO irqchip RMW with bgpio spinlock Marek Vasut
2023-01-16  9:49 ` [PATCH v7 2/2] gpio: mxc: Always set GPIOs used as interrupt source to INPUT mode Marek Vasut
2023-01-16  9:55 ` [PATCH v7 1/2] gpio: mxc: Protect GPIO irqchip RMW with bgpio spinlock Bartosz Golaszewski
2023-01-16 10:22   ` Marek Vasut [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fcaa6629-7f1d-9c31-16cd-613cd48d6675@denx.de \
    --to=marex@denx.de \
    --cc=bgolaszewski@baylibre.com \
    --cc=brgl@bgdev.pl \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-imx@nxp.com \
    --cc=loic.poulain@linaro.org \
    --cc=maz@kernel.org \
    --cc=peng.fan@nxp.com \
    --cc=shawnguo@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox