From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.176 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796422953; b=aAxP5ophB2MteiqUVTp7JhW/V1xh/zFjj9LbqVSRlO614NjzBLagMg1vWxS6DcCtJaCV RjJeMLfQM8UP2BT5thRLRtY96UIMSqjBe0TFOypPMgszq5xTp3iwvVXsfm0ytv1F6tKuA aYnoWUcbNrcNNkHUM3vfvI2c6CNjE/yHQH4ypu4lFhjwJyzxQmO8ALzYfSSHI8hP5F1ZK WWrB/hRw1BPgHjTlUBtqDVblyywD3LJG+C3q94PEHPXBaHb+mzd+xqZ+tBP9HJQe+hJec I3WK3m5cHFtGIkB09PksWBq/0ZNyI1aDA6iDB82uUSd9K2kvBSz1GrREVNbwrGZgF5Q== 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=0K8B/3UzNe3ml0sBdoC5DyNO3y3/brm6NzOulrhmI0bTtNBxmtg/1Pq8khckm/Df71rN 3TyNLjwK2SmP5HKSd7mwwRbUtPpuli6/M3yRnDkn1bNAGOVUEIP7IU59kagZVOMb2vqSy X3Lm5rlMctdkZszZ2T75KqC3gb2xnG2kWvtDCqmMPTuN7n+tZkiSZtQfOF4/WmTKyJbee 7a9goasDSYVYjJiyGcT//Q+iEpWEpO2wy8QqR4cJ8GxGojUfzht/31bLnixRiHclchi33 Q3wTL6GrI2JQpmzfeaumEeOKU39cuLqNUvyLv+rkOKHFuXU2wDvkyk8QYoXFfrcbZow== 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.176 Received: from mail-dy1-f176.google.com (mail-dy1-f176.google.com [74.125.82.176]) (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 69571606A330 for ; Fri, 4 Dec 2026 22:22:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 69571606A330 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-dy1-f176.google.com with SMTP id 5a478bee46e88-386c71feeeaso1878256eec.0 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=rmm4jToUNZHvEmbNpT77G+1W7w1uoBJzZehSVn4DZOSUhel/UTImhYII8julwoEuYT Z+mVmTIyjrcu4Ddxt41fpmwIMRMTjrMYd5rB67v0bNsQ3tjJ+sVXvydGbKrTRqZGTw9L hFSOzGICdEQl3BiwRwZYlfSJZb17uElb7Wrn8sQO6kUpunYC48xKkWkz+8DzwTlgoXkb 3jHsTcGWINfCoFlKZ+ynbfOj8kxiVNjEq6/HzoFqYgOwSlow9Qy/LDK0IfPz58/OdYEY xI7DvWxmdNBcJ9jKT2+TW8IsSDGshlyFDdbKHcakNQIqf+xWO9gzOY0X/pSwrDuGptLf N8Fg== X-Forwarded-Encrypted: i=1; AL+hErGP1Digmgz/R/lvOXSYbANvJO3dd6MHVbtFEClD6GMTMGUgQLM9mu2uuGZoCbHt1Ox+rnXyehBOo1wcN/s=@vger.kernel.org X-Gm-Message-State: APuU4Z/WNLYeCRys83M3CpMMb4MQFJ/1enUgxUtws6PbvRYuTDiMvXqd uqVQoNnBnCrqrEE7kpSbbkfxMIltMhdbslisRCryD8FqSD5B5kO/bDA3 X-Gm-Gg: AZFdTZePwkWHf0sHGu4aHCR9Y/A6yo/41PDZDb9aSJogoGsP2r7DiTt5JuMbeRPzgff MOfl83yw7ZnXOZ6PFXBkannFvm9XBWlbElJ19GyKGpwgaerQ1t40i7hRzobY/xdgaPviAdHvoE2 fDs42xJaP+wscfiALdJUdBgD19Y+ZqfLHbemW/wQvB16nZMZfuH30UnBvaHTIFCUiSF0elmUElP qJTLWH+X+M3uBDZZuXwQ/ZL8eldhbQVbBMArVSg/GCWmceUn3+5DtARSFjC9LFH1aE/zSPR0Tf3 kJJedYbuRZ1uS5e6GE8EE9SkKv04xGFBqIk4Mid291U95wP1fNkAZIgVBYypHArm+RsLSDCZsZq v8/qSliAgmypRYOcjxaXD20bKHKmo7FqiPeAeJX82OHlV37WjzbopRhPGTlNQvLY4Tn7Q51dNyr D3ASEw692RvGip0t9MeB1d0cuRdC7popWm8ROST12VkmfEONijlJLjG04XL4WkVTwoHf4iJXJcb a7uX21UbtrGZ1XgYnrIwsOdmErc4p8GT72HHRLL6YOU5VyZp6FrBt1xQEb1SIetmAXW0EzORZYa pqKqE1F4U4NrTPiR1h2EPhxEsJYGVQfe2IbgTja3PiYMddXVXq6pxdJdyKyml0MKoAmg 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: linux-kernel@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