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: health: max30102: Use IIO cleanup helpers

Use IIO_DEV_GUARD_CURRENT_MODE() cleanup helper to simplify and drop
busy-waiting code in max30102_read_raw().

Reviewed-by: David Lechner <dlechner@baylibre.com>
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Signed-off-by: Kurt Borja <kuurtb@gmail.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Kurt Borja and committed by
Jonathan Cameron
421ac0c2 6a3fe0fc

+9 -24
+9 -24
drivers/iio/health/max30102.c
··· 467 467 int *val, int *val2, long mask) 468 468 { 469 469 struct max30102_data *data = iio_priv(indio_dev); 470 - int ret = -EINVAL; 470 + int ret; 471 471 472 472 switch (mask) { 473 - case IIO_CHAN_INFO_RAW: 473 + case IIO_CHAN_INFO_RAW: { 474 474 /* 475 475 * Temperature reading can only be acquired when not in 476 476 * shutdown; leave shutdown briefly when buffer not running 477 477 */ 478 - any_mode_retry: 479 - if (!iio_device_try_claim_buffer_mode(indio_dev)) { 480 - /* 481 - * This one is a *bit* hacky. If we cannot claim buffer 482 - * mode, then try direct mode so that we make sure 483 - * things cannot concurrently change. And we just keep 484 - * trying until we get one of the modes... 485 - */ 486 - if (!iio_device_claim_direct(indio_dev)) 487 - goto any_mode_retry; 478 + IIO_DEV_GUARD_CURRENT_MODE(indio_dev); 488 479 489 - ret = max30102_get_temp(data, val, true); 490 - iio_device_release_direct(indio_dev); 491 - } else { 492 - ret = max30102_get_temp(data, val, false); 493 - iio_device_release_buffer_mode(indio_dev); 494 - } 480 + ret = max30102_get_temp(data, val, !iio_buffer_enabled(indio_dev)); 495 481 if (ret) 496 482 return ret; 497 483 498 - ret = IIO_VAL_INT; 499 - break; 484 + return IIO_VAL_INT; 485 + } 500 486 case IIO_CHAN_INFO_SCALE: 501 487 *val = 1000; /* 62.5 */ 502 488 *val2 = 16; 503 - ret = IIO_VAL_FRACTIONAL; 504 - break; 489 + return IIO_VAL_FRACTIONAL; 490 + default: 491 + return -EINVAL; 505 492 } 506 - 507 - return ret; 508 493 } 509 494 510 495 static const struct iio_info max30102_info = {