mirror of
https://github.com/torvalds/linux.git
synced 2026-05-26 08:02:27 +02:00
iio: light: vcnl4000: Use IIO cleanup helpers
Use IIO_DEV_ACQUIRE_DIRECT_MODE() helper to automatically release direct mode. 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>
This commit is contained in:
parent
7a38b75da1
commit
6a3fe0fc9e
|
|
@ -1078,20 +1078,17 @@ static int vcnl4010_read_raw(struct iio_dev *indio_dev,
|
|||
|
||||
switch (mask) {
|
||||
case IIO_CHAN_INFO_RAW:
|
||||
case IIO_CHAN_INFO_SCALE:
|
||||
if (!iio_device_claim_direct(indio_dev))
|
||||
case IIO_CHAN_INFO_SCALE: {
|
||||
IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim);
|
||||
if (IIO_DEV_ACQUIRE_FAILED(claim))
|
||||
return -EBUSY;
|
||||
|
||||
/* Protect against event capture. */
|
||||
if (vcnl4010_is_in_periodic_mode(data)) {
|
||||
ret = -EBUSY;
|
||||
} else {
|
||||
ret = vcnl4000_read_raw(indio_dev, chan, val, val2,
|
||||
mask);
|
||||
}
|
||||
if (vcnl4010_is_in_periodic_mode(data))
|
||||
return -EBUSY;
|
||||
|
||||
iio_device_release_direct(indio_dev);
|
||||
return ret;
|
||||
return vcnl4000_read_raw(indio_dev, chan, val, val2, mask);
|
||||
}
|
||||
case IIO_CHAN_INFO_SAMP_FREQ:
|
||||
switch (chan->type) {
|
||||
case IIO_PROXIMITY:
|
||||
|
|
@ -1148,36 +1145,27 @@ static int vcnl4010_write_raw(struct iio_dev *indio_dev,
|
|||
struct iio_chan_spec const *chan,
|
||||
int val, int val2, long mask)
|
||||
{
|
||||
int ret;
|
||||
struct vcnl4000_data *data = iio_priv(indio_dev);
|
||||
|
||||
if (!iio_device_claim_direct(indio_dev))
|
||||
IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim);
|
||||
if (IIO_DEV_ACQUIRE_FAILED(claim))
|
||||
return -EBUSY;
|
||||
|
||||
/* Protect against event capture. */
|
||||
if (vcnl4010_is_in_periodic_mode(data)) {
|
||||
ret = -EBUSY;
|
||||
goto end;
|
||||
}
|
||||
if (vcnl4010_is_in_periodic_mode(data))
|
||||
return -EBUSY;
|
||||
|
||||
switch (mask) {
|
||||
case IIO_CHAN_INFO_SAMP_FREQ:
|
||||
switch (chan->type) {
|
||||
case IIO_PROXIMITY:
|
||||
ret = vcnl4010_write_proxy_samp_freq(data, val, val2);
|
||||
goto end;
|
||||
return vcnl4010_write_proxy_samp_freq(data, val, val2);
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
goto end;
|
||||
return -EINVAL;
|
||||
}
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
goto end;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
end:
|
||||
iio_device_release_direct(indio_dev);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int vcnl4010_read_event(struct iio_dev *indio_dev,
|
||||
|
|
@ -1438,14 +1426,13 @@ static int vcnl4010_config_threshold_disable(struct vcnl4000_data *data)
|
|||
static int vcnl4010_config_threshold(struct iio_dev *indio_dev, bool state)
|
||||
{
|
||||
struct vcnl4000_data *data = iio_priv(indio_dev);
|
||||
int ret;
|
||||
|
||||
if (state) {
|
||||
if (!iio_device_claim_direct(indio_dev))
|
||||
IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim);
|
||||
if (IIO_DEV_ACQUIRE_FAILED(claim))
|
||||
return -EBUSY;
|
||||
ret = vcnl4010_config_threshold_enable(data);
|
||||
iio_device_release_direct(indio_dev);
|
||||
return ret;
|
||||
|
||||
return vcnl4010_config_threshold_enable(data);
|
||||
} else {
|
||||
return vcnl4010_config_threshold_disable(data);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user