* Copyright (c) Tomasz Duszynski <tduszyns@gmail.com>
*/
+#include <linux/cleanup.h>
#include <linux/crc8.h>
#include <linux/delay.h>
#include <linux/i2c.h>
{
int i, ret;
+ guard(mutex)(&state->lock);
+
if (state->state == RESET) {
ret = state->ops->start_meas(state);
if (ret)
aligned_s64 ts;
} scan;
- mutex_lock(&state->lock);
ret = sps30_do_meas(state, scan.data, ARRAY_SIZE(scan.data));
- mutex_unlock(&state->lock);
if (ret)
goto err;
case IIO_CHAN_INFO_PROCESSED:
switch (chan->type) {
case IIO_MASSCONCENTRATION:
- mutex_lock(&state->lock);
/* read up to the number of bytes actually needed */
switch (chan->channel2) {
case IIO_MOD_PM1:
ret = sps30_do_meas(state, data, 4);
break;
}
- mutex_unlock(&state->lock);
if (ret)
return ret;
if (kstrtoint(buf, 0, &val) || val != 1)
return -EINVAL;
- mutex_lock(&state->lock);
+ guard(mutex)(&state->lock);
+
ret = state->ops->clean_fan(state);
- mutex_unlock(&state->lock);
if (ret)
return ret;
__be32 val;
int ret;
- mutex_lock(&state->lock);
+ guard(mutex)(&state->lock);
+
ret = state->ops->read_cleaning_period(state, &val);
- mutex_unlock(&state->lock);
if (ret)
return ret;
(val > SPS30_AUTO_CLEANING_PERIOD_MAX))
return -EINVAL;
- mutex_lock(&state->lock);
+ guard(mutex)(&state->lock);
+
ret = state->ops->write_cleaning_period(state, cpu_to_be32(val));
- if (ret) {
- mutex_unlock(&state->lock);
+ if (ret)
return ret;
- }
msleep(20);
dev_warn(dev,
"period changed but reads will return the old value\n");
- mutex_unlock(&state->lock);
-
return len;
}