linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] GPIO, Fix bug where the wrong GPIO register is written to
@ 2020-01-25 22:14 Paul Thomas
  2020-01-26 21:31 ` Andrew Lunn
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Paul Thomas @ 2020-01-25 22:14 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Michal Simek, linux-gpio,
	linux-arm-kernel, linux-kernel
  Cc: Paul Thomas

Care is taken with "index", however with the current version
the actual xgpio_writereg is using index for data but
xgpio_regoffset(chip, i) for the offset. And since i is already
incremented it is incorrect. This patch fixes it so that index
is used for the offset too.

Signed-off-by: Paul Thomas <pthomas8589@gmail.com>
---
 There are many different ways to correct this, I'd just like it to get
 fixed. I've tested this with a 5.2 kernel, but this patch is against
 5.5rc7.

 drivers/gpio/gpio-xilinx.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c
index a9748b5198e6..67f9f82e0db0 100644
--- a/drivers/gpio/gpio-xilinx.c
+++ b/drivers/gpio/gpio-xilinx.c
@@ -147,9 +147,10 @@ static void xgpio_set_multiple(struct gpio_chip *gc, unsigned long *mask,
 	for (i = 0; i < gc->ngpio; i++) {
 		if (*mask == 0)
 			break;
+		/* Once finished with an index write it out to the register */
 		if (index !=  xgpio_index(chip, i)) {
 			xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET +
-				       xgpio_regoffset(chip, i),
+				       index * XGPIO_CHANNEL_OFFSET,
 				       chip->gpio_state[index]);
 			spin_unlock_irqrestore(&chip->gpio_lock[index], flags);
 			index =  xgpio_index(chip, i);
@@ -165,7 +166,7 @@ static void xgpio_set_multiple(struct gpio_chip *gc, unsigned long *mask,
 	}
 
 	xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET +
-		       xgpio_regoffset(chip, i), chip->gpio_state[index]);
+		       index * XGPIO_CHANNEL_OFFSET, chip->gpio_state[index]);
 
 	spin_unlock_irqrestore(&chip->gpio_lock[index], flags);
 }
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] GPIO, Fix bug where the wrong GPIO register is written to
  2020-01-25 22:14 [PATCH] GPIO, Fix bug where the wrong GPIO register is written to Paul Thomas
@ 2020-01-26 21:31 ` Andrew Lunn
  2020-01-27  7:42 ` Michal Simek
  2020-02-10 11:52 ` Linus Walleij
  2 siblings, 0 replies; 5+ messages in thread
From: Andrew Lunn @ 2020-01-26 21:31 UTC (permalink / raw)
  To: Paul Thomas
  Cc: Linus Walleij, Bartosz Golaszewski, Michal Simek, linux-gpio,
	linux-arm-kernel, linux-kernel

On Sat, Jan 25, 2020 at 05:14:10PM -0500, Paul Thomas wrote:
> Care is taken with "index", however with the current version
> the actual xgpio_writereg is using index for data but
> xgpio_regoffset(chip, i) for the offset. And since i is already
> incremented it is incorrect. This patch fixes it so that index
> is used for the offset too.
> 
> Signed-off-by: Paul Thomas <pthomas8589@gmail.com>

Hi Paul

Please put Xilinx into the subject line. I had to actually look at the
patch to decide it was not relevant to me.

      Andrew

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] GPIO, Fix bug where the wrong GPIO register is written to
  2020-01-25 22:14 [PATCH] GPIO, Fix bug where the wrong GPIO register is written to Paul Thomas
  2020-01-26 21:31 ` Andrew Lunn
@ 2020-01-27  7:42 ` Michal Simek
  2020-02-10 11:52 ` Linus Walleij
  2 siblings, 0 replies; 5+ messages in thread
From: Michal Simek @ 2020-01-27  7:42 UTC (permalink / raw)
  To: Paul Thomas, Linus Walleij, Bartosz Golaszewski, Michal Simek,
	linux-gpio, linux-arm-kernel, linux-kernel, Shubhrajyoti Datta

On 25. 01. 20 23:14, Paul Thomas wrote:
> Care is taken with "index", however with the current version
> the actual xgpio_writereg is using index for data but
> xgpio_regoffset(chip, i) for the offset. And since i is already
> incremented it is incorrect. This patch fixes it so that index
> is used for the offset too.
> 
> Signed-off-by: Paul Thomas <pthomas8589@gmail.com>
> ---
>  There are many different ways to correct this, I'd just like it to get
>  fixed. I've tested this with a 5.2 kernel, but this patch is against
>  5.5rc7.
> 
>  drivers/gpio/gpio-xilinx.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c
> index a9748b5198e6..67f9f82e0db0 100644
> --- a/drivers/gpio/gpio-xilinx.c
> +++ b/drivers/gpio/gpio-xilinx.c
> @@ -147,9 +147,10 @@ static void xgpio_set_multiple(struct gpio_chip *gc, unsigned long *mask,
>  	for (i = 0; i < gc->ngpio; i++) {
>  		if (*mask == 0)
>  			break;
> +		/* Once finished with an index write it out to the register */
>  		if (index !=  xgpio_index(chip, i)) {
>  			xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET +
> -				       xgpio_regoffset(chip, i),
> +				       index * XGPIO_CHANNEL_OFFSET,
>  				       chip->gpio_state[index]);
>  			spin_unlock_irqrestore(&chip->gpio_lock[index], flags);
>  			index =  xgpio_index(chip, i);
> @@ -165,7 +166,7 @@ static void xgpio_set_multiple(struct gpio_chip *gc, unsigned long *mask,
>  	}
>  
>  	xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET +
> -		       xgpio_regoffset(chip, i), chip->gpio_state[index]);
> +		       index * XGPIO_CHANNEL_OFFSET, chip->gpio_state[index]);
>  
>  	spin_unlock_irqrestore(&chip->gpio_lock[index], flags);
>  }
> 

Shubhrajyoti: Please take a look.

Thanks,
Michal


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] GPIO, Fix bug where the wrong GPIO register is written to
  2020-01-25 22:14 [PATCH] GPIO, Fix bug where the wrong GPIO register is written to Paul Thomas
  2020-01-26 21:31 ` Andrew Lunn
  2020-01-27  7:42 ` Michal Simek
@ 2020-02-10 11:52 ` Linus Walleij
  2020-02-18  7:28   ` Paul Thomas
  2 siblings, 1 reply; 5+ messages in thread
From: Linus Walleij @ 2020-02-10 11:52 UTC (permalink / raw)
  To: Paul Thomas
  Cc: Bartosz Golaszewski, Michal Simek, open list:GPIO SUBSYSTEM,
	Linux ARM, linux-kernel

On Sat, Jan 25, 2020 at 11:14 PM Paul Thomas <pthomas8589@gmail.com> wrote:

> Care is taken with "index", however with the current version
> the actual xgpio_writereg is using index for data but
> xgpio_regoffset(chip, i) for the offset. And since i is already
> incremented it is incorrect. This patch fixes it so that index
> is used for the offset too.
>
> Signed-off-by: Paul Thomas <pthomas8589@gmail.com>
> ---
>  There are many different ways to correct this, I'd just like it to get
>  fixed. I've tested this with a 5.2 kernel, but this patch is against
>  5.5rc7.

Fixed up the subject and applied, added a tag for stable.

Thanks!
Linus Walleij

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] GPIO, Fix bug where the wrong GPIO register is written to
  2020-02-10 11:52 ` Linus Walleij
@ 2020-02-18  7:28   ` Paul Thomas
  0 siblings, 0 replies; 5+ messages in thread
From: Paul Thomas @ 2020-02-18  7:28 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Bartosz Golaszewski, Michal Simek, open list:GPIO SUBSYSTEM,
	Linux ARM, linux-kernel

> Fixed up the subject and applied, added a tag for stable.
>
> Thanks!
> Linus Walleij

Thanks everyone, next time I'll do the subject better.

-Paul

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-02-18  7:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-25 22:14 [PATCH] GPIO, Fix bug where the wrong GPIO register is written to Paul Thomas
2020-01-26 21:31 ` Andrew Lunn
2020-01-27  7:42 ` Michal Simek
2020-02-10 11:52 ` Linus Walleij
2020-02-18  7:28   ` Paul Thomas

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).