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] misc: bh1770glc: Hold chip->mutex while reconfiguring the chip on resume
Date: Fri, 4 Dec 2026 10:51:03 -0800 [thread overview]
Message-ID: <20261204185103.1687865-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.
Take chip->mutex around the resume sequence, as
bh1770_power_state_store() does.
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:
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). Not runtime-tested; I do not have this hardware, and I
have not observed the race myself.
drivers/misc/bh1770glc.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/misc/bh1770glc.c b/drivers/misc/bh1770glc.c
index 26bae1aec423..1d5197f54aa6 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;
+ mutex_lock(&chip->mutex);
bh1770_chip_on(chip);
if (!pm_runtime_suspended(dev)) {
@@ -1336,6 +1337,7 @@ static int bh1770_resume(struct device *dev)
chip->lux_wait_result = true;
bh1770_prox_mode_control(chip);
}
+ mutex_unlock(&chip->mutex);
return ret;
}
#endif
--
2.25.1
next reply other threads:[~2026-12-04 18:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 18:51 Praneeth Balasubramanian [this message]
2026-12-04 20:51 ` [PATCH] misc: bh1770glc: Hold chip->mutex while reconfiguring the chip on resume Greg Kroah-Hartman
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=20261204185103.1687865-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox