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

iio: health: max30100: do not use internal iio_dev lock

The pattern used in this device does not quite fit in the
iio_device_claim_direct_mode() typical usage. In this case,
iio_buffer_enabled() was being used not to prevent the raw
access but to allow it. Hence, let's make use of the new
iio_device_claim_buffer_mode() API to make sure we stay in
buffered mode during the complete read.

Note that we are shadowing the error code returned by
iio_device_claim_buffer_mode() so that we keep the original one
(-EAGAIN). The reason is that some userspace stack might already be
relying on this particular code so that we are not taking chances and
leave it alone.

Signed-off-by: Nuno Sá <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/20221012151620.1725215-3-nuno.sa@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Nuno Sá and committed by
Jonathan Cameron
1555790c 0a856542

+9 -6
+9 -6
drivers/iio/health/max30100.c
··· 387 387 * Temperature reading can only be acquired while engine 388 388 * is running 389 389 */ 390 - mutex_lock(&indio_dev->mlock); 391 - 392 - if (!iio_buffer_enabled(indio_dev)) 390 + if (iio_device_claim_buffer_mode(indio_dev)) { 391 + /* 392 + * Replacing -EBUSY or other error code 393 + * returned by iio_device_claim_buffer_mode() 394 + * because user space may rely on the current 395 + * one. 396 + */ 393 397 ret = -EAGAIN; 394 - else { 398 + } else { 395 399 ret = max30100_get_temp(data, val); 396 400 if (!ret) 397 401 ret = IIO_VAL_INT; 398 402 403 + iio_device_release_buffer_mode(indio_dev); 399 404 } 400 - 401 - mutex_unlock(&indio_dev->mlock); 402 405 break; 403 406 case IIO_CHAN_INFO_SCALE: 404 407 *val = 1; /* 0.0625 */