From: sashiko-bot@kernel.org
To: "Sahaj Chaudhari" <sahaj123.sc@gmail.com>
Cc: linux-gpio@vger.kernel.org
Subject: Re: [PATCH] gpio: pca953x: Handle direction register read errors in IRQ paths
Date: Sun, 18 Oct 2026 16:55:33 +0000 [thread overview]
Message-ID: <sashiko-outbox-176299@kernel.org> (raw)
In-Reply-To: <20261018165003.3372368-1-sahaj123.sc@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] gpio: pca953x: mixing guard() and goto in pca953x_irq_bus_sync_unlock()
--
commit f8c41495cf791bc6655e128fd9192a150f30aa3c
Author: Sahaj Chaudhari <sahaj123.sc@gmail.com>
gpio: pca953x: Handle direction register read errors in IRQ paths
This commit adds error checking for direction register reads in
pca953x_irq_bus_sync_unlock(), pca953x_irq_pending(), and
pca953x_irq_setup() to avoid using uninitialized stack bitmaps when
pca953x_read_regs() fails.
> diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
> index aac9ea7520b60..b6f0849d3bdf9 100644
> --- a/drivers/gpio/gpio-pca953x.c
> +++ b/drivers/gpio/gpio-pca953x.c
> @@ -862,6 +862,7 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d)
> DECLARE_BITMAP(irq_mask, MAX_LINE);
> DECLARE_BITMAP(reg_direction, MAX_LINE);
> int level;
> + int ret;
>
> guard(mutex)(&chip->i2c_lock);
>
> @@ -880,7 +881,9 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d)
> }
>
> /* Switch direction to input if needed */
> - pca953x_read_regs(chip, chip->regs->direction, reg_direction);
> + ret = pca953x_read_regs(chip, chip->regs->direction, reg_direction);
> + if (ret)
> + goto out;
>
> bitmap_or(irq_mask, chip->irq_trig_fall, chip->irq_trig_raise, gc->ngpio);
> bitmap_or(irq_mask, irq_mask, chip->irq_trig_level_high, gc->ngpio);
> @@ -890,6 +893,7 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d)
> for_each_andnot_bit(level, irq_mask, reg_direction, gc->ngpio)
> pca953x_gpio_direction_input_unlocked(&chip->gpio_chip, level);
>
> +out:
> mutex_unlock(&chip->irq_lock);
> }
[Severity: Low]
In drivers/gpio/gpio-pca953x.c, pca953x_irq_bus_sync_unlock() uses
guard(mutex)(&chip->i2c_lock) at function scope. When pca953x_read_regs()
returns an error, this change jumps to the new out label to unlock
chip->irq_lock.
Per include/linux/cleanup.h:
* Lastly, given that the benefit of cleanup helpers is removal of
* "goto", and that the "goto" statement can jump between scopes, the
* expectation is that usage of "goto" and cleanup helpers is never
* mixed in the same function. I.e. for a given routine, convert all
* resources that need a "goto" cleanup to scope-based cleanup, or
* convert none of them.
Could pca953x_irq_bus_sync_unlock() avoid mixing guard() and goto by wrapping
the direction update in an if (!ret) block (or using scoped_guard(mutex,
&chip->i2c_lock) around the I2C accesses before unlocking chip->irq_lock)?
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261018165003.3372368-1-sahaj123.sc@gmail.com?part=1
next prev parent reply other threads:[~2026-10-18 16:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-18 16:50 [PATCH] gpio: pca953x: Handle direction register read errors in IRQ paths Sahaj Chaudhari
2026-10-18 16:55 ` sashiko-bot [this message]
2026-10-20 13:28 ` Bartosz Golaszewski
2026-10-20 13:28 ` Bartosz Golaszewski
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=sashiko-outbox-176299@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=sahaj123.sc@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
/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