diff options
author | Alison Schofield <amsfield22@gmail.com> | 2016-06-01 00:35:49 -0400 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2016-06-03 08:12:50 -0400 |
commit | d7203ad864db0b34f0e106ec0659890c4e58c143 (patch) | |
tree | f1e4612e277b371c44c13099c8342ca2066259a3 | |
parent | afa814841c812cd1a36dbbb124542a487c2df5ee (diff) |
iio: adc: ad7791: claim direct mode when writing frequency
Driver was checking for direct mode and trying to lock it, but
left a gap where mode could change before the desired operation.
Use iio_device_claim_direct_mode() to guarantee device stays in
direct mode.
Refactor function to clarify look-up followed by lock sequence.
Signed-off-by: Alison Schofield <amsfield22@gmail.com>
Cc: Daniel Baluta <daniel.baluta@gmail.com>
Acked-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
-rw-r--r-- | drivers/iio/adc/ad7791.c | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/drivers/iio/adc/ad7791.c b/drivers/iio/adc/ad7791.c index cf172d58cd44..1dfe6410c64c 100644 --- a/drivers/iio/adc/ad7791.c +++ b/drivers/iio/adc/ad7791.c | |||
@@ -272,30 +272,22 @@ static ssize_t ad7791_write_frequency(struct device *dev, | |||
272 | struct ad7791_state *st = iio_priv(indio_dev); | 272 | struct ad7791_state *st = iio_priv(indio_dev); |
273 | int i, ret; | 273 | int i, ret; |
274 | 274 | ||
275 | mutex_lock(&indio_dev->mlock); | 275 | for (i = 0; i < ARRAY_SIZE(ad7791_sample_freq_avail); i++) |
276 | if (iio_buffer_enabled(indio_dev)) { | 276 | if (sysfs_streq(ad7791_sample_freq_avail[i], buf)) |
277 | mutex_unlock(&indio_dev->mlock); | ||
278 | return -EBUSY; | ||
279 | } | ||
280 | mutex_unlock(&indio_dev->mlock); | ||
281 | |||
282 | ret = -EINVAL; | ||
283 | |||
284 | for (i = 0; i < ARRAY_SIZE(ad7791_sample_freq_avail); i++) { | ||
285 | if (sysfs_streq(ad7791_sample_freq_avail[i], buf)) { | ||
286 | |||
287 | mutex_lock(&indio_dev->mlock); | ||
288 | st->filter &= ~AD7791_FILTER_RATE_MASK; | ||
289 | st->filter |= i; | ||
290 | ad_sd_write_reg(&st->sd, AD7791_REG_FILTER, | ||
291 | sizeof(st->filter), st->filter); | ||
292 | mutex_unlock(&indio_dev->mlock); | ||
293 | ret = 0; | ||
294 | break; | 277 | break; |
295 | } | 278 | if (i == ARRAY_SIZE(ad7791_sample_freq_avail)) |
296 | } | 279 | return -EINVAL; |
280 | |||
281 | ret = iio_device_claim_direct_mode(indio_dev); | ||
282 | if (ret) | ||
283 | return ret; | ||
284 | st->filter &= ~AD7791_FILTER_RATE_MASK; | ||
285 | st->filter |= i; | ||
286 | ad_sd_write_reg(&st->sd, AD7791_REG_FILTER, sizeof(st->filter), | ||
287 | st->filter); | ||
288 | iio_device_release_direct_mode(indio_dev); | ||
297 | 289 | ||
298 | return ret ? ret : len; | 290 | return len; |
299 | } | 291 | } |
300 | 292 | ||
301 | static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO, | 293 | static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO, |