Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH] misc: bh1770glc: Hold chip->mutex while reconfiguring the chip on resume
@ 2026-12-04 18:51 Praneeth Balasubramanian
  2026-12-04 20:51 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 2+ messages in thread
From: Praneeth Balasubramanian @ 2026-12-04 18:51 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.

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-04 21:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 18:51 [PATCH] misc: bh1770glc: Hold chip->mutex while reconfiguring the chip on resume Praneeth Balasubramanian
2026-12-04 20:51 ` Greg Kroah-Hartman

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