Skip to contentSkip to conversation

gpio: pca953x: Fix dereference of irq data in shutdown

PATCH In review Mark Walton 3 participants 5 messages Feb 28, 2019

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

PATCH v2 1/1 gpio: pca953x: Fix dereference of irq data in shutdown

If a PCA953x gpio was used as an interrupt and then released, the shutdown function was trying to extract the pca953x_chip pointer directly from the irq_data, but in reality was getting the gpio_chip structure.

The net effect was that the subsequent writes to the data structure corrupted data in the gpio_chip structure, which wasn't immediately obvious until attempting to use the GPIO again in the future, at which point the kernel panics.

This fix correctly extracts the pca953x_chip structure via the gpio_chip structure, as is correctly done in the other irq functions.

Fixes 0a70fe00efea ("gpio: pca953x: Clear irq trigger type on irq shutdown")
---
 drivers/gpio/gpio-pca953x.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpio/gpio-pca953x.c +2 -1
index caf7dd1..6bd55a4 100644
@@ -659,7 +659,8 @@ static int pca953x_irq_set_type(struct irq_data *d, unsigned int type)
 
 static void pca953x_irq_shutdown(struct irq_data *d)
 {
-	struct pca953x_chip *chip = irq_data_get_irq_chip_data(d);
+	struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
+	struct pca953x_chip *chip = gpiochip_get_data(gc);
 	u8 mask = 1 << (d->hwirq % BANK_SZ);
 
 	chip->irq_trig_raise[d->hwirq / BANK_SZ] &= ~mask;
Signature · 1 line
2.7.4
Reviewed-by on v2 1/1
#1 lore raw

czw., 28 lut 2019 o 15:27 Mark Walton <[email protected]> napisał(a):

Quoted 36 lines

If a PCA953x gpio was used as an interrupt and then released, the shutdown function was trying to extract the pca953x_chip pointer directly from the irq_data, but in reality was getting the gpio_chip structure.

The net effect was that the subsequent writes to the data structure corrupted data in the gpio_chip structure, which wasn't immediately obvious until attempting to use the GPIO again in the future, at which point the kernel panics.

This fix correctly extracts the pca953x_chip structure via the gpio_chip structure, as is correctly done in the other irq functions.

Fixes 0a70fe00efea ("gpio: pca953x: Clear irq trigger type on irq shutdown")
---
 drivers/gpio/gpio-pca953x.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpio/gpio-pca953x.c +2 -2
index caf7dd1..6bd55a4 100644
@@ -659,7 +659,8 @@ static int pca953x_irq_set_type(struct irq_data *d, unsigned int type)
 
 static void pca953x_irq_shutdown(struct irq_data *d)
 {
-       struct pca953x_chip *chip = irq_data_get_irq_chip_data(d);
+       struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
+       struct pca953x_chip *chip = gpiochip_get_data(gc);
        u8 mask = 1 << (d->hwirq % BANK_SZ);
 
        chip->irq_trig_raise[d->hwirq / BANK_SZ] &= ~mask;
--
Quoted 2 lines

2.7.4

maintainer
#2 lore raw
In reply to Mark Walton
Quoted 14 lines · Mark Walton

If a PCA953x gpio was used as an interrupt and then released, the shutdown function was trying to extract the pca953x_chip pointer directly from the irq_data, but in reality was getting the gpio_chip structure.

The net effect was that the subsequent writes to the data structure corrupted data in the gpio_chip structure, which wasn't immediately obvious until attempting to use the GPIO again in the future, at which point the kernel panics.

This fix correctly extracts the pca953x_chip structure via the gpio_chip structure, as is correctly done in the other irq functions.

Quoted 5 lines
Fixes 0a70fe00efea ("gpio: pca953x: Clear irq trigger type on irq shutdown")
---
 drivers/gpio/gpio-pca953x.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

<formletter>

This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.

</formletter>

#3 lore raw
Quoted 33 lines

-----Original Message-----
From: Greg KH <[email protected]>
Sent: 28 February 2019 15:16
To: Mark Walton <[email protected]>
Cc: Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Marek Vasut <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH v2] gpio: pca953x: Fix dereference of irq data in shutdown

Quoted 13 lines · Mark Walton

If a PCA953x gpio was used as an interrupt and then released, the shutdown function was trying to extract the pca953x_chip pointer directly from the irq_data, but in reality was getting the gpio_chip structure.

The net effect was that the subsequent writes to the data structure corrupted data in the gpio_chip structure, which wasn't immediately obvious until attempting to use the GPIO again in the future, at which point the kernel panics.

This fix correctly extracts the pca953x_chip structure via the gpio_chip structure, as is correctly done in the other irq functions.

Quoted 6 lines
Fixes 0a70fe00efea ("gpio: pca953x: Clear irq trigger type on irq

shutdown")

---
 drivers/gpio/gpio-pca953x.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 8 lines

<formletter>

This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.

</formletter>

Hi Greg,

Apologies, I'm pretty new to submitting patches to the kernel.

Is it just a case of needing to move the CC: [email protected] line to the sign-off area?

As far as I can tell it meets all of the other requirements (with the exception of not being in the upstream).

Thanks,

Mark

maintainer
#4 lore raw
Quoted 40 lines · Mark Walton
Quoted 40 lines

-----Original Message-----
From: Greg KH <[email protected]>
Sent: 28 February 2019 15:16
To: Mark Walton <[email protected]>
Cc: Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Marek Vasut <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH v2] gpio: pca953x: Fix dereference of irq data in shutdown

Quoted 13 lines · Mark Walton

If a PCA953x gpio was used as an interrupt and then released, the shutdown function was trying to extract the pca953x_chip pointer directly from the irq_data, but in reality was getting the gpio_chip structure.

The net effect was that the subsequent writes to the data structure corrupted data in the gpio_chip structure, which wasn't immediately obvious until attempting to use the GPIO again in the future, at which point the kernel panics.

This fix correctly extracts the pca953x_chip structure via the gpio_chip structure, as is correctly done in the other irq functions.

Quoted 6 lines
Fixes 0a70fe00efea ("gpio: pca953x: Clear irq trigger type on irq

shutdown")

---
 drivers/gpio/gpio-pca953x.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

<formletter>

This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.

Quoted 8 lines
Quoted 1 line

</formletter>

Hi Greg,

Apologies, I'm pretty new to submitting patches to the kernel.

Is it just a case of needing to move the CC: [email protected] line to the sign-off area?

Yes, that's what the documentation says to do, correct?

thanks,

greg k-h