gpio: gpio-pca953x: no interrupts with 4-bit devices
diff mbox

Message ID emac54c752-04e5-4445-a05e-e6d24a098066@t410-5a
State New
Headers show

Commit Message

mrpace2@gmail.com March 9, 2016, 12:37 p.m. UTC
I/O expanders with less than 8 I/O (PCA9536 and PCA9537, currently) fail 
to invoke interrupt handlers because the NBANK macro

     #define NBANK(chip) (chip->gpio_chip.ngpio / BANK_SZ)
incorrectly calculates no banks for these devices. As a result, 
pca953x_irq_pending() never sets the trigger_seen flag.

The patch below fixed the issue by changing the NBANK() macro.

Signed-off-by: Frank Edelhaeuser <mrpace2 <at> gmail.com>
---

--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Alexander Stein March 9, 2016, 1:05 p.m. UTC | #1
On Wednesday 09 March 2016 12:37:09, mrpace2@gmail.com wrote:
> I/O expanders with less than 8 I/O (PCA9536 and PCA9537, currently) fail 
> to invoke interrupt handlers because the NBANK macro
> 
>      #define NBANK(chip) (chip->gpio_chip.ngpio / BANK_SZ)
> incorrectly calculates no banks for these devices. As a result, 
> pca953x_irq_pending() never sets the trigger_seen flag.
> 
> The patch below fixed the issue by changing the NBANK() macro.
> 
> Signed-off-by: Frank Edelhaeuser <mrpace2 <at> gmail.com>
> ---
> diff -Nur a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
> --- a/drivers/gpio/gpio-pca953x.c 2016-03-08 00:00:00.000000000 +0000
> +++ b/drivers/gpio/gpio-pca953x.c 2016-03-08 00:00:00.000000000 +0000
> @@ -86,7 +86,7 @@
>   #define MAX_BANK 5
>   #define BANK_SZ 8
> 
> -#define NBANK(chip) (chip->gpio_chip.ngpio / BANK_SZ)
> +#define NBANK(chip) (((chip->gpio_chip.ngpio - 1) / BANK_SZ) + 1)

If ngpio is 0 (e.g. wrong platform device) this underflows and gets a completly wrong result. But I see more of those "ngpio - 1" all over the place.
What about?
> #define NBANK(chip) (((chip->gpio_chip.ngpio + (BANK_SZ - 1)) / BANK_SZ))

Best regards,
Alexander

--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff -Nur a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
--- a/drivers/gpio/gpio-pca953x.c 2016-03-08 00:00:00.000000000 +0000
+++ b/drivers/gpio/gpio-pca953x.c 2016-03-08 00:00:00.000000000 +0000
@@ -86,7 +86,7 @@ 
  #define MAX_BANK 5
  #define BANK_SZ 8

-#define NBANK(chip) (chip->gpio_chip.ngpio / BANK_SZ)
+#define NBANK(chip) (((chip->gpio_chip.ngpio - 1) / BANK_SZ) + 1)

  struct pca953x_chip {
   unsigned gpio_start;