Skip to contentSkip to conversation

GPIO, Fix bug where the wrong GPIO register is written to

PATCH In review Paul Thomas 4 participants 5 messages Jan 25, 2020 – Feb 18, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 GPIO, Fix bug where the wrong GPIO register is written to

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.

---
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(-)
drivers/gpio/gpio-xilinx.c +3 -2
index a9748b5198e6..67f9f82e0db0 100644
@@ -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);
 }
Signature · 1 line
2.17.1
#1 lore raw
Quoted 7 lines · 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.

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

#2 lore raw
In reply to Paul Thomas
Quoted 33 lines · 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.

---
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(-)
drivers/gpio/gpio-xilinx.c +2 -1
index a9748b5198e6..67f9f82e0db0 100644
@@ -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);

drivers/gpio/gpio-xilinx.c static void xgpio_set_multiple(struct gpio_chip *gc, unsigned long *mask, · line 172

Quoted 8 lines
drivers/gpio/gpio-xilinx.c +1 -1
@@ -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

#3 lore raw
In reply to Paul Thomas
Quoted 11 lines · 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.

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

#4 lore raw
Quoted 4 lines

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