Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: light: vcnl4035: Switch to sparse friendly iio_device_claim/release_direct()

These new functions allow sparse to find failures to release
direct mode reducing chances of bugs over the claim_direct_mode()
functions that are deprecated.

This case triggered a false positive from sparse, resolved by
factoring out the code that includes the claim and release of
direct mode.

Reviewed-by: David Lechner <dlechner@baylibre.com>
Link: https://patch.msgid.link/20250309170633.1347476-19-jic23@kernel.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

+26 -16
+26 -16
drivers/iio/light/vcnl4035.c
··· 156 156 return ret; 157 157 } 158 158 159 + static int vcnl4035_read_info_raw(struct iio_dev *indio_dev, 160 + struct iio_chan_spec const *chan, int *val) 161 + { 162 + struct vcnl4035_data *data = iio_priv(indio_dev); 163 + int ret; 164 + int raw_data; 165 + unsigned int reg; 166 + 167 + if (!iio_device_claim_direct(indio_dev)) 168 + return -EBUSY; 169 + 170 + if (chan->channel) 171 + reg = VCNL4035_ALS_DATA; 172 + else 173 + reg = VCNL4035_WHITE_DATA; 174 + ret = regmap_read(data->regmap, reg, &raw_data); 175 + iio_device_release_direct(indio_dev); 176 + if (ret) 177 + return ret; 178 + 179 + *val = raw_data; 180 + 181 + return IIO_VAL_INT; 182 + } 183 + 159 184 /* 160 185 * Device IT INT Time (ms) Scale (lux/step) 161 186 * 000 50 0.064 ··· 200 175 { 201 176 struct vcnl4035_data *data = iio_priv(indio_dev); 202 177 int ret; 203 - int raw_data; 204 - unsigned int reg; 205 178 206 179 switch (mask) { 207 180 case IIO_CHAN_INFO_RAW: 208 181 ret = vcnl4035_set_pm_runtime_state(data, true); 209 182 if (ret < 0) 210 183 return ret; 211 - 212 - ret = iio_device_claim_direct_mode(indio_dev); 213 - if (!ret) { 214 - if (chan->channel) 215 - reg = VCNL4035_ALS_DATA; 216 - else 217 - reg = VCNL4035_WHITE_DATA; 218 - ret = regmap_read(data->regmap, reg, &raw_data); 219 - iio_device_release_direct_mode(indio_dev); 220 - if (!ret) { 221 - *val = raw_data; 222 - ret = IIO_VAL_INT; 223 - } 224 - } 184 + ret = vcnl4035_read_info_raw(indio_dev, chan, val); 225 185 vcnl4035_set_pm_runtime_state(data, false); 226 186 return ret; 227 187 case IIO_CHAN_INFO_INT_TIME: