From: sashiko-bot@kernel.org
To: "Anatoliy Oleinikov" <admin@wizle.tech>
Cc: linux-gpio@vger.kernel.org
Subject: Re: [PATCH RESEND] i2c: i2c-gpio: Enhance driver for buses with shared SDA
Date: Wed, 02 Dec 2026 12:51:32 +0000 [thread overview]
Message-ID: <sashiko-outbox-245810@kernel.org> (raw)
In-Reply-To: <20261202-i2c-gpio-shared-sda-v1-1-8b411d498d14@wizle.tech>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] i2c: gpio: race in i2c_gpio_cleanup_line() unlocking before
gpiod_put()
--
commit dfec81ba8dfe460cb6648555affaacf28b81ef65
Author: Anatoliy Oleinikov <admin@wizle.tech>
i2c: i2c-gpio: Enhance driver for buses with shared SDA
This commit generalizes the shared SCL line tracking and locking in
i2c-gpio to also support sharing the SDA line across multiple I2C
adapters.
> diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
> index 56d6847cbf6d7..40d7d0178af86 100644
> --- a/drivers/i2c/busses/i2c-gpio.c
> +++ b/drivers/i2c/busses/i2c-gpio.c
[ ... ]
> @@ -455,66 +480,76 @@ static bool i2c_gpio_scl_matches(struct i2c_gpio_scl_data *a, struct i2c_gpio_sc
[ ... ]
> -static void i2c_gpio_cleanup_scl(struct i2c_gpio_scl_data *scl)
> +static void i2c_gpio_cleanup_line(struct i2c_gpio_line_data *line)
> {
> - if (!refcount_dec_and_mutex_lock(&scl->ref, &i2c_gpio_scl_list_lock))
> + if (!refcount_dec_and_mutex_lock(&line->ref, &i2c_gpio_line_list_lock))
> return;
>
> - list_del(&scl->list);
> - mutex_unlock(&i2c_gpio_scl_list_lock);
> - gpiod_put(scl->gpio);
> - i2c_gpio_free_scl(scl);
> + list_del(&line->list);
> + mutex_unlock(&i2c_gpio_line_list_lock);
> + gpiod_put(line->gpio);
> + i2c_gpio_free_line(line);
> }
[Severity: Medium]
Can a concurrent i2c_gpio_lookup_line() fail with -EBUSY if it runs
between mutex_unlock(&i2c_gpio_line_list_lock) and gpiod_put(line->gpio)?
With both SDA and SCL now going through i2c_gpio_lookup_line(), a probe
that succeeds on SDA and hits -EPROBE_DEFER on SCL unwinds via
err_cleanup_sda -> i2c_gpio_cleanup_line(priv->sda). If another adapter
sharing that SDA pin probes at the same time, the following interleaving
can occur:
CPU0 CPU1
i2c_gpio_probe() [adapter A] i2c_gpio_probe() [adapter B]
priv->sda = i2c_gpio_lookup_line()
priv->scl = i2c_gpio_lookup_line()
-> -EPROBE_DEFER
i2c_gpio_cleanup_line(priv->sda)
refcount_dec_and_mutex_lock()
list_del(&line->list)
mutex_unlock(&i2c_gpio_line_list_lock)
i2c_gpio_lookup_line("sda", ...)
lock(&i2c_gpio_line_list_lock)
// misses entry, adds new_line
unlock(&i2c_gpio_line_list_lock)
i2c_gpio_get_desc()
gpiod_get() -> -EBUSY
gpiod_put(line->gpio)
Because the GPIO descriptor still has FLAG_REQUESTED set until
gpiod_put() finishes, adapter B fails permanently with -EBUSY instead of
deferring probe. Calling gpiod_put(line->gpio) before removing the entry
and unlocking i2c_gpio_line_list_lock (or clearing line->gpio under the
lock before dropping it for gpiod_put()) would avoid this race.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202-i2c-gpio-shared-sda-v1-1-8b411d498d14@wizle.tech?part=1
prev parent reply other threads:[~2026-12-02 12:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 12:37 [PATCH RESEND] i2c: i2c-gpio: Enhance driver for buses with shared SDA Anatoliy Oleinikov via B4 Relay
2026-12-02 12:51 ` sashiko-bot [this message]
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-245810@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=admin@wizle.tech \
--cc=linux-gpio@vger.kernel.org \
--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