Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH v2] misc: bh1770glc: Hold chip->mutex while reconfiguring the chip on resume
@ 2026-12-04 22:22 Praneeth Balasubramanian
  0 siblings, 0 replies; only message in thread
From: Praneeth Balasubramanian @ 2026-12-04 22:22 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Arnd Bergmann
  Cc: Jiale Yao, linux-kernel, Praneeth Balasubramanian, stable

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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-04 22:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 22:22 [PATCH v2] misc: bh1770glc: Hold chip->mutex while reconfiguring the chip on resume Praneeth Balasubramanian

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox