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

iio: adc: ad7791: Factor out core of ad7791_write_raw() to simplify error handling

Factor out everything under the direct mode claim allowing direct returns
in error paths.

Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Link: https://patch.msgid.link/20250217141630.897334-16-jic23@kernel.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

+18 -12
+18 -12
drivers/iio/adc/ad7791.c
··· 310 310 return -EINVAL; 311 311 } 312 312 313 - static int ad7791_write_raw(struct iio_dev *indio_dev, 313 + static int __ad7791_write_raw(struct iio_dev *indio_dev, 314 314 struct iio_chan_spec const *chan, int val, int val2, long mask) 315 315 { 316 316 struct ad7791_state *st = iio_priv(indio_dev); 317 - int ret, i; 318 - 319 - ret = iio_device_claim_direct_mode(indio_dev); 320 - if (ret) 321 - return ret; 317 + int i; 322 318 323 319 switch (mask) { 324 320 case IIO_CHAN_INFO_SAMP_FREQ: ··· 324 328 break; 325 329 } 326 330 327 - if (i == ARRAY_SIZE(ad7791_sample_freq_avail)) { 328 - ret = -EINVAL; 329 - break; 330 - } 331 + if (i == ARRAY_SIZE(ad7791_sample_freq_avail)) 332 + return -EINVAL; 331 333 332 334 st->filter &= ~AD7791_FILTER_RATE_MASK; 333 335 st->filter |= i; 334 336 ad_sd_write_reg(&st->sd, AD7791_REG_FILTER, 335 337 sizeof(st->filter), 336 338 st->filter); 337 - break; 339 + return 0; 338 340 default: 339 - ret = -EINVAL; 341 + return -EINVAL; 340 342 } 343 + } 344 + 345 + static int ad7791_write_raw(struct iio_dev *indio_dev, 346 + struct iio_chan_spec const *chan, int val, int val2, long mask) 347 + { 348 + int ret; 349 + 350 + ret = iio_device_claim_direct_mode(indio_dev); 351 + if (ret) 352 + return ret; 353 + 354 + ret = __ad7791_write_raw(indio_dev, chan, val, val2, mask); 341 355 342 356 iio_device_release_direct_mode(indio_dev); 343 357 return ret;