From: Praneeth Balasubramanian <praneethb2002@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Arnd Bergmann <arnd@arndb.de>
Cc: Jiale Yao <yaojiale02@163.com>,
linux-kernel@vger.kernel.org,
Praneeth Balasubramanian <praneethb2002@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH v2] misc: bh1770glc: Hold chip->mutex while reconfiguring the chip on resume
Date: Fri, 4 Dec 2026 14:22:23 -0800 [thread overview]
Message-ID: <20261204222223.1868666-1-praneethb2002@gmail.com> (raw)
bh1770_resume() reprograms the ALS rate, the ALS thresholds and the
proximity mode with bh1770_lux_rate(), bh1770_lux_update_thresholds()
and bh1770_prox_mode_control(), and sets chip->lux_wait_result, all
without chip->mutex. The comments above these helpers say that the mutex
is held when they are called, and bh1770_power_state_store(), which runs
the same sequence, holds it.
The threaded interrupt handler takes chip->mutex and also updates the
thresholds and lux_wait_result, and device interrupts are enabled again
before ->resume() runs. Without the mutex the two can interleave and
leave the programmed thresholds or proximity mode out of step with
chip->lux_wait_result and chip->prox_force_update.
Hold chip->mutex for the rest of bh1770_resume() with guard(mutex), as
bh1770_power_state_store() holds it around the same sequence.
This is independent of the pending "misc: bh1770glc: queue proximity
work on freezable workqueue", which keeps the proximity work from
running across suspend but does not serialize resume with the interrupt
thread.
The missing lock was found by a static check that turns the locking rule
in a function's comment into a Clang context-analysis requirement on its
callers.
Fixes: 190420ab34ab ("drivers/misc: driver for bh1770glc / sfh7770 ALS and proximity sensor")
Cc: stable@vger.kernel.org
Signed-off-by: Praneeth Balasubramanian <praneethb2002@gmail.com>
---
Notes:
Changes in v2:
- Use guard(mutex) instead of mutex_lock()/mutex_unlock()
(Greg Kroah-Hartman).
This was found by a compiler-based check, part of research at UCSB SecLab.
The locking rule stated in the kernel-doc comment of the called function
was turned into a Clang context-analysis requirement (__must_hold) on that
function, and Clang 23 with CONFIG_WARN_CONTEXT_ANALYSIS then checked every
caller. An LLM was used only to turn the comment into a machine-readable
rule; the report itself comes from the compiler. The patch and changelog
were drafted with Claude Opus 5.5. I reviewed the patch and take
responsibility for it.
Testing: builds without new warnings with W=1 (x86_64, clang 23,
allmodconfig). With __must_hold(&chip->mutex) on the three helpers and
context analysis enabled, the three calls in bh1770_resume() warn before
this patch and not after it. Not runtime-tested; I do not have this
hardware, and I have not observed the race myself.
drivers/misc/bh1770glc.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/misc/bh1770glc.c b/drivers/misc/bh1770glc.c
index 26bae1aec423..8da357a413d0 100644
--- a/drivers/misc/bh1770glc.c
+++ b/drivers/misc/bh1770glc.c
@@ -1319,6 +1319,7 @@ static int bh1770_resume(struct device *dev)
struct bh1770_chip *chip = i2c_get_clientdata(client);
int ret = 0;
+ guard(mutex)(&chip->mutex);
bh1770_chip_on(chip);
if (!pm_runtime_suspended(dev)) {
--
2.25.1
reply other threads:[~2026-12-04 22:22 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261204222223.1868666-1-praneethb2002@gmail.com \
--to=praneethb2002@gmail.com \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=yaojiale02@163.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.