@@ -221,20 +221,24 @@ static int stk8ba50_read_raw(struct iio_dev *indio_dev,
return -EBUSY;
mutex_lock(&data->lock);
ret = stk8ba50_set_power(data, STK8BA50_MODE_NORMAL);
- if (ret < 0) {
- mutex_unlock(&data->lock);
- return -EINVAL;
- }
+ if (ret < 0)
+ goto e_inval;
+
ret = stk8ba50_read_accel(data, chan->address);
if (ret < 0) {
stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND);
- mutex_unlock(&data->lock);
- return -EINVAL;
+e_inval:
+ ret = -EINVAL;
+ goto unlock;
}
*val = sign_extend32(ret >> STK8BA50_DATA_SHIFT, 9);
- stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND);
+ ret = stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND);
+unlock:
mutex_unlock(&data->lock);
- return IIO_VAL_INT;
+ if (ret >= 0)
+ ret = IIO_VAL_INT;
+
+ return ret;
case IIO_CHAN_INFO_SCALE:
*val = 0;
*val2 = stk8ba50_scale_table[data->range].scale_val;