mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-18 02:04:05 +08:00
iio: light: vcnl4000: Add missing locking
Signed-off-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
This commit is contained in:
parent
5d6931393f
commit
ff34ed6d78
@ -48,6 +48,7 @@
|
|||||||
|
|
||||||
struct vcnl4000_data {
|
struct vcnl4000_data {
|
||||||
struct i2c_client *client;
|
struct i2c_client *client;
|
||||||
|
struct mutex lock;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct i2c_device_id vcnl4000_id[] = {
|
static const struct i2c_device_id vcnl4000_id[] = {
|
||||||
@ -63,16 +64,18 @@ static int vcnl4000_measure(struct vcnl4000_data *data, u8 req_mask,
|
|||||||
__be16 buf;
|
__be16 buf;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
mutex_lock(&data->lock);
|
||||||
|
|
||||||
ret = i2c_smbus_write_byte_data(data->client, VCNL4000_COMMAND,
|
ret = i2c_smbus_write_byte_data(data->client, VCNL4000_COMMAND,
|
||||||
req_mask);
|
req_mask);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
goto fail;
|
||||||
|
|
||||||
/* wait for data to become ready */
|
/* wait for data to become ready */
|
||||||
while (tries--) {
|
while (tries--) {
|
||||||
ret = i2c_smbus_read_byte_data(data->client, VCNL4000_COMMAND);
|
ret = i2c_smbus_read_byte_data(data->client, VCNL4000_COMMAND);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
goto fail;
|
||||||
if (ret & rdy_mask)
|
if (ret & rdy_mask)
|
||||||
break;
|
break;
|
||||||
msleep(20); /* measurement takes up to 100 ms */
|
msleep(20); /* measurement takes up to 100 ms */
|
||||||
@ -81,17 +84,23 @@ static int vcnl4000_measure(struct vcnl4000_data *data, u8 req_mask,
|
|||||||
if (tries < 0) {
|
if (tries < 0) {
|
||||||
dev_err(&data->client->dev,
|
dev_err(&data->client->dev,
|
||||||
"vcnl4000_measure() failed, data not ready\n");
|
"vcnl4000_measure() failed, data not ready\n");
|
||||||
return -EIO;
|
ret = -EIO;
|
||||||
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = i2c_smbus_read_i2c_block_data(data->client,
|
ret = i2c_smbus_read_i2c_block_data(data->client,
|
||||||
data_reg, sizeof(buf), (u8 *) &buf);
|
data_reg, sizeof(buf), (u8 *) &buf);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
goto fail;
|
||||||
|
|
||||||
|
mutex_unlock(&data->lock);
|
||||||
*val = be16_to_cpu(buf);
|
*val = be16_to_cpu(buf);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
mutex_unlock(&data->lock);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct iio_chan_spec vcnl4000_channels[] = {
|
static const struct iio_chan_spec vcnl4000_channels[] = {
|
||||||
@ -163,6 +172,7 @@ static int vcnl4000_probe(struct i2c_client *client,
|
|||||||
data = iio_priv(indio_dev);
|
data = iio_priv(indio_dev);
|
||||||
i2c_set_clientdata(client, indio_dev);
|
i2c_set_clientdata(client, indio_dev);
|
||||||
data->client = client;
|
data->client = client;
|
||||||
|
mutex_init(&data->lock);
|
||||||
|
|
||||||
ret = i2c_smbus_read_byte_data(data->client, VCNL4000_PROD_REV);
|
ret = i2c_smbus_read_byte_data(data->client, VCNL4000_PROD_REV);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user