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

iio: pressure: ms5611: claim direct mode during oversampling changes

Driver was checking for direct mode before changing oversampling
ratios, but was not locking it. Use the claim/release helper
functions to guarantee the device stays in direct mode while the
oversampling ratios are being updated. Continue to use the drivers
private state lock to protect against conflicting direct mode access
of the state data.

Signed-off-by: Alison Schofield <amsfield22@gmail.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

authored by

Alison Schofield and committed by
Jonathan Cameron
3bc1abcd 6b2e7589

+7 -5
+7 -5
drivers/iio/pressure/ms5611_core.c
··· 308 308 { 309 309 struct ms5611_state *st = iio_priv(indio_dev); 310 310 const struct ms5611_osr *osr = NULL; 311 + int ret; 311 312 312 313 if (mask != IIO_CHAN_INFO_OVERSAMPLING_RATIO) 313 314 return -EINVAL; ··· 322 321 if (!osr) 323 322 return -EINVAL; 324 323 325 - mutex_lock(&st->lock); 324 + ret = iio_device_claim_direct_mode(indio_dev); 325 + if (ret) 326 + return ret; 326 327 327 - if (iio_buffer_enabled(indio_dev)) { 328 - mutex_unlock(&st->lock); 329 - return -EBUSY; 330 - } 328 + mutex_lock(&st->lock); 331 329 332 330 if (chan->type == IIO_TEMP) 333 331 st->temp_osr = osr; ··· 334 334 st->pressure_osr = osr; 335 335 336 336 mutex_unlock(&st->lock); 337 + iio_device_release_direct_mode(indio_dev); 338 + 337 339 return 0; 338 340 } 339 341