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,
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:
......
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