iio: enable context analysis for all drivers
Subsystems (11)
v4 cover iio: enable context analysis for all drivers
Jonathan asked for the qcom-spmi-adc5-gen3 fix to become the first patch of a series that enables context analysis across IIO [1]. This is that series.
With CONTEXT_ANALYSIS := y in every drivers/iio Makefile, testing gives 256 warnings and 2 errors in 126 files (x86_64 allmodconfig, clang 23.1).
Patch 1 fixes the two qcom errors, as v3 did, but names the lock the way Bart suggested [2]. Patch 2 annotates the two conditional mode claims in iio.h, which accounts for 241 of the warnings, in 120 files. Patch 3 covers the core helpers behind them. Patches 4 to 8 annotate lock helpers in kx022a, meson_saradc, the DMA buffer, opt3001 and veml6031x00. None of them is a locking bug. Patch 9 enables the analysis. The common and sensorhubs Makefiles only list subdirectories and are left alone.
With the series applied all 726 files build without warnings, also with W=1. bma180, ab8500-gpadc and intel_dc_ti_adc are not in allmodconfig and were built on their own. gcc W=1 builds show no warnings. Removing an unlock or a release is still reported, tried in kx022a, ms5611 and veml6031x00.
Bart's thread-safety branch [3] has most of the same annotations. For meson_saradc and the DMA buffer he uses __context_unsafe(). Here they name the lock, so the helpers are checked, and for meson_saradc the callers too.
Written with help from an LLM coding assistant.
v4: was a single qcom patch, now the first of nine
v3: https://lore.kernel.org/linux-iio/[email protected]/
[1] https://lore.kernel.org/linux-iio/20261025215954.73549810@jic23-hlaptop/
[2] https://lore.kernel.org/linux-iio/[email protected]/
[3] https://github.com/bvanassche/linux/tree/thread-safety
Rupesh Majhi (9):
iio: adc: qcom-spmi-adc5-gen3: fix lock annotations on mutex helpers
iio: core: annotate the conditional mode claims
iio: core: mark the mode lock helpers __context_unsafe
iio: accel: kionix-kx022a: annotate the lock helpers
iio: adc: meson_saradc: annotate the lock helpers
iio: buffer-dma: annotate the queue lock helpers
iio: light: opt3001: mark the interrupt handler __context_unsafe
iio: light: veml6031x00: annotate the event enable helpers
iio: enable context analysis for all drivers
drivers/iio/Makefile | 2 ++ drivers/iio/accel/Makefile | 2 ++ drivers/iio/accel/kionix-kx022a.c | 2 ++ drivers/iio/adc/Makefile | 2 ++ drivers/iio/adc/meson_saradc.c | 2 ++ drivers/iio/adc/qcom-spmi-adc5-gen3.c | 4 ++-- drivers/iio/addac/Makefile | 2 ++ drivers/iio/afe/Makefile | 2 ++ drivers/iio/amplifiers/Makefile | 2 ++ drivers/iio/buffer/Makefile | 2 ++ drivers/iio/buffer/industrialio-buffer-dma.c | 2 ++ drivers/iio/cdc/Makefile | 2 ++ drivers/iio/chemical/Makefile | 2 ++ drivers/iio/common/cros_ec_sensors/Makefile | 2 ++ drivers/iio/common/hid-sensors/Makefile | 2 ++ drivers/iio/common/inv_sensors/Makefile | 2 ++ drivers/iio/common/ms_sensors/Makefile | 2 ++ drivers/iio/common/scmi_sensors/Makefile | 3 +++ drivers/iio/common/ssp_sensors/Makefile | 2 ++ drivers/iio/common/st_sensors/Makefile | 2 ++ drivers/iio/dac/Makefile | 2 ++ drivers/iio/dummy/Makefile | 2 ++ drivers/iio/filter/Makefile | 2 ++ drivers/iio/flow/Makefile | 2 ++ drivers/iio/frequency/Makefile | 2 ++ drivers/iio/gyro/Makefile | 2 ++ drivers/iio/health/Makefile | 2 ++ drivers/iio/humidity/Makefile | 2 ++ drivers/iio/imu/Makefile | 2 ++ drivers/iio/imu/bmi160/Makefile | 3 +++ drivers/iio/imu/bmi270/Makefile | 3 +++ drivers/iio/imu/bmi323/Makefile | 3 +++ drivers/iio/imu/bno055/Makefile | 2 ++ drivers/iio/imu/inv_icm42600/Makefile | 2 ++ drivers/iio/imu/inv_icm42607/Makefile | 2 ++ drivers/iio/imu/inv_icm45600/Makefile | 2 ++ drivers/iio/imu/inv_mpu6050/Makefile | 2 ++ drivers/iio/imu/smi330/Makefile | 3 +++ drivers/iio/imu/st_lsm6dsx/Makefile | 3 +++ drivers/iio/imu/st_lsm9ds0/Makefile | 3 +++ drivers/iio/industrialio-core.c | 2 ++ drivers/iio/light/Makefile | 2 ++ drivers/iio/light/opt3001.c | 1 + drivers/iio/light/veml6031x00.c | 2 ++ drivers/iio/magnetometer/Makefile | 2 ++ drivers/iio/multiplexer/Makefile | 2 ++ drivers/iio/orientation/Makefile | 2 ++ drivers/iio/position/Makefile | 2 ++ drivers/iio/potentiometer/Makefile | 2 ++ drivers/iio/potentiostat/Makefile | 2 ++ drivers/iio/pressure/Makefile | 2 +- drivers/iio/proximity/Makefile | 2 ++ drivers/iio/resolver/Makefile | 2 ++ drivers/iio/sensorhubs/osf/Makefile | 2 ++ drivers/iio/temperature/Makefile | 2 ++ drivers/iio/test/Makefile | 2 ++ drivers/iio/trigger/Makefile | 2 ++ include/linux/iio/iio.h | 9 ++------- 58 files changed, 121 insertions(+), 10 deletions(-)
base-commit: 7d80b4b383bc53b48abd3a30ca4a91cdab568bfa
Signature · 1 line
2.43.0
PATCH v4 1/9 iio: adc: qcom-spmi-adc5-gen3: fix lock annotations on mutex helpers
Since commit 5b63d0ae94cc ("compiler-context-analysis: Remove Sparse support"), __acquires() and __releases() only feed context analysis. Their argument is parsed before the function body, where only dev is in scope, so with analysis enabled for this file the build fails:
error: use of undeclared identifier 'adc'
Name the lock through dev, the same way the bodies find it. The analysis then also checks that the helpers really take and drop it.
---
Cc: Marco Elver <[email protected]>
Cc: Bart Van Assche <[email protected]>
Cc: Jishnu Prakash <[email protected]>
v4: name the lock through dev instead of __context_unsafe() (Bart),
now the first patch of the series that enables the analysis (Jonathan)
v3: drop Fixes tag (Jonathan), trailer cleanup (Andy)
https://lore.kernel.org/linux-iio/[email protected]/ v2: __context_unsafe() explained in commit message (Andy) https://lore.kernel.org/linux-iio/[email protected]/
v1: https://lore.kernel.org/linux-iio/[email protected]/
drivers/iio/adc/qcom-spmi-adc5-gen3.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/qcom-spmi-adc5-gen3.c +2 -2
@@ -663,7 +663,7 @@ static int adc5_gen3_add_aux_tm_device(struct adc5_chip *adc) }void adc5_gen3_mutex_lock (struct device *dev) - __acquires(&adc->lock) + __acquires(&((struct adc5_chip *)iio_priv(dev_get_drvdata(dev->parent)))->lock) {struct iio_dev *indio_dev =dev_get_drvdata (dev->parent);struct adc5_chip *adc =iio_priv (indio_dev);
@@ -673,7 +673,7 @@ void adc5_gen3_mutex_lock(struct device *dev)EXPORT_SYMBOL_NS_GPL (adc5_gen3_mutex_lock,"QCOM_SPMI_ADC5_GEN3" );void adc5_gen3_mutex_unlock (struct device *dev) - __releases(&adc->lock) + __releases(&((struct adc5_chip *)iio_priv(dev_get_drvdata(dev->parent)))->lock) {struct iio_dev *indio_dev =dev_get_drvdata (dev->parent);struct adc5_chip *adc =iio_priv (indio_dev);
Signature · 1 line
2.43.0
PATCH v4 2/9 iio: core: annotate the conditional mode claims
In reply to Rupesh Majhiiio_device_claim_direct() and iio_device_try_claim_buffer_mode() hold the mode lock only when they return true, but carry no annotation. With context analysis on, each caller that releases the claim is reported for releasing a lock it never took.
Mark both __cond_acquires(true, indio_dev), the token that __iio_dev_mode_lock() acquires. Sparse no longer reads these annotations, so drop the comment about it.
---
Cc: Marco Elver <[email protected]>
Cc: Bart Van Assche <[email protected]>
include/linux/iio/iio.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
include/linux/iio/iio.h +2 -7
@@ -707,13 +707,6 @@ int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp); void __iio_dev_mode_lock(struct iio_dev *indio_dev) __acquires(indio_dev); void __iio_dev_mode_unlock(struct iio_dev *indio_dev) __releases(indio_dev); -/* -* Helper functions that allow claim and release of direct mode -* in a fashion that doesn't generate many false positives from sparse. -* Note this must remain static inline in the header so that sparse -* can see the __acquires() and __releases() annotations. -*/ -/** * iio_device_claim_direct() - Keep device in direct mode * @indio_dev: the iio_dev associated with the device
@@ -726,6 +719,7 @@ void __iio_dev_mode_unlock(struct iio_dev *indio_dev) __releases(indio_dev);* Returns: true on success, false on failure. */ static inline bool iio_device_claim_direct (struct iio_dev *indio_dev) +__cond_acquires (true, indio_dev) {__iio_dev_mode_lock (indio_dev);
@@ -760,6 +754,7 @@ static inline bool iio_device_claim_direct(struct iio_dev *indio_dev)* Returns: true on success, false on failure. */ static inline bool iio_device_try_claim_buffer_mode (struct iio_dev *indio_dev) +__cond_acquires (true, indio_dev) {__iio_dev_mode_lock (indio_dev);
Signature · 1 line
2.43.0
Jonathan Cameron
maintainerRe: [PATCH v4 2/9] iio: core: annotate the conditional mode claims
Quoted 8 lines · On Tue, 27 Oct 2026 14:49:47 +0200 Rupesh Majhi <[email protected]> wrote:
iio_device_claim_direct()andiio_device_try_claim_buffer_mode()hold the mode lock only when they return true, but carry no annotation. With context analysis on, each caller that releases the claim is reported for releasing a lock it never took.Mark both
__cond_acquires(true, indio_dev), the token that__iio_dev_mode_lock()acquires. Sparse no longer reads these annotations, so drop the comment about it.
Hi Rupesh,
The history of the definitions of these being in the header at all was to make them visible enough to sparse that it could figure out the locking and 'mostly' give good coverage.
Given that's no longer necessary, maybe it makes sense to make the implementations private. It doesn't really help us that much as those nasty helpers are still needed for the rarely used guard that claims the current mode.
So maybe it's worth this maybe not... Anyhow, perhaps one for another day given I don't think it helps this effort.
drivers/iio/industrialio-core.c +27 -0
@@ -2269,6 +2269,33 @@ void __iio_dev_mode_unlock(struct iio_dev *indio_dev) }EXPORT_SYMBOL_GPL (__iio_dev_mode_unlock); +bool iio_device_claim_direct (struct iio_dev *indio_dev) +{ +__iio_dev_mode_lock (indio_dev); + +if (iio_buffer_enabled (indio_dev)) { +__iio_dev_mode_unlock (indio_dev); +return false; + } + +return true; +} +EXPORT_SYMBOL_GPL (iio_device_claim_direct); + +bool iio_device_try_claim_buffer_mode (struct iio_dev *indio_dev) +__cond_acquires (true, indio_dev) +{ +__iio_dev_mode_lock (indio_dev); + +if (!iio_buffer_enabled (indio_dev)) { +__iio_dev_mode_unlock (indio_dev); +return false; + } + +return true; +} +EXPORT_SYMBOL_GPL (iio_device_try_claim_buffer_mode); +/** * iio_device_get_current_mode() - helper function providing read-only access to * the opaque @currentmode variable
include/linux/iio/iio.h +3 -24
@@ -718,18 +718,7 @@ void __iio_dev_mode_unlock(struct iio_dev *indio_dev) __releases(indio_dev);* * Returns: true on success, false on failure. */ -static inline bool iio_device_claim_direct (struct iio_dev *indio_dev) -__cond_acquires (true, indio_dev) -{ -__iio_dev_mode_lock (indio_dev); - -if (iio_buffer_enabled (indio_dev)) { -__iio_dev_mode_unlock (indio_dev); -return false; - } - -return true; -} +bool iio_device_claim_direct(struct iio_dev *indio_dev) __cond_acquires(true, indio_dev);/** * iio_device_release_direct() - Releases claim on direct mode
@@ -753,18 +742,8 @@ static inline bool iio_device_claim_direct(struct iio_dev *indio_dev)* * Returns: true on success, false on failure. */ -static inline bool iio_device_try_claim_buffer_mode (struct iio_dev *indio_dev) -__cond_acquires (true, indio_dev) -{ -__iio_dev_mode_lock (indio_dev); - -if (!iio_buffer_enabled (indio_dev)) { -__iio_dev_mode_unlock (indio_dev); -return false; - } - -return true; -} +bool iio_device_try_claim_buffer_mode(struct iio_dev *indio_dev) + __cond_acquires(true, indio_dev);/** * iio_device_release_buffer_mode() - releases claim on buffer mode
Quoted 43 lines
Signed-off-by Rupesh Majhi <[email protected]>---
Cc: Marco Elver <[email protected]>
Cc: Bart Van Assche <[email protected]>include/linux/iio/iio.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)include/linux/iio/iio.h +2
-7@@ -707,13 +707,6 @@ int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp); void __iio_dev_mode_lock(struct iio_dev *indio_dev) __acquires(indio_dev); void __iio_dev_mode_unlock(struct iio_dev *indio_dev) __releases(indio_dev); -/* -* Helper functions that allow claim and release of direct mode -* in a fashion that doesn't generate many false positives from sparse. -* Note this must remain static inline in the header so that sparse -* can see the __acquires() and __releases() annotations. -*/ -/** * iio_device_claim_direct() - Keep device in direct mode * @indio_dev: the iio_dev associated with the device @@ -726,6 +719,7 @@ void __iio_dev_mode_unlock(struct iio_dev *indio_dev) __releases(indio_dev);* Returns: true on success, false on failure. */ static inline bool iio_device_claim_direct (struct iio_dev *indio_dev) +__cond_acquires (true, indio_dev) {__iio_dev_mode_lock (indio_dev);@@ -760,6 +754,7 @@ static inline bool iio_device_claim_direct(struct iio_dev *indio_dev)* Returns: true on success, false on failure. */ static inline bool iio_device_try_claim_buffer_mode (struct iio_dev *indio_dev) +__cond_acquires (true, indio_dev) {__iio_dev_mode_lock (indio_dev);
Jonathan Cameron
maintainerRe: [PATCH v4 2/9] iio: core: annotate the conditional mode claims
Quoted 39 lines · On Wed, 28 Oct 2026 03:18:34 +0000 Jonathan Cameron <[email protected]> wrote:
Quoted 8 lines · On Tue, 27 Oct 2026 14:49:47 +0200 Rupesh Majhi <[email protected]> wrote:
iio_device_claim_direct()andiio_device_try_claim_buffer_mode()hold the mode lock only when they return true, but carry no annotation. With context analysis on, each caller that releases the claim is reported for releasing a lock it never took.Mark both
__cond_acquires(true, indio_dev), the token that__iio_dev_mode_lock()acquires. Sparse no longer reads these annotations, so drop the comment about it.Hi Rupesh,
The history of the definitions of these being in the header at all was to make them visible enough to sparse that it could figure out the locking and 'mostly' give good coverage.
Given that's no longer necessary, maybe it makes sense to make the implementations private. It doesn't really help us that much as those nasty helpers are still needed for the rarely used guard that claims the current mode.
So maybe it's worth this maybe not... Anyhow, perhaps one for another day given I don't think it helps this effort.
drivers/iio/industrialio-core.c +5
-0@@ -2269,6 +2269,33 @@ void __iio_dev_mode_unlock(struct iio_dev *indio_dev) }EXPORT_SYMBOL_GPL (__iio_dev_mode_unlock); +bool iio_device_claim_direct(struct iio_dev *indio_dev +{ +__iio_dev_mode_lock (indio_dev); + +if (iio_buffer_enabled (indio_dev)) {
drivers/iio/industrialio-core.c void __iio_dev_mode_unlock(struct iio_dev *indio_dev) · line 2286
Quoted 10 lines
drivers/iio/industrialio-core.c +10
-0+__iio_dev_mode_unlock (indio_dev); +return false; + } + +return true; +} +EXPORT_SYMBOL_GPL (iio_device_claim_direct); + +bool iio_device_try_claim_buffer_mode(struct iio_dev *indio_dev) + __cond_acquires(true, indio_dev)
Dropping that marking. Turns out I even failed to build test this...
Quoted 107 lines
drivers/iio/industrialio-core.c +12
-0+{ +__iio_dev_mode_lock (indio_dev); + +if (!iio_buffer_enabled (indio_dev)) { +__iio_dev_mode_unlock (indio_dev); +return false; + } + +return true; +} +EXPORT_SYMBOL_GPL (iio_device_try_claim_buffer_mode); +/** * iio_device_get_current_mode() - helper function providing read-only access to * the opaque @currentmode variable include/linux/iio/iio.h +3
-24@@ -718,18 +718,7 @@ void __iio_dev_mode_unlock(struct iio_dev *indio_dev) __releases(indio_dev);* * Returns: true on success, false on failure. */ -static inline bool iio_device_claim_direct (struct iio_dev *indio_dev) -__cond_acquires (true, indio_dev) -{ -__iio_dev_mode_lock (indio_dev); - -if (iio_buffer_enabled (indio_dev)) { -__iio_dev_mode_unlock (indio_dev); -return false; - } - -return true; -} +bool iio_device_claim_direct(struct iio_dev *indio_dev) __cond_acquires(true, indio_dev);/** * iio_device_release_direct() - Releases claim on direct mode @@ -753,18 +742,8 @@ static inline bool iio_device_claim_direct(struct iio_dev *indio_dev)* * Returns: true on success, false on failure. */ -static inline bool iio_device_try_claim_buffer_mode (struct iio_dev *indio_dev) -__cond_acquires (true, indio_dev) -{ -__iio_dev_mode_lock (indio_dev); - -if (!iio_buffer_enabled (indio_dev)) { -__iio_dev_mode_unlock (indio_dev); -return false; - } - -return true; -} +bool iio_device_try_claim_buffer_mode(struct iio_dev *indio_dev) + __cond_acquires(true, indio_dev);/** * iio_device_release_buffer_mode() - releases claim on buffer mode Quoted 45 lines
Signed-off-by Rupesh Majhi <[email protected]>---
Cc: Marco Elver <[email protected]>
Cc: Bart Van Assche <[email protected]>include/linux/iio/iio.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)include/linux/iio/iio.h +2
-7@@ -707,13 +707,6 @@ int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp); void __iio_dev_mode_lock(struct iio_dev *indio_dev) __acquires(indio_dev); void __iio_dev_mode_unlock(struct iio_dev *indio_dev) __releases(indio_dev); -/* -* Helper functions that allow claim and release of direct mode -* in a fashion that doesn't generate many false positives from sparse. -* Note this must remain static inline in the header so that sparse -* can see the __acquires() and __releases() annotations. -*/ -/** * iio_device_claim_direct() - Keep device in direct mode * @indio_dev: the iio_dev associated with the device @@ -726,6 +719,7 @@ void __iio_dev_mode_unlock(struct iio_dev *indio_dev) __releases(indio_dev);* Returns: true on success, false on failure. */ static inline bool iio_device_claim_direct (struct iio_dev *indio_dev) +__cond_acquires (true, indio_dev) {__iio_dev_mode_lock (indio_dev);@@ -760,6 +754,7 @@ static inline bool iio_device_claim_direct(struct iio_dev *indio_dev)* Returns: true on success, false on failure. */ static inline bool iio_device_try_claim_buffer_mode (struct iio_dev *indio_dev) +__cond_acquires (true, indio_dev) {__iio_dev_mode_lock (indio_dev);
PATCH v4 3/9 iio: core: mark the mode lock helpers __context_unsafe
In reply to Rupesh Majhi__iio_dev_mode_lock() and __iio_dev_mode_unlock() are declared to take and release indio_dev, a token for the mode lock, because the mutex itself is private to the core. Their bodies take and release the mutex instead, which context analysis reports once it is on for the core. Mark both definitions __context_unsafe().
---
Cc: Marco Elver <[email protected]>
Cc: Bart Van Assche <[email protected]>
drivers/iio/industrialio-core.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/iio/industrialio-core.c +2 -0
@@ -2252,6 +2252,7 @@ EXPORT_SYMBOL_GPL(__devm_iio_device_register);* iio_device_try_claim_buffer_mode() pairs or related helpers instead. */ void __iio_dev_mode_lock (struct iio_dev *indio_dev) +__context_unsafe (/* returns with mlock held */ ) {mutex_lock (&to_iio_dev_opaque (indio_dev)->mlock); }
@@ -2262,6 +2263,7 @@ EXPORT_SYMBOL_GPL(__iio_dev_mode_lock);* @indio_dev: the iio_dev associated with the device */ void __iio_dev_mode_unlock (struct iio_dev *indio_dev) +__context_unsafe (/* releases mlock */ ) {mutex_unlock (&to_iio_dev_opaque (indio_dev)->mlock); }
Signature · 1 line
2.43.0
PATCH v4 4/9 iio: accel: kionix-kx022a: annotate the lock helpers
In reply to Rupesh Majhikx022a_turn_off_lock() returns with data->mutex held when it succeeds, and kx022a_turn_on_unlock() releases it. Annotate both so context analysis follows the lock into the callers.
---
Cc: Marco Elver <[email protected]>
Cc: Bart Van Assche <[email protected]>
drivers/iio/accel/kionix-kx022a.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/iio/accel/kionix-kx022a.c +2 -0
@@ -484,6 +484,7 @@ static int __kx022a_turn_on_off(struct kx022a_data *data, bool on) }static int kx022a_turn_off_lock (struct kx022a_data *data) + __cond_acquires(0, &data->mutex) {int ret;
@@ -496,6 +497,7 @@ static int kx022a_turn_off_lock(struct kx022a_data *data) }static int kx022a_turn_on_unlock (struct kx022a_data *data) + __releases(&data->mutex) {int ret;
Signature · 1 line
2.43.0
Re: [PATCH v4 4/9] iio: accel: kionix-kx022a: annotate the lock helpers
Quoted 5 lines · Rupesh Majhi
kx022a_turn_off_lock()returns withdata->mutexheld when it succeeds, andkx022a_turn_on_unlock()releases it. Annotate both so context analysis follows the lock into the callers.Signed-off-by Rupesh Majhi <[email protected]>
Thanks.
Signature · 5 lines
Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~
PATCH v4 5/9 iio: adc: meson_saradc: annotate the lock helpers
In reply to Rupesh Majhimeson_sar_adc_lock() returns 0 with priv->lock held, and meson_sar_adc_unlock() releases it. Annotate both so context analysis follows the lock into the callers. Only indio_dev is in scope in the annotation, so the lock is reached through iio_priv().
---
Cc: Marco Elver <[email protected]>
Cc: Bart Van Assche <[email protected]>
drivers/iio/adc/meson_saradc.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/iio/adc/meson_saradc.c +2 -0
@@ -578,6 +578,7 @@ static void meson_sar_adc_stop_sample_engine(struct iio_dev *indio_dev) }static int meson_sar_adc_lock (struct iio_dev *indio_dev) + __cond_acquires(0, &((struct meson_sar_adc_priv *)iio_priv(indio_dev))->lock) {struct meson_sar_adc_priv *priv =iio_priv (indio_dev);int val, ret;
@@ -608,6 +609,7 @@ static int meson_sar_adc_lock(struct iio_dev *indio_dev) }static void meson_sar_adc_unlock (struct iio_dev *indio_dev) + __releases(&((struct meson_sar_adc_priv *)iio_priv(indio_dev))->lock) {struct meson_sar_adc_priv *priv =iio_priv (indio_dev);
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v4 5/9] iio: adc: meson_saradc: annotate the lock helpers
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] iio: adc: meson_saradc: context analysis warning in meson_sar_adc_hw_disable() --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] iio: adc: meson_saradc: context analysis warning in meson_sar_adc_hw_disable() --
commit ab37c3948447f440afeebef2fb0a7a0fdf5e9e63
Author: Rupesh Majhi <[email protected]>
iio: adc: meson_saradc: annotate the lock helpers
This patch adds __cond_acquires() and __releases() context analysis annotations to meson_sar_adc_lock() and meson_sar_adc_unlock() so that compiler context analysis tracks priv->lock across their callers.
Quoted 13 lines
drivers/iio/adc/meson_saradc.c +1
-0@@ -578,6 +578,7 @@ static void meson_sar_adc_stop_sample_engine(struct iio_dev *indio_dev) }static int meson_sar_adc_lock (struct iio_dev *indio_dev) + __cond_acquires(0, &((struct meson_sar_adc_priv *)iio_priv(indio_dev))->lock) {struct meson_sar_adc_priv *priv =iio_priv (indio_dev);int val, ret;
drivers/iio/adc/meson_saradc.c static int meson_sar_adc_lock(struct iio_dev *indio_dev) · line 612
Quoted 4 lines
drivers/iio/adc/meson_saradc.c +1
-0@@ -608,6 +609,7 @@ static int meson_sar_adc_lock(struct iio_dev *indio_dev) } static void meson_sar_adc_unlock(struct iio_dev *indio_dev) + __releases(&((struct meson_sar_adc_priv *)iio_priv(indio_dev))->lock)
[Severity: Medium]
Does adding these annotations trigger a -Wthread-safety-analysis warning in meson_sar_adc_hw_disable() when context analysis is enabled?
In drivers/iio/adc/meson_saradc.c:meson_sar_adc_hw_disable(), the caller logs an error if meson_sar_adc_lock() fails, but continues execution rather than returning early:
ret = meson_sar_adc_lock(indio_dev); if (ret) dev_err(indio_dev->dev.parent, "Failed to lock ADC (%pE)\n", ERR_PTR(ret)); clk_disable_unprepare(priv->adc_clk); regmap_clear_bits(priv->regmap, MESON_SAR_ADC_REG3, MESON_SAR_ADC_REG3_ADC_EN); meson_sar_adc_set_bandgap(indio_dev, false); regulator_disable(priv->vref); if (!ret) meson_sar_adc_unlock(indio_dev);
Because the error branch falls through, the locked (ret == 0) and unlocked (ret != 0) control-flow paths merge at clk_disable_unprepare(priv->adc_clk) with mismatched lock sets, followed by a conditional unlock at if (!ret).
When building with CONFIG_MESON_SARADC=y and CONFIG_WARN_CONTEXT_ANALYSIS=y (and CONTEXT_ANALYSIS := y enabled for IIO drivers), wouldn't Clang warn that priv->lock is not held on every path through here and on the conditional release in meson_sar_adc_unlock(), unless meson_sar_adc_hw_disable() is also annotated with __context_unsafe() or its control flow is restructured?
Signature · 6 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5 _______________________________________________ linux-amlogic mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-amlogic
PATCH v4 6/9 iio: buffer-dma: annotate the queue lock helpers
In reply to Rupesh Majhiiio_dma_buffer_lock_queue() and iio_dma_buffer_unlock_queue() take and release the queue lock for the core. Annotate them with that lock so context analysis checks them.
---
Cc: Marco Elver <[email protected]>
Cc: Bart Van Assche <[email protected]>
drivers/iio/buffer/industrialio-buffer-dma.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/iio/buffer/industrialio-buffer-dma.c +2 -0
@@ -763,6 +763,7 @@ struct device *iio_dma_buffer_get_dma_dev(struct iio_buffer *buffer)EXPORT_SYMBOL_NS_GPL (iio_dma_buffer_get_dma_dev,"IIO_DMA_BUFFER" );void iio_dma_buffer_lock_queue (struct iio_buffer *buffer) + __acquires(&iio_buffer_to_queue(buffer)->lock) {struct iio_dma_buffer_queue *queue =iio_buffer_to_queue (buffer);
@@ -771,6 +772,7 @@ void iio_dma_buffer_lock_queue(struct iio_buffer *buffer)EXPORT_SYMBOL_NS_GPL (iio_dma_buffer_lock_queue,"IIO_DMA_BUFFER" );void iio_dma_buffer_unlock_queue (struct iio_buffer *buffer) + __releases(&iio_buffer_to_queue(buffer)->lock) {struct iio_dma_buffer_queue *queue =iio_buffer_to_queue (buffer);
Signature · 1 line
2.43.0
PATCH v4 7/9 iio: light: opt3001: mark the interrupt handler __context_unsafe
In reply to Rupesh Majhiopt3001_irq() takes opt->lock only when ok_to_ignore_lock is false, and releases it under the same test. Context analysis does not follow a lock taken and released on a condition, so mark the handler __context_unsafe().
---
Cc: Marco Elver <[email protected]>
Cc: Bart Van Assche <[email protected]>
drivers/iio/light/opt3001.c | 1 + 1 file changed, 1 insertion(+)
drivers/iio/light/opt3001.c +1 -0
@@ -817,6 +817,7 @@ static int opt3001_configure(struct opt3001 *opt) }static irqreturn_t opt3001_irq (int irq,void *_iio) +__context_unsafe (/* lock only taken when !ok_to_ignore_lock */ ) {struct iio_dev *iio = _iio;struct opt3001 *opt =iio_priv (iio);
Signature · 1 line
2.43.0
PATCH v4 8/9 iio: light: veml6031x00: annotate the event enable helpers
In reply to Rupesh Majhiveml6031x00_event_enable() and veml6031x00_event_disable() call veml6031x00_set_interrupt(), which needs irq_lock held. Their only caller holds it, so mark both __must_hold(&data->irq_lock).
---
Cc: Marco Elver <[email protected]>
Cc: Bart Van Assche <[email protected]>
drivers/iio/light/veml6031x00.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/iio/light/veml6031x00.c +2 -0
@@ -784,6 +784,7 @@ static int veml6031x00_read_event_config(struct iio_dev *iio, }static int veml6031x00_event_enable (struct veml6031x00_data *data) + __must_hold(&data->irq_lock) {struct device *dev =regmap_get_device (data->regmap);int ret;
@@ -804,6 +805,7 @@ static int veml6031x00_event_enable(struct veml6031x00_data *data) }static int veml6031x00_event_disable (struct veml6031x00_data *data) + __must_hold(&data->irq_lock) {struct device *dev =regmap_get_device (data->regmap);int ret;
Signature · 1 line
2.43.0
Re: [PATCH v4 8/9] iio: light: veml6031x00: annotate the event enable helpers
Quoted 25 lines · Rupesh Majhi
veml6031x00_event_enable()andveml6031x00_event_disable()callveml6031x00_set_interrupt(), which needsirq_lockheld. Their only caller holds it, so mark both__must_hold(&data->irq_lock).Signed-off-by Rupesh Majhi <[email protected]>---
Cc: Marco Elver <[email protected]>
Cc: Bart Van Assche <[email protected]>drivers/iio/light/veml6031x00.c | 2 ++ 1 file changed, 2 insertions(+)drivers/iio/light/veml6031x00.c +1
-0@@ -784,6 +784,7 @@ static int veml6031x00_read_event_config(struct iio_dev *iio, }static int veml6031x00_event_enable (struct veml6031x00_data *data) + __must_hold(&data->irq_lock) {struct device *dev =regmap_get_device (data->regmap);int ret;
drivers/iio/light/veml6031x00.c static int veml6031x00_event_enable(struct veml6031x00_data *data) · line 811
Quoted 7 lines
drivers/iio/light/veml6031x00.c +1
-0@@ -804,6 +805,7 @@ static int veml6031x00_event_enable(struct veml6031x00_data *data) }static int veml6031x00_event_disable (struct veml6031x00_data *data) + __must_hold(&data->irq_lock) {struct device *dev =regmap_get_device (data->regmap);int ret;
Thanks!
PATCH v4 9/9 iio: enable context analysis for all drivers
In reply to Rupesh MajhiAll of drivers/iio now builds without context analysis warnings, so enable it in every Makefile that builds objects, replacing the entry for dps310 alone.
---
Cc: Marco Elver <[email protected]>
Cc: Bart Van Assche <[email protected]>
drivers/iio/Makefile | 2 ++ drivers/iio/accel/Makefile | 2 ++ drivers/iio/adc/Makefile | 2 ++ drivers/iio/addac/Makefile | 2 ++ drivers/iio/afe/Makefile | 2 ++ drivers/iio/amplifiers/Makefile | 2 ++ drivers/iio/buffer/Makefile | 2 ++ drivers/iio/cdc/Makefile | 2 ++ drivers/iio/chemical/Makefile | 2 ++ drivers/iio/common/cros_ec_sensors/Makefile | 2 ++ drivers/iio/common/hid-sensors/Makefile | 2 ++ drivers/iio/common/inv_sensors/Makefile | 2 ++ drivers/iio/common/ms_sensors/Makefile | 2 ++ drivers/iio/common/scmi_sensors/Makefile | 3 +++ drivers/iio/common/ssp_sensors/Makefile | 2 ++ drivers/iio/common/st_sensors/Makefile | 2 ++ drivers/iio/dac/Makefile | 2 ++ drivers/iio/dummy/Makefile | 2 ++ drivers/iio/filter/Makefile | 2 ++ drivers/iio/flow/Makefile | 2 ++ drivers/iio/frequency/Makefile | 2 ++ drivers/iio/gyro/Makefile | 2 ++ drivers/iio/health/Makefile | 2 ++ drivers/iio/humidity/Makefile | 2 ++ drivers/iio/imu/Makefile | 2 ++ drivers/iio/imu/bmi160/Makefile | 3 +++ drivers/iio/imu/bmi270/Makefile | 3 +++ drivers/iio/imu/bmi323/Makefile | 3 +++ drivers/iio/imu/bno055/Makefile | 2 ++ drivers/iio/imu/inv_icm42600/Makefile | 2 ++ drivers/iio/imu/inv_icm42607/Makefile | 2 ++ drivers/iio/imu/inv_icm45600/Makefile | 2 ++ drivers/iio/imu/inv_mpu6050/Makefile | 2 ++ drivers/iio/imu/smi330/Makefile | 3 +++ drivers/iio/imu/st_lsm6dsx/Makefile | 3 +++ drivers/iio/imu/st_lsm9ds0/Makefile | 3 +++ drivers/iio/light/Makefile | 2 ++ drivers/iio/magnetometer/Makefile | 2 ++ drivers/iio/multiplexer/Makefile | 2 ++ drivers/iio/orientation/Makefile | 2 ++ drivers/iio/position/Makefile | 2 ++ drivers/iio/potentiometer/Makefile | 2 ++ drivers/iio/potentiostat/Makefile | 2 ++ drivers/iio/pressure/Makefile | 2 +- drivers/iio/proximity/Makefile | 2 ++ drivers/iio/resolver/Makefile | 2 ++ drivers/iio/sensorhubs/osf/Makefile | 2 ++ drivers/iio/temperature/Makefile | 2 ++ drivers/iio/test/Makefile | 2 ++ drivers/iio/trigger/Makefile | 2 ++ 50 files changed, 106 insertions(+), 1 deletion(-)
drivers/iio/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for the industrial I/O core. # +CONTEXT_ANALYSIS := y + obj-$(CONFIG_IIO) += industrialio.o industrialio-y := industrialio-core.o industrialio-event.o inkern.o industrialio-$(CONFIG_IIO_BUFFER) += industrialio-buffer.o
drivers/iio/accel/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for industrial I/O accelerometer drivers # +CONTEXT_ANALYSIS := y + # When adding new entries keep the list in alphabetical order obj-$(CONFIG_ADIS16201) += adis16201.o obj-$(CONFIG_ADIS16209) += adis16209.o
drivers/iio/adc/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for IIO ADC drivers # +CONTEXT_ANALYSIS := y + obj-$(CONFIG_IIO_ADC_HELPER) += industrialio-adc.o # When adding new entries keep the list in alphabetical order
drivers/iio/addac/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for industrial I/O ADDAC drivers # +CONTEXT_ANALYSIS := y + # When adding new entries keep the list in alphabetical order obj-$(CONFIG_AD74115) += ad74115.o obj-$(CONFIG_AD74413R) += ad74413r.o
drivers/iio/afe/Makefile +2 -0
@@ -3,5 +3,7 @@ # Makefile for industrial I/O Analog Front Ends (AFE) # +CONTEXT_ANALYSIS := y + # When adding new entries keep the list in alphabetical order obj-$(CONFIG_IIO_RESCALE) += iio-rescale.o
drivers/iio/amplifiers/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile iio/amplifiers # +CONTEXT_ANALYSIS := y + # When adding new entries keep the list in alphabetical order obj-$(CONFIG_AD8366) += ad8366.o obj-$(CONFIG_ADA4250) += ada4250.o
drivers/iio/buffer/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for the industrial I/O buffer implementations # +CONTEXT_ANALYSIS := y + # When adding new entries keep the list in alphabetical order obj-$(CONFIG_IIO_BUFFER_CB) += industrialio-buffer-cb.o obj-$(CONFIG_IIO_BUFFER_DMA) += industrialio-buffer-dma.o
drivers/iio/cdc/Makefile +2 -0
@@ -3,5 +3,7 @@ # Makefile for industrial I/O capacitance to digital converter (CDC) drivers # +CONTEXT_ANALYSIS := y + obj-$(CONFIG_AD7150) += ad7150.o obj-$(CONFIG_AD7746) += ad7746.o
drivers/iio/chemical/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for IIO chemical sensors # +CONTEXT_ANALYSIS := y + # When adding new entries keep the list in alphabetical order obj-$(CONFIG_AOSONG_AGS02MA) += ags02ma.o obj-$(CONFIG_ATLAS_PH_SENSOR) += atlas-sensor.o
drivers/iio/common/cros_ec_sensors/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for sensors seen through the ChromeOS EC sensor hub. # +CONTEXT_ANALYSIS := y + cros-ec-sensors-core-objs += cros_ec_sensors_core.o cros_ec_sensors_trace.o obj-$(CONFIG_IIO_CROS_EC_SENSORS_CORE) += cros-ec-sensors-core.o obj-$(CONFIG_IIO_CROS_EC_SENSORS) += cros_ec_sensors.o
drivers/iio/common/hid-sensors/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for the Hid sensor common modules. # +CONTEXT_ANALYSIS := y + obj-$(CONFIG_HID_SENSOR_IIO_COMMON) += hid-sensor-iio-common.o obj-$(CONFIG_HID_SENSOR_IIO_TRIGGER) += hid-sensor-trigger.o hid-sensor-iio-common-y := hid-sensor-attributes.o
drivers/iio/common/inv_sensors/Makefile +2 -0
@@ -3,4 +3,6 @@ # Makefile for TDK-InvenSense sensors module. # +CONTEXT_ANALYSIS := y + obj-$(CONFIG_IIO_INV_SENSORS_TIMESTAMP) += inv_sensors_timestamp.o
drivers/iio/common/ms_sensors/Makefile +2 -0
@@ -3,4 +3,6 @@ # Makefile for the Measurement Specialties sensor common modules. # +CONTEXT_ANALYSIS := y + obj-$(CONFIG_IIO_MS_SENSORS_I2C) += ms_sensors_i2c.o
drivers/iio/common/scmi_sensors/Makefile +3 -0
@@ -2,4 +2,7 @@ # # Makefile for the IIO over SCMI # + +CONTEXT_ANALYSIS := y + obj-$(CONFIG_IIO_SCMI) += scmi_iio.o
drivers/iio/common/ssp_sensors/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for SSP sensor drivers and commons. # +CONTEXT_ANALYSIS := y + sensorhub-objs := ssp_dev.o ssp_spi.o obj-$(CONFIG_IIO_SSP_SENSORHUB) += sensorhub.o
drivers/iio/common/st_sensors/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for the STMicroelectronics sensor common modules. # +CONTEXT_ANALYSIS := y + obj-$(CONFIG_IIO_ST_SENSORS_I2C) += st_sensors_i2c.o obj-$(CONFIG_IIO_ST_SENSORS_SPI) += st_sensors_spi.o obj-$(CONFIG_IIO_ST_SENSORS_CORE) += st_sensors.o
drivers/iio/dac/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for industrial I/O DAC drivers # +CONTEXT_ANALYSIS := y + # When adding new entries keep the list in alphabetical order obj-$(CONFIG_AD3530R) += ad3530r.o obj-$(CONFIG_AD3552R_HS) += ad3552r-hs.o
drivers/iio/dummy/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for the IIO Dummy Driver # +CONTEXT_ANALYSIS := y + obj-$(CONFIG_IIO_SIMPLE_DUMMY) += iio_dummy.o iio_dummy-y := iio_simple_dummy.o iio_dummy-$(CONFIG_IIO_SIMPLE_DUMMY_EVENTS) += iio_simple_dummy_events.o
drivers/iio/filter/Makefile +2 -0
@@ -3,5 +3,7 @@ # Makefile for industrial I/O Filter drivers # +CONTEXT_ANALYSIS := y + # When adding new entries keep the list in alphabetical order obj-$(CONFIG_ADMV8818) += admv8818.o
drivers/iio/flow/Makefile +2 -0
@@ -3,5 +3,7 @@ # Makefile for industrial I/O flow sensor drivers # +CONTEXT_ANALYSIS := y + # When adding new entries keep the list in alphabetical order obj-$(CONFIG_SENSIRION_SLF3S) += slf3s.o
drivers/iio/frequency/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile iio/frequency # +CONTEXT_ANALYSIS := y + # When adding new entries keep the list in alphabetical order obj-$(CONFIG_AD9523) += ad9523.o obj-$(CONFIG_AD9910) += ad9910.o
drivers/iio/gyro/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for industrial I/O gyroscope sensor drivers # +CONTEXT_ANALYSIS := y + # When adding new entries keep the list in alphabetical order obj-$(CONFIG_ADIS16080) += adis16080.o obj-$(CONFIG_ADIS16130) += adis16130.o
drivers/iio/health/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for IIO Health sensors # +CONTEXT_ANALYSIS := y + # When adding new entries keep the list in alphabetical order obj-$(CONFIG_AFE4403) += afe4403.o
drivers/iio/humidity/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for IIO humidity sensor drivers # +CONTEXT_ANALYSIS := y + obj-$(CONFIG_AM2315) += am2315.o obj-$(CONFIG_DHT11) += dht11.o obj-$(CONFIG_ENS210) += ens210.o
drivers/iio/imu/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for Inertial Measurement Units # +CONTEXT_ANALYSIS := y + # When adding new entries keep the list in alphabetical order obj-$(CONFIG_ADIS16400) += adis16400.o obj-$(CONFIG_ADIS16460) += adis16460.o
drivers/iio/imu/bmi160/Makefile +3 -0
@@ -2,6 +2,9 @@ # # Makefile for Bosch BMI160 IMU # + +CONTEXT_ANALYSIS := y + obj-$(CONFIG_BMI160) += bmi160_core.o obj-$(CONFIG_BMI160_I2C) += bmi160_i2c.o obj-$(CONFIG_BMI160_SPI) += bmi160_spi.o
drivers/iio/imu/bmi270/Makefile +3 -0
@@ -2,6 +2,9 @@ # # Makefile for Bosch BMI270 IMU # + +CONTEXT_ANALYSIS := y + obj-$(CONFIG_BMI270) += bmi270_core.o obj-$(CONFIG_BMI270_I2C) += bmi270_i2c.o obj-$(CONFIG_BMI270_SPI) += bmi270_spi.o
drivers/iio/imu/bmi323/Makefile +3 -0
@@ -2,6 +2,9 @@ # # Makefile for Bosch BMI323 IMU # + +CONTEXT_ANALYSIS := y + obj-$(CONFIG_BMI323) += bmi323_core.o obj-$(CONFIG_BMI323_I2C) += bmi323_i2c.o obj-$(CONFIG_BMI323_SPI) += bmi323_spi.o
drivers/iio/imu/bno055/Makefile +2 -0
@@ -1,5 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 +CONTEXT_ANALYSIS := y + obj-$(CONFIG_BOSCH_BNO055) += bno055.o obj-$(CONFIG_BOSCH_BNO055_SERIAL) += bno055_ser.o bno055_ser-y := bno055_ser_core.o
drivers/iio/imu/inv_icm42600/Makefile +2 -0
@@ -1,5 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-or-later +CONTEXT_ANALYSIS := y + obj-$(CONFIG_INV_ICM42600) += inv-icm42600.o inv-icm42600-y += inv_icm42600_core.o inv-icm42600-y += inv_icm42600_gyro.o
drivers/iio/imu/inv_icm42607/Makefile +2 -0
@@ -1,5 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-or-later +CONTEXT_ANALYSIS := y + obj-$(CONFIG_INV_ICM42607) += inv-icm42607.o inv-icm42607-y += inv_icm42607_core.o inv-icm42607-y += inv_icm42607_gyro.o
drivers/iio/imu/inv_icm45600/Makefile +2 -0
@@ -1,5 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-or-later +CONTEXT_ANALYSIS := y + obj-$(CONFIG_INV_ICM45600) += inv-icm45600.o inv-icm45600-y += inv_icm45600_core.o inv-icm45600-y += inv_icm45600_buffer.o
drivers/iio/imu/inv_mpu6050/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for Invensense MPU6050 device. # +CONTEXT_ANALYSIS := y + obj-$(CONFIG_INV_MPU6050_IIO) += inv-mpu6050.o inv-mpu6050-y := inv_mpu_core.o inv_mpu_ring.o inv_mpu_trigger.o \ inv_mpu_aux.o inv_mpu_magn.o
drivers/iio/imu/smi330/Makefile +3 -0
@@ -2,6 +2,9 @@ # # Makefile for Bosch SMI330 IMU # + +CONTEXT_ANALYSIS := y + obj-$(CONFIG_SMI330) += smi330_core.o obj-$(CONFIG_SMI330_I2C) += smi330_i2c.o obj-$(CONFIG_SMI330_SPI) += smi330_spi.o
drivers/iio/imu/st_lsm6dsx/Makefile +3 -0
@@ -1,4 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only + +CONTEXT_ANALYSIS := y + st_lsm6dsx-y := st_lsm6dsx_core.o st_lsm6dsx_buffer.o \ st_lsm6dsx_shub.o st_lsm6dsx_fusion.o
drivers/iio/imu/st_lsm9ds0/Makefile +3 -0
@@ -1,4 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only + +CONTEXT_ANALYSIS := y + obj-$(CONFIG_IIO_ST_LSM9DS0) += st_lsm9ds0.o st_lsm9ds0-y := st_lsm9ds0_core.o obj-$(CONFIG_IIO_ST_LSM9DS0_I2C) += st_lsm9ds0_i2c.o
drivers/iio/light/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for IIO Light sensors # +CONTEXT_ANALYSIS := y + # When adding new entries keep the list in alphabetical order obj-$(CONFIG_ACPI_ALS) += acpi-als.o obj-$(CONFIG_ADJD_S311) += adjd_s311.o
drivers/iio/magnetometer/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for industrial I/O Magnetometer sensor drivers # +CONTEXT_ANALYSIS := y + # When adding new entries keep the list in alphabetical order obj-$(CONFIG_AF8133J) += af8133j.o obj-$(CONFIG_AK8974) += ak8974.o
drivers/iio/multiplexer/Makefile +2 -0
@@ -3,5 +3,7 @@ # Makefile for industrial I/O multiplexer drivers # +CONTEXT_ANALYSIS := y + # When adding new entries keep the list in alphabetical order obj-$(CONFIG_IIO_MUX) += iio-mux.o
drivers/iio/orientation/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for industrial I/O Inclinometer sensor drivers # +CONTEXT_ANALYSIS := y + # When adding new entries keep the list in alphabetical order obj-$(CONFIG_HID_SENSOR_INCLINOMETER_3D) += hid-sensor-incl-3d.o obj-$(CONFIG_HID_SENSOR_DEVICE_ROTATION) += hid-sensor-rotation.o
drivers/iio/position/Makefile +2 -0
@@ -2,6 +2,8 @@ # Makefile for IIO linear and angular position sensors # +CONTEXT_ANALYSIS := y + # When adding new entries keep the list in alphabetical order obj-$(CONFIG_HID_SENSOR_CUSTOM_INTEL_HINGE) += hid-sensor-custom-intel-hinge.o
drivers/iio/potentiometer/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for industrial I/O potentiometer drivers # +CONTEXT_ANALYSIS := y + # When adding new entries keep the list in alphabetical order obj-$(CONFIG_AD5110) += ad5110.o obj-$(CONFIG_AD5272) += ad5272.o
drivers/iio/potentiostat/Makefile +2 -0
@@ -3,5 +3,7 @@ # Makefile for industrial I/O potentiostat drivers # +CONTEXT_ANALYSIS := y + # When adding new entries keep the list in alphabetical order obj-$(CONFIG_LMP91000) += lmp91000.o
drivers/iio/pressure/Makefile +1 -1
@@ -3,7 +3,7 @@ # Makefile for industrial I/O pressure drivers # -CONTEXT_ANALYSIS_dps310.o := y +CONTEXT_ANALYSIS := y # When adding new entries keep the list in alphabetical order obj-$(CONFIG_ABP060MG) += abp060mg.o
drivers/iio/proximity/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for IIO proximity sensors # +CONTEXT_ANALYSIS := y + # When adding new entries keep the list in alphabetical order obj-$(CONFIG_AS3935) += as3935.o obj-$(CONFIG_CROS_EC_MKBP_PROXIMITY) += cros_ec_mkbp_proximity.o
drivers/iio/resolver/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for Resolver/Synchro drivers # +CONTEXT_ANALYSIS := y + obj-$(CONFIG_AD2S90) += ad2s90.o obj-$(CONFIG_AD2S1200) += ad2s1200.o obj-$(CONFIG_AD2S1210) += ad2s1210.o
drivers/iio/sensorhubs/osf/Makefile +2 -0
@@ -1,5 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only +CONTEXT_ANALYSIS := y + obj-$(CONFIG_OPEN_SENSOR_FUSION) += open-sensor-fusion.o open-sensor-fusion-y := osf_core.o osf_iio.o osf_protocol.o osf_serdev.o \
drivers/iio/temperature/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for industrial I/O temperature drivers # +CONTEXT_ANALYSIS := y + obj-$(CONFIG_IQS620AT_TEMP) += iqs620at-temp.o obj-$(CONFIG_LTC2983) += ltc2983.o obj-$(CONFIG_HID_SENSOR_TEMP) += hid-sensor-temperature.o
drivers/iio/test/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for the industrial I/O unit tests. # +CONTEXT_ANALYSIS := y + # Keep in alphabetical order obj-$(CONFIG_IIO_CHANNEL_PREFIX_KUNIT_TEST) += iio-test-channel-prefix.o obj-$(CONFIG_IIO_RESCALE_KUNIT_TEST) += iio-test-rescale.o
drivers/iio/trigger/Makefile +2 -0
@@ -3,6 +3,8 @@ # Makefile for triggers not associated with iio-devices # +CONTEXT_ANALYSIS := y + # When adding new entries keep the list in alphabetical order obj-$(CONFIG_IIO_HRTIMER_TRIGGER) += iio-trig-hrtimer.o
Signature · 1 line
2.43.0
I independently build-tested the full v4 series (1/9 through 9/9) on top of jic23/iio.git testing at 7d80b4b383bc, using Clang 24.0.0git with context analysis enabled and W=1.
Results:
- x86_64 OSF: 5/5 translation units built, 0 warnings/errors.
- ARM64 OSF: 5/5 translation units built, 0 warnings/errors.
- x86_64 allmodconfig-based IIO: 723/723 selected translation units
built, 0 warnings/errors.
As a control, enabling context analysis with 9/9 alone reproduced 256 warnings and 2 errors. Applying the complete series eliminated these diagnostics, including an OSF warning resolved by the conditional mode claim annotation in 2/9.
Testing covered compilation and static context analysis only. Final module linking, module loading and runtime/hardware testing were not performed.
Quoted 3 lines · Rupesh Majhi
All of
drivers/iionow builds without context analysis warnings, so enable it in everyMakefilethat builds objects, replacing the entry for dps310 alone.
...
Quoted 3 lines
+++ b/drivers/iio/Makefile
+CONTEXT_ANALYSIS := y
Can we reduce the churn to only adding it here and do some magic to propagate this recursively, please? I truly believe it's feasible to achieve.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 6 lines · Andy Shevchenko
Quoted 3 lines · Rupesh Majhi
All of
drivers/iionow builds without context analysis warnings, so enable it in everyMakefilethat builds objects, replacing the entry for dps310 alone.
Quoted 8 lines
...
Quoted 3 lines
+++ b/drivers/iio/Makefile
+CONTEXT_ANALYSIS := y
Can we reduce the churn to only adding it here and do some magic to propagate this recursively, please? I truly believe it's feasible to achieve.
Should be:
subdir-ccflags-y += $(CFLAGS_CONTEXT_ANALYSIS)
Jonathan Cameron
maintainerQuoted 12 lines · On Tue, 27 Oct 2026 18:21:29 +0100 Marco Elver <[email protected]> wrote:
Quoted 10 lines · Andy Shevchenko
Quoted 3 lines · Rupesh Majhi
All of
drivers/iionow builds without context analysis warnings, so enable it in everyMakefilethat builds objects, replacing the entry for dps310 alone....
Quoted 1 line
+++ b/drivers/iio/Makefile
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
+CONTEXT_ANALYSIS := y
Can we reduce the churn to only adding it here and do some magic to propagate this recursively, please? I truly believe it's feasible to achieve.
Should be:
subdir-ccflags-y += $(CFLAGS_CONTEXT_ANALYSIS)
Nice. If nothing else comes up requiring a v5. I'll tweak the last patch to just do this whilst applying.
Will leave these on the list for a few more days but I just gave them a spin and they seem to be working well.
Thanks,
Jonathan
Jonathan Cameron
maintainerQuoted 3 lines · On Tue, 27 Oct 2026 14:49:45 +0200 Rupesh Majhi <[email protected]> wrote:
Jonathan asked for the qcom-spmi-adc5-gen3 fix to become the first patch of a series that enables context analysis across IIO [1]. This is that series.
Nice work. I'm very happy to see this. I had a play the other day with the patches reordered so I could see the reports getting fixed as I went patch by patch.
Applied with the last patch modified to what Marco Elver suggested. I added a note to say that I'd modified that from the posted patch. (pasted below)
Please take a look and check I didn't mess it up.
I kept your sign off as fundamental change was yours even if the actual diff ends up completely different!
Now on the testing branch of iio.git which I'll rebase on rc1 in the next few days and push out for linux-next to pick up towards the end of the week.
Thanks,
Jonathan
From 137ca6e5de3bd4e1056877d0b82214e82143efa7 Mon Sep 17 00:00:00 2001
From: Rupesh Majhi <[email protected]>
Date: Sun, 1 Nov 2026 03:24:24 +0000
Subject: [PATCH] All of drivers/iio now builds without context analysis
warnings, so enable it for drivers/iio.
Modified from posted patch following suggestion from Marco Elver to limit the necessary change to the top level Makefile.
--- drivers/iio/Makefile | 1 + 1 file changed, 1 insertion(+)
drivers/iio/Makefile +1 -0
@@ -2,6 +2,7 @@ # # Makefile for the industrial I/O core. # +subdir-ccflags-y += $(CFLAGS_CONTEXT_ANALYSIS) obj-$(CONFIG_IIO) += industrialio.o industrialio-y := industrialio-core.o industrialio-event.o inkern.o
Signature · 1 line
2.56.0
Quoted 1 line · On Sun, 01 Nov 2026 03:30:18 +0000 Jonathan Cameron <[email protected]> wrote:
Please take a look and check I didn't mess it up.
Diff is fine. Built drivers/iio with clang 23 allmodconfig: no warnings, and a dropped unlock is still caught.
Subject line got lost though. It should be "iio: enable context analysis for all drivers".
CONTEXT_ANALYSIS_dps310.o := y in pressure/Makefile can go now too. I can send a follow-up.
Jinseob Kim's Tested-by didn't make it in:
https://lore.kernel.org/linux-iio/CALMSew+nhZp9BoqS5tOgFdiVy13U1r2f4UQa9Sd5zc9pSt_YcA@mail.gmail.com/
Rupesh
Jonathan Cameron
maintainerQuoted 10 lines · On Sun, 1 Nov 2026 12:58:32 +0200 Rupesh Majhi <[email protected]> wrote:
Quoted 1 line · On Sun, 01 Nov 2026 03:30:18 +0000 Jonathan Cameron <[email protected]> wrote:
Please take a look and check I didn't mess it up.
Diff is fine. Built
drivers/iiowith clang 23 allmodconfig: no warnings, and a dropped unlock is still caught.Subject line got lost though. It should be "iio: enable context analysis for all drivers".
Doh. Cut and paste bug!
Quoted 3 lines
CONTEXT_ANALYSIS_dps310.o := y in pressure/Makefile can go now too. I can send a follow-up.
No problem - I roled that in. Didn't bother changing the commit message as it is obvious what is going on there.
Quoted 3 lines
Jinseob Kim's Tested-by didn't make it in:
https://lore.kernel.org/linux-iio/CALMSew+nhZp9BoqS5tOgFdiVy13U1r2f4UQa9Sd5zc9pSt_YcA@mail.gmail.com/
Ah. b4 didn't pick that. I guess because the formatting was missing the <> around the email address that is standard. Anyhow, fixed up.
Thanks!
Jonathan
Quoted 2 lines
Rupesh
Quoted 2 lines · Jonathan Cameron
On Tue, 27 Oct 2026 14:49:45 +0200
Rupesh Majhi <[email protected]> wrote:
...
Quoted 4 lines
#
#Makefilefor the industrial I/O core.
#
+subdir-ccflags-y += $(CFLAGS_CONTEXT_ANALYSIS)
Personally I would move this to the end of Makefile.
Quoted 2 lines
obj-$(CONFIG_IIO) += industrialio.o
industrialio-y := industrialio-core.o industrialio-event.o inkern.o
But if it's already in, it's not a big deal.
Signature · 2 lines
With Best Regards, Andy Shevchenko