Linux GPIO subsystem development
 help / color / mirror / Atom feed
From: Alexander Stein <alexander.stein@systec-electronic.com>
To: mrpace2@gmail.com
Cc: linux-gpio@vger.kernel.org
Subject: Re: [PATCH] gpio: gpio-pca953x: no interrupts with 4-bit devices
Date: Wed, 09 Mar 2016 14:05:32 +0100	[thread overview]
Message-ID: <2550700.ucYhgAiWGF@ws-stein> (raw)
In-Reply-To: <emac54c752-04e5-4445-a05e-e6d24a098066@t410-5a>

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


  reply	other threads:[~2016-03-09 13:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-09 12:37 [PATCH] gpio: gpio-pca953x: no interrupts with 4-bit devices mrpace2
2016-03-09 13:05 ` Alexander Stein [this message]
2016-03-10 10:15   ` [PATCH v2] " mrpace2
2016-03-10 18:02     ` Grygorii Strashko

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=2550700.ucYhgAiWGF@ws-stein \
    --to=alexander.stein@systec-electronic.com \
    --cc=linux-gpio@vger.kernel.org \
    --cc=mrpace2@gmail.com \
    /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