Commit b6dde109 authored by Jonathan Cameron's avatar Jonathan Cameron

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: default avatarNuno Sa <nuno.a@analog.com>
Link: https://lore.kernel.org/r/20240128150537.44592-5-jic23@kernel.orgSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent eabc6b08
...@@ -1668,52 +1668,41 @@ static int bmi323_write_raw(struct iio_dev *indio_dev, ...@@ -1668,52 +1668,41 @@ static int bmi323_write_raw(struct iio_dev *indio_dev,
int val2, long mask) int val2, long mask)
{ {
struct bmi323_data *data = iio_priv(indio_dev); struct bmi323_data *data = iio_priv(indio_dev);
int ret;
switch (mask) { switch (mask) {
case IIO_CHAN_INFO_SAMP_FREQ: case IIO_CHAN_INFO_SAMP_FREQ:
ret = iio_device_claim_direct_mode(indio_dev); iio_device_claim_direct_scoped(return -EBUSY, indio_dev)
if (ret) return bmi323_set_odr(data,
return ret; bmi323_iio_to_sensor(chan->type),
val, val2);
ret = bmi323_set_odr(data, bmi323_iio_to_sensor(chan->type), unreachable();
val, val2);
iio_device_release_direct_mode(indio_dev);
return ret;
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
ret = iio_device_claim_direct_mode(indio_dev); iio_device_claim_direct_scoped(return -EBUSY, indio_dev)
if (ret) return bmi323_set_scale(data,
return ret; bmi323_iio_to_sensor(chan->type),
val, val2);
ret = bmi323_set_scale(data, bmi323_iio_to_sensor(chan->type), unreachable();
val, val2);
iio_device_release_direct_mode(indio_dev);
return ret;
case IIO_CHAN_INFO_OVERSAMPLING_RATIO: case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
ret = iio_device_claim_direct_mode(indio_dev); iio_device_claim_direct_scoped(return -EBUSY, indio_dev)
if (ret) return bmi323_set_average(data,
return ret; bmi323_iio_to_sensor(chan->type),
val);
ret = bmi323_set_average(data, bmi323_iio_to_sensor(chan->type), unreachable();
val);
iio_device_release_direct_mode(indio_dev);
return ret;
case IIO_CHAN_INFO_ENABLE: case IIO_CHAN_INFO_ENABLE:
return bmi323_enable_steps(data, val); return bmi323_enable_steps(data, val);
case IIO_CHAN_INFO_PROCESSED: case IIO_CHAN_INFO_PROCESSED: {
scoped_guard(mutex, &data->mutex) { guard(mutex)(&data->mutex);
if (val || !FIELD_GET(BMI323_FEAT_IO0_STP_CNT_MSK,
data->feature_events))
return -EINVAL;
/* Clear step counter value */ if (val || !FIELD_GET(BMI323_FEAT_IO0_STP_CNT_MSK,
ret = bmi323_update_ext_reg(data, BMI323_STEP_SC1_REG, data->feature_events))
BMI323_STEP_SC1_RST_CNT_MSK, return -EINVAL;
FIELD_PREP(BMI323_STEP_SC1_RST_CNT_MSK,
1)); /* Clear step counter value */
} return bmi323_update_ext_reg(data, BMI323_STEP_SC1_REG,
return ret; BMI323_STEP_SC1_RST_CNT_MSK,
FIELD_PREP(BMI323_STEP_SC1_RST_CNT_MSK,
1));
}
default: default:
return -EINVAL; return -EINVAL;
} }
...@@ -1724,7 +1713,6 @@ static int bmi323_read_raw(struct iio_dev *indio_dev, ...@@ -1724,7 +1713,6 @@ static int bmi323_read_raw(struct iio_dev *indio_dev,
int *val2, long mask) int *val2, long mask)
{ {
struct bmi323_data *data = iio_priv(indio_dev); struct bmi323_data *data = iio_priv(indio_dev);
int ret;
switch (mask) { switch (mask) {
case IIO_CHAN_INFO_PROCESSED: case IIO_CHAN_INFO_PROCESSED:
...@@ -1733,14 +1721,10 @@ static int bmi323_read_raw(struct iio_dev *indio_dev, ...@@ -1733,14 +1721,10 @@ static int bmi323_read_raw(struct iio_dev *indio_dev,
switch (chan->type) { switch (chan->type) {
case IIO_ACCEL: case IIO_ACCEL:
case IIO_ANGL_VEL: case IIO_ANGL_VEL:
ret = iio_device_claim_direct_mode(indio_dev); iio_device_claim_direct_scoped(return -EBUSY,
if (ret) indio_dev)
return ret; return bmi323_read_axis(data, chan, val);
unreachable();
ret = bmi323_read_axis(data, chan, val);
iio_device_release_direct_mode(indio_dev);
return ret;
case IIO_TEMP: case IIO_TEMP:
return bmi323_get_temp_data(data, val); return bmi323_get_temp_data(data, val);
default: default:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment