summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorIvan Mikhaylov <i.mikhaylov@yadro.com>2021-07-22 18:44:20 +0300
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2021-07-24 18:07:17 +0300
commit7ff98c8afa46ea0ca207bcc89185ea28e6e83829 (patch)
tree575c74183b951fffc4dd31ae96fa35d2d724a2dd /drivers
parent3363fbbe19e542e183bcc32780cf1d5d4156a5b2 (diff)
downloadlinux-7ff98c8afa46ea0ca207bcc89185ea28e6e83829.tar.xz
iio: proximity: vcnl3020: remove iio_claim/release_direct
Remove iio_claim/release and change it on mutex accordingly in vcnl3020_write_proxy_samp_freq. Signed-off-by: Ivan Mikhaylov <i.mikhaylov@yadro.com> Link: https://lore.kernel.org/r/20210722154420.915082-4-i.mikhaylov@yadro.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/iio/proximity/vcnl3020.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/drivers/iio/proximity/vcnl3020.c b/drivers/iio/proximity/vcnl3020.c
index bcc4cef127a4..ff83638db16f 100644
--- a/drivers/iio/proximity/vcnl3020.c
+++ b/drivers/iio/proximity/vcnl3020.c
@@ -236,10 +236,15 @@ static int vcnl3020_write_proxy_samp_freq(struct vcnl3020_data *data, int val,
{
unsigned int i;
int index = -1;
+ int rc;
+
+ mutex_lock(&data->lock);
/* Protect against event capture. */
- if (vcnl3020_is_in_periodic_mode(data))
- return -EBUSY;
+ if (vcnl3020_is_in_periodic_mode(data)) {
+ rc = -EBUSY;
+ goto err_unlock;
+ }
for (i = 0; i < ARRAY_SIZE(vcnl3020_prox_sampling_frequency); i++) {
if (val == vcnl3020_prox_sampling_frequency[i][0] &&
@@ -249,10 +254,20 @@ static int vcnl3020_write_proxy_samp_freq(struct vcnl3020_data *data, int val,
}
}
- if (index < 0)
- return -EINVAL;
+ if (index < 0) {
+ rc = -EINVAL;
+ goto err_unlock;
+ }
- return regmap_write(data->regmap, VCNL_PROXIMITY_RATE, index);
+ rc = regmap_write(data->regmap, VCNL_PROXIMITY_RATE, index);
+ if (rc)
+ dev_err(data->dev,
+ "Error (%d) writing proximity rate register\n", rc);
+
+err_unlock:
+ mutex_unlock(&data->lock);
+
+ return rc;
}
static bool vcnl3020_is_thr_enabled(struct vcnl3020_data *data)
@@ -513,17 +528,11 @@ static int vcnl3020_write_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int val, int val2, long mask)
{
- int rc;
struct vcnl3020_data *data = iio_priv(indio_dev);
switch (mask) {
case IIO_CHAN_INFO_SAMP_FREQ:
- rc = iio_device_claim_direct_mode(indio_dev);
- if (rc)
- return rc;
- rc = vcnl3020_write_proxy_samp_freq(data, val, val2);
- iio_device_release_direct_mode(indio_dev);
- return rc;
+ return vcnl3020_write_proxy_samp_freq(data, val, val2);
default:
return -EINVAL;
}