[PATCH v11 5/5] iio: pressure: dps310: assert the lock at runtime too

From: Rupesh Majhi

Date: Fri Oct 02 2026 - 03:26:07 EST


__must_hold() is clang only and does nothing in GCC builds. Add
lockdep_assert_held() next to each, so lockdep catches a missing lock
too.

Assisted-by: LLM
Signed-off-by: Rupesh Majhi <zoone.rupert@xxxxxxxxx>
---
drivers/iio/pressure/dps310.c | 41 +++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)

diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
index 959f4bdd3995..1614255312ba 100644
--- a/drivers/iio/pressure/dps310.c
+++ b/drivers/iio/pressure/dps310.c
@@ -13,6 +13,7 @@
#include <linux/devm-helpers.h>
#include <linux/i2c.h>
#include <linux/limits.h>
+#include <linux/lockdep.h>
#include <linux/math64.h>
#include <linux/module.h>
#include <linux/mutex.h>
@@ -359,6 +360,8 @@ static int dps310_set_pres_precision(struct dps310_data *data, int val)
int rc;
u8 shift_en;

+ lockdep_assert_held(&data->lock);
+
if (val < 0 || val > 128)
return -EINVAL;

@@ -378,6 +381,8 @@ static int dps310_set_temp_precision(struct dps310_data *data, int val)
int rc;
u8 shift_en;

+ lockdep_assert_held(&data->lock);
+
if (val < 0 || val > 128)
return -EINVAL;

@@ -396,6 +401,8 @@ static int dps310_set_pres_samp_freq(struct dps310_data *data, int freq)
{
u8 val;

+ lockdep_assert_held(&data->lock);
+
if (freq < 0 || freq > 128)
return -EINVAL;

@@ -410,6 +417,8 @@ static int dps310_set_temp_samp_freq(struct dps310_data *data, int freq)
{
u8 val;

+ lockdep_assert_held(&data->lock);
+
if (freq < 0 || freq > 128)
return -EINVAL;

@@ -509,6 +518,8 @@ static int dps310_ready(struct dps310_data *data, int ready_bit, int timeout)
{
int rc;

+ lockdep_assert_held(&data->lock);
+
rc = dps310_ready_status(data, ready_bit, timeout);
if (rc) {
if (rc == -ETIMEDOUT && !data->timeout_recovery_failed) {
@@ -539,6 +550,8 @@ static int dps310_read_pres_raw_locked(struct dps310_data *data)
int timeout;
u8 val[3];

+ lockdep_assert_held(&data->lock);
+
rc = dps310_get_pres_samp_freq(data, &rate);
if (rc)
return rc;
@@ -565,6 +578,8 @@ static int dps310_read_temp_ready(struct dps310_data *data)
int rc;
u8 val[3];

+ lockdep_assert_held(&data->lock);
+
rc = regmap_bulk_read(data->regmap, DPS310_TMP_BASE, val, sizeof(val));
if (rc < 0)
return rc;
@@ -581,6 +596,8 @@ static int dps310_read_temp_raw_locked(struct dps310_data *data)
int rate;
int timeout;

+ lockdep_assert_held(&data->lock);
+
rc = dps310_get_temp_samp_freq(data, &rate);
if (rc)
return rc;
@@ -602,6 +619,8 @@ static void dps310_refresh_temp_locked(struct dps310_data *data)
int rc;
int t_ready;

+ lockdep_assert_held(&data->lock);
+
rc = regmap_read(data->regmap, DPS310_MEAS_CFG, &t_ready);
if (rc)
return;
@@ -707,6 +726,8 @@ static int dps310_calculate_pressure(struct dps310_data *data, int *val)
s64 kp;
s64 kt;

+ lockdep_assert_held(&data->lock);
+
rc = dps310_get_pres_k(data, &kpi);
if (rc)
return rc;
@@ -832,6 +853,8 @@ static int dps310_calculate_temp(struct dps310_data *data, int *val)
s64 t;
int kt, rc;

+ lockdep_assert_held(&data->lock);
+
rc = dps310_get_temp_k(data, &kt);
if (rc)
return rc;
@@ -940,6 +963,8 @@ static int dps310_fill_channels(struct dps310_data *data,
unsigned int i;
int rc;

+ lockdep_assert_held(&data->lock);
+
/* Compensation needs a temperature, so it is sampled either way */
rc = dps310_read_temp_raw_locked(data);
if (rc)
@@ -970,12 +995,16 @@ static int dps310_fill_channels(struct dps310_data *data,
static int dps310_fifo_hw_flush(struct dps310_data *data)
__must_hold(&data->lock)
{
+ lockdep_assert_held(&data->lock);
+
return regmap_write(data->regmap, DPS310_RESET, DPS310_FIFO_FLUSH);
}

static int dps310_fifo_set_enable(struct dps310_data *data, bool enable)
__must_hold(&data->lock)
{
+ lockdep_assert_held(&data->lock);
+
return regmap_assign_bits(data->regmap, DPS310_CFG_REG, DPS310_FIFO_EN,
enable);
}
@@ -1017,6 +1046,8 @@ static int dps310_fifo_read_entry(struct dps310_data *data, s32 *value)
s32 raw;
int rc;

+ lockdep_assert_held(&data->lock);
+
/* Entries come out of the pressure registers whichever made them */
rc = regmap_bulk_read(data->regmap, DPS310_PRS_BASE, val, sizeof(val));
if (rc < 0)
@@ -1041,6 +1072,8 @@ static int dps310_fifo_push_scan(struct dps310_data *data, s32 temp_raw,
unsigned int i;
int rc;

+ lockdep_assert_held(&data->lock);
+
/* Direct-mode claim keeps sysfs reads off these */
data->temp_raw = temp_raw;
data->pressure_raw = pressure_raw;
@@ -1067,6 +1100,8 @@ static int dps310_fifo_push_scan(struct dps310_data *data, s32 temp_raw,
static void dps310_fifo_hold(struct dps310_data *data, s32 pressure_raw)
__must_hold(&data->lock)
{
+ lockdep_assert_held(&data->lock);
+
if (data->fifo_held < data->fifo_hold_max)
data->fifo_hold[data->fifo_held++] = pressure_raw;
}
@@ -1078,6 +1113,8 @@ static unsigned int dps310_fifo_push_held(struct dps310_data *data)
unsigned int pushed = 0;
unsigned int i;

+ lockdep_assert_held(&data->lock);
+
for (i = 0; i < data->fifo_held; i++) {
if (!dps310_fifo_push_scan(data, data->fifo_temp_raw,
data->fifo_hold[i]))
@@ -1111,6 +1148,8 @@ static int dps310_fifo_drain(struct dps310_data *data, unsigned int max_scans)
bool is_pressure;
int rc;

+ lockdep_assert_held(&data->lock);
+
for (cnt = 0; cnt < DPS310_FIFO_DEPTH; cnt++) {
if (max_scans && scans >= max_scans)
break;
@@ -1182,6 +1221,8 @@ static int dps310_fifo_hold_alloc(struct dps310_data *data, int prs_rate,
int tmp_rate)
__must_hold(&data->lock)
{
+ lockdep_assert_held(&data->lock);
+
data->fifo_temp_valid = false;
data->fifo_held = 0;
data->fifo_hold = NULL;
--
2.43.0