From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796422953; b=DdYmiV1oI4ZyvPtn6zSJoSE18HgVext1ZPGM+27SzteB9y0vEKzUuHzHTK26cWdtw8hl DOq/m5ZV7a/TycQwIt2LP1sKXHJAcOqxDTRuwFhFFFbbNLL2FH1CNIWlFzxB9Jj/S+UYH hB0yWraZ5kvcZV2n09D4iHfPHMSfNwoZG0zwei2QuMhAzPMVrmDP97VNnnlLSeE6fKnsP zJe+29QE99je7DhzF7/I1lin+uLL2ZXLgp5ybLrJhNSfw6RvFj3K7kmJKPLOl6fFNJsTP NP/JZRpVRTMEd1ui1k9eYU2THNws0ZrFoDTO6EQIQtFmGZmGVIfopgR9I4vLi+DQTgQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796422953; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=mHnb8e0zz37Cci3Npxg329BGvnOOEGPMACqobfpMKpQ=; b=Nl36gXoiq21sxYq7xzrCCz10g7bP+4GQsXzuPQduV1yzYuAzToDPQmrCxXCp0R8VJbAI P8izEBhFV1vlR7Q1ZsT4qMEyprg70Nb1O4ZF0vJM8eno6Frd1X64ao5O4Q2P3uGAfl7EO dLmEzAHhslMIQbgllnyy+8Vyz2YOLYlFYDSH246JXcrbVL3amkrm0xVDcsQvsGoTyLZXU VaNMpTxVyteApe2P9GWBBBGAwQvLcFNTnUSdqPE+yhkQ+a/B+JFKToFUv1EPOvApPFlgm iSCmN6w+FL+jIGfEUPhrQ8SYGfE4tzztJwDuABEfmVWewhq/+w127g+37aRNJX6INrQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=QoNHIKLX; arc=none smtp.remote-ip=74.125.82.43 Received: from mail-dl1-f43.google.com (mail-dl1-f43.google.com [74.125.82.43]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A781606A32D for ; Fri, 4 Dec 2026 22:22:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5A781606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=QoNHIKLX Received: by mail-dl1-f43.google.com with SMTP id a92af1059eb24-1b5d5f9938cso1588797c88.1 for ; Fri, 04 Dec 2026 14:22:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796422952; x=1797027752; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=mHnb8e0zz37Cci3Npxg329BGvnOOEGPMACqobfpMKpQ=; b=QoNHIKLXS8y/55XS7fDjRi4HeJWIiRjclMQGXtkCWKpSZ5eSY1LZBzPdWjx+L10pfY R3JS1wyMG80TblwWrDTSoeyLndHjxvCcl4m1hDnvZScJV46pBwhyc0xBt0OHbzn26j6g wL3dB8/9FbLBSY+Fl+cYQrpFRzpDHnE9ao+SaO/9Gk4Z4XpDfEurdA/SVxiu/IWD2/i7 Iv5T9WizREHV9ec44IQgrcyBCEx60+AyL78P1Lly1POf3iN2VrpsSHtTawFRUG/XBu0F 3Cp0pbfU+f8XbLFzfixppo/6mVnl0fqeiTV8nc+6ofRt+Qf2ocZi8J+m9iC/UumDTicO rY+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796422952; x=1797027752; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=mHnb8e0zz37Cci3Npxg329BGvnOOEGPMACqobfpMKpQ=; b=M40d8LjK0Ak36zAIx5+LadDp7RoRP1vx/q721+/q6E2cgMqM9ARALGmXCMox6DYEOr KSIamZkVVifXv30cKsuHqE2OtOgkDO5rEOCVfNo42f/j3EMwMGY6PiRaEnDOqAbo/fXs Z8EneeLS/Xw+p8CgP5hUS50Ztn8Q3Y74IRoUsBTlZ5/qwyWKdMuHzAJJTdPu1IRgI4Xj lqQbt8OD36QnOhejSYOSqgKs6ut6njpUkKuJTOM4U7FrcTPCXCUk3qpEwRIfP4fE8UBG 32IckP8Bu5A97Dnzh02uUOM3vDt8NGysKcKuOfMaUyZZ4J8XZq6OJR8MB7RgGEPJYgUI 0eXA== X-Forwarded-Encrypted: i=1; AL+hErGwkeBw04D04f58j+RzQhIRJmpT4GPLaeNokP7qhfloN2331CPaxdNZ2DJY5U8fNPHoV1OCbZQ=@vger.kernel.org X-Gm-Message-State: APuU4Z/sry05EDnbNcrBbHEo70pitsS7+P1jHD4izHoWkQvrflLIPeCc EvNUT5NKpin+3IagkNPMltXtOW8XdaaA05+dJ8ICo+WwMytU/HsmBAEJvPjJbxZq X-Gm-Gg: AZFdTZd0NaYyCNVkKZ/sY7cAHjLVOVHZXGKQ+crKi8MJSH5eagWF+UToGJieDYdQrdK oSVOLF3d9ZiNIvzY6jOIshk18OZv4apcL3kBF3R1RoEEDnczeodql7ePvi9HvuojEIfpJfByPr3 CNEGv6m1RIwewXLi90ZYztHJLLvRQU12eBCkeSM88WjH4lLJnmntT3THvfJm2Y18FIFvZpwcTGl DG0lMh+bv0kEbANpcpSmzfEBUwumXd0wDdEnS4tq1liYJglSOhOwN9xtj8ynm3stNxb0gs04M9q nE4LMc4tynxmXhSt8wNJci+bajq9nD+CHA+sdubBGM/BoWe27b2rVAq1u2XRZjvhM05GmYwLj85 dtIwv0ik35ZXy0tuP1Yt1k+jWPWqX+96MzRFfEmmUQlXfAxlMf4GDi7/bVPiYnHoCKmdthnunhQ mUNTHG18IW1Imh+FtSTgI4VT5vRjMGFLHpguj8y/bopaQe03uahLSs/dkLQKrTTuGNitk2thZk7 gODLN+m2oiZm86afTFLd/HU5mE+jcg2uI4WHEBYTblnS70xA2N3vgRviBkrkoBX2fi7ibu7+8u+ GU+J8JCICRhMcwsIomC5gOsZP5sHQX4I0ZSyB3OhHcXdSIfSyU3h1mIPE9BCqTyc5w1A X-Received: by 2002:a05:693c:69d3:b0:387:cb1:2214 with SMTP id 5a478bee46e88-387521ade38mr2918840eec.22.1796422952171; Fri, 04 Dec 2026 14:22:32 -0800 (PST) Received: from localhost.localdomain (wood.seclab.cs.ucsb.edu. [128.111.49.37]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-387521e5626sm10068596eec.17.2026.12.04.14.22.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 14:22:31 -0800 (PST) From: Praneeth Balasubramanian To: Greg Kroah-Hartman , Arnd Bergmann Cc: Jiale Yao , linux-kernel@vger.kernel.org, Praneeth Balasubramanian , 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 Message-Id: <20261204222223.1868666-1-praneethb2002@gmail.com> X-Mailer: git-send-email 2.25.1 X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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