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

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

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
8284a498 421ac0c2

+17 -35
+17 -35
drivers/iio/light/opt4060.c
··· 302 302 bool continuous_irq) 303 303 { 304 304 struct opt4060_chip *chip = iio_priv(indio_dev); 305 - int ret = 0; 306 - any_mode_retry: 307 - if (!iio_device_try_claim_buffer_mode(indio_dev)) { 308 - /* 309 - * This one is a *bit* hacky. If we cannot claim buffer mode, 310 - * then try direct mode so that we make sure things cannot 311 - * concurrently change. And we just keep trying until we get one 312 - * of the modes... 313 - */ 314 - if (!iio_device_claim_direct(indio_dev)) 315 - goto any_mode_retry; 316 - /* 317 - * This path means that we managed to claim direct mode. In 318 - * this case the buffer isn't enabled and it's okay to leave 319 - * continuous mode for sampling and/or irq. 320 - */ 321 - ret = opt4060_set_state_common(chip, continuous_sampling, 322 - continuous_irq); 323 - iio_device_release_direct(indio_dev); 324 - return ret; 325 - } else { 326 - /* 327 - * This path means that we managed to claim buffer mode. In 328 - * this case the buffer is enabled and irq and sampling must go 329 - * to or remain continuous, but only if the trigger is from this 330 - * device. 331 - */ 332 - if (!iio_trigger_validate_own_device(indio_dev->trig, indio_dev)) 333 - ret = opt4060_set_state_common(chip, true, true); 334 - else 335 - ret = opt4060_set_state_common(chip, continuous_sampling, 336 - continuous_irq); 337 - iio_device_release_buffer_mode(indio_dev); 338 - } 339 - return ret; 305 + 306 + IIO_DEV_GUARD_CURRENT_MODE(indio_dev); 307 + 308 + /* 309 + * If we manage to claim buffer mode and we are using our own trigger, 310 + * IRQ and sampling must go to or remain continuous. 311 + */ 312 + if (iio_buffer_enabled(indio_dev) && 313 + iio_trigger_validate_own_device(indio_dev->trig, indio_dev)) 314 + return opt4060_set_state_common(chip, true, true); 315 + 316 + /* 317 + * This path means that we managed to claim direct mode. In this case 318 + * the buffer isn't enabled and it's okay to leave continuous mode for 319 + * sampling and/or irq. 320 + */ 321 + return opt4060_set_state_common(chip, continuous_sampling, continuous_irq); 340 322 } 341 323 342 324 /*