From: "Luca Ceresoli" <luca.ceresoli@bootlin.com>
To: "zhangjiao2" <zhangjiao2@cmss.chinamobile.com>,
<andi.shyti@kernel.org>, <dumitru.ceclan@analog.com>,
<sakari.ailus@linux.intel.com>, <luca.ceresoli@bootlin.com>,
<andriy.shevchenko@linux.intel.com>, <gonglinkai@kylinos.cn>,
<rosenp@gmail.com>, <stable@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <trivial@kernel.org>
Cc: <romain.gantois@bootlin.com>,
"Cosmin Tanislav" <demonsingur@gmail.com>,
"Tomi Valkeinen" <tomi.valkeinen@ideasonboard.com>
Subject: Re: [PATCH] i2c: atr: fix race condition caused by static local variable in i2c_atr_map_msgs()
Date: Thu, 29 Oct 2026 09:25:26 +0100 [thread overview]
Message-ID: <DMH6FVUD4K0S.R8UAMMH8TVZY@bootlin.com> (raw)
In-Reply-To: <20261029070818.639-1-zhangjiao2@cmss.chinamobile.com>
Hello,
+Cc Romain, Cosmin, Tomi
On Thu Oct 29, 2026 at 8:08 AM CET, zhangjiao2 wrote:
> From: zhang jiao <zhangjiao2@cmss.chinamobile.com>
>
> The variable `c2a` in i2c_atr_map_msgs() is declared `static`, which means
> it is shared across all invocations of this function regardless of which
> ATR channel is being serviced. Since each channel has its own
> orig_addrs_lock and alias_pairs_lock mutexes, two threads can execute
> i2c_atr_map_msgs() concurrently on different channels, racing on the
> shared `c2a` pointer.
>
> This can cause:
> - The wrong alias to be used for address translation, sending I2C
> transactions to the wrong device.
> - The `fixed` flag of an unrelated mapping to be corrupted, breaking the
> alias replacement logic.
>
> Remove the `static` keyword so that `c2a` becomes a regular local
> variable, eliminating the shared state between concurrent calls.
>
> Signed-off-by: zhang jiao <zhangjiao2@cmss.chinamobile.com>
Was this potential bug observed on real hardware? I'm a bit surprised
nobody noticed before.
Also, if it's a bugfix, it should have a Fixes: tag and possibly Cc:
stable.
Code-wise it looks OK. Not sure a bug can really happen but I don't see any
reason this variable should be static: it is always set before being read
by this function.
Also please keep Romain, Cosmin and Tomi in Cc in future iterations, they
worked significantly on this code.
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
next prev parent reply other threads:[~2026-10-29 8:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-29 7:08 zhangjiao2
2026-10-29 8:25 ` Luca Ceresoli [this message]
2026-10-29 15:38 ` Tomi Valkeinen
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=DMH6FVUD4K0S.R8UAMMH8TVZY@bootlin.com \
--to=luca.ceresoli@bootlin.com \
--cc=andi.shyti@kernel.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=demonsingur@gmail.com \
--cc=dumitru.ceclan@analog.com \
--cc=gonglinkai@kylinos.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=romain.gantois@bootlin.com \
--cc=rosenp@gmail.com \
--cc=sakari.ailus@linux.intel.com \
--cc=stable@vger.kernel.org \
--cc=tomi.valkeinen@ideasonboard.com \
--cc=trivial@kernel.org \
--cc=zhangjiao2@cmss.chinamobile.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
all inboxes | Powered by JetHome®