iio: imu: bmi323: Use cleanup handling for iio_device_claim_direct_mode()
Similar to existing use of guard() in this driver, iio_device_claim_direct_scoped() will ensure that scope based cleanup occurs. Reviewed-by: Nuno Sa <nuno.a@analog.com> Link: https://lore.kernel.org/r/20240128150537.44592-5-jic23@kernel.org Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
parent
eabc6b0847
commit
b6dde10923
@ -1668,52 +1668,41 @@ static int bmi323_write_raw(struct iio_dev *indio_dev,
|
||||
int val2, long mask)
|
||||
{
|
||||
struct bmi323_data *data = iio_priv(indio_dev);
|
||||
int ret;
|
||||
|
||||
switch (mask) {
|
||||
case IIO_CHAN_INFO_SAMP_FREQ:
|
||||
ret = iio_device_claim_direct_mode(indio_dev);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = bmi323_set_odr(data, bmi323_iio_to_sensor(chan->type),
|
||||
val, val2);
|
||||
iio_device_release_direct_mode(indio_dev);
|
||||
return ret;
|
||||
iio_device_claim_direct_scoped(return -EBUSY, indio_dev)
|
||||
return bmi323_set_odr(data,
|
||||
bmi323_iio_to_sensor(chan->type),
|
||||
val, val2);
|
||||
unreachable();
|
||||
case IIO_CHAN_INFO_SCALE:
|
||||
ret = iio_device_claim_direct_mode(indio_dev);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = bmi323_set_scale(data, bmi323_iio_to_sensor(chan->type),
|
||||
val, val2);
|
||||
iio_device_release_direct_mode(indio_dev);
|
||||
return ret;
|
||||
iio_device_claim_direct_scoped(return -EBUSY, indio_dev)
|
||||
return bmi323_set_scale(data,
|
||||
bmi323_iio_to_sensor(chan->type),
|
||||
val, val2);
|
||||
unreachable();
|
||||
case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
|
||||
ret = iio_device_claim_direct_mode(indio_dev);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = bmi323_set_average(data, bmi323_iio_to_sensor(chan->type),
|
||||
val);
|
||||
|
||||
iio_device_release_direct_mode(indio_dev);
|
||||
return ret;
|
||||
iio_device_claim_direct_scoped(return -EBUSY, indio_dev)
|
||||
return bmi323_set_average(data,
|
||||
bmi323_iio_to_sensor(chan->type),
|
||||
val);
|
||||
unreachable();
|
||||
case IIO_CHAN_INFO_ENABLE:
|
||||
return bmi323_enable_steps(data, val);
|
||||
case IIO_CHAN_INFO_PROCESSED:
|
||||
scoped_guard(mutex, &data->mutex) {
|
||||
if (val || !FIELD_GET(BMI323_FEAT_IO0_STP_CNT_MSK,
|
||||
data->feature_events))
|
||||
return -EINVAL;
|
||||
case IIO_CHAN_INFO_PROCESSED: {
|
||||
guard(mutex)(&data->mutex);
|
||||
|
||||
/* Clear step counter value */
|
||||
ret = bmi323_update_ext_reg(data, BMI323_STEP_SC1_REG,
|
||||
BMI323_STEP_SC1_RST_CNT_MSK,
|
||||
FIELD_PREP(BMI323_STEP_SC1_RST_CNT_MSK,
|
||||
1));
|
||||
}
|
||||
return ret;
|
||||
if (val || !FIELD_GET(BMI323_FEAT_IO0_STP_CNT_MSK,
|
||||
data->feature_events))
|
||||
return -EINVAL;
|
||||
|
||||
/* Clear step counter value */
|
||||
return bmi323_update_ext_reg(data, BMI323_STEP_SC1_REG,
|
||||
BMI323_STEP_SC1_RST_CNT_MSK,
|
||||
FIELD_PREP(BMI323_STEP_SC1_RST_CNT_MSK,
|
||||
1));
|
||||
}
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
@ -1724,7 +1713,6 @@ static int bmi323_read_raw(struct iio_dev *indio_dev,
|
||||
int *val2, long mask)
|
||||
{
|
||||
struct bmi323_data *data = iio_priv(indio_dev);
|
||||
int ret;
|
||||
|
||||
switch (mask) {
|
||||
case IIO_CHAN_INFO_PROCESSED:
|
||||
@ -1733,14 +1721,10 @@ static int bmi323_read_raw(struct iio_dev *indio_dev,
|
||||
switch (chan->type) {
|
||||
case IIO_ACCEL:
|
||||
case IIO_ANGL_VEL:
|
||||
ret = iio_device_claim_direct_mode(indio_dev);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = bmi323_read_axis(data, chan, val);
|
||||
|
||||
iio_device_release_direct_mode(indio_dev);
|
||||
return ret;
|
||||
iio_device_claim_direct_scoped(return -EBUSY,
|
||||
indio_dev)
|
||||
return bmi323_read_axis(data, chan, val);
|
||||
unreachable();
|
||||
case IIO_TEMP:
|
||||
return bmi323_get_temp_data(data, val);
|
||||
default:
|
||||
|
Loading…
x
Reference in New Issue
Block a user