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: adc: rtq6056: Use automated cleanup for mode handling in write_raw

Using iio_device_claim_direct_scoped() to automate mode claim and release
simplifies code flow and allows for straight-forward error handling with
direct returns on errors.

Signed-off-by: Gabriel Schwartz <gschwartz@usp.br>
Reviewed-by: Marcelo Schmitt <marcelo.schmitt1@gmail.com>
Reviewed-by: ChiYuan Huang <cy_huang@richtek.com>
Link: https://lore.kernel.org/r/20240426200118.20900-1-gschwartz@usp.br
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Gabriel Schwartz and committed by
Jonathan Cameron
427298c6 0d8d6264

+11 -23
+11 -23
drivers/iio/adc/rtq6056.c
··· 520 520 { 521 521 struct rtq6056_priv *priv = iio_priv(indio_dev); 522 522 const struct richtek_dev_data *devdata = priv->devdata; 523 - int ret; 524 523 525 - ret = iio_device_claim_direct_mode(indio_dev); 526 - if (ret) 527 - return ret; 528 - 529 - switch (mask) { 530 - case IIO_CHAN_INFO_SAMP_FREQ: 531 - if (devdata->fixed_samp_freq) { 532 - ret = -EINVAL; 533 - break; 524 + iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { 525 + switch (mask) { 526 + case IIO_CHAN_INFO_SAMP_FREQ: 527 + if (devdata->fixed_samp_freq) 528 + return -EINVAL; 529 + return rtq6056_adc_set_samp_freq(priv, chan, val); 530 + case IIO_CHAN_INFO_OVERSAMPLING_RATIO: 531 + return devdata->set_average(priv, val); 532 + default: 533 + return -EINVAL; 534 534 } 535 - 536 - ret = rtq6056_adc_set_samp_freq(priv, chan, val); 537 - break; 538 - case IIO_CHAN_INFO_OVERSAMPLING_RATIO: 539 - ret = devdata->set_average(priv, val); 540 - break; 541 - default: 542 - ret = -EINVAL; 543 - break; 544 535 } 545 - 546 - iio_device_release_direct_mode(indio_dev); 547 - 548 - return ret; 536 + unreachable(); 549 537 } 550 538 551 539 static const char *rtq6056_channel_labels[RTQ6056_MAX_CHANNEL] = {