Skip to content

Commit

Permalink
driver_si7210: add missing locks and synchronization
Browse files Browse the repository at this point in the history
  • Loading branch information
panantoni01 committed Jul 7, 2024
1 parent 91f3c0b commit 272d0e2
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions driver_si7210/si7210_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <linux/iio/iio.h>
#include <linux/regmap.h>
#include <linux/math64.h>
#include <linux/mutex.h>

#define SI7210_REG_DSPSIGM 0xC1
#define SI7210_REG_DSPSIGL 0xC2
Expand Down Expand Up @@ -76,6 +77,8 @@ struct si7210_data {
struct regmap *regmap;
u8 temp_offset;
u8 temp_gain;
struct mutex fetch_lock;
struct mutex otp_lock;
};

static const struct iio_chan_spec si7210_channels[] = {
Expand All @@ -102,6 +105,8 @@ static int si7210_fetch_measurement(struct si7210_data* data,
else /* IIO_TEMP */
dspsigsel = 1;

mutex_lock(&data->fetch_lock);

ret = regmap_update_bits(data->regmap, SI7210_REG_DSPSIGSEL,
SI7210_MASK_DSPSIGSEL, dspsigsel);
if (ret < 0)
Expand All @@ -123,6 +128,8 @@ static int si7210_fetch_measurement(struct si7210_data* data,
if (ret < 0)
return ret;

mutex_unlock(&data->fetch_lock);

return 0;
}

Expand Down Expand Up @@ -178,6 +185,8 @@ static int si7210_read_otpreg_val(struct si7210_data *data, unsigned int otpreg,
{
int ret;

mutex_lock(&data->otp_lock);

ret = regmap_write(data->regmap, SI7210_REG_OTP_ADDR, otpreg);
if (ret < 0)
return ret;
Expand All @@ -191,6 +200,8 @@ static int si7210_read_otpreg_val(struct si7210_data *data, unsigned int otpreg,
if (ret < 0)
return ret;

mutex_unlock(&data->otp_lock);

return 0;
}

Expand Down Expand Up @@ -249,6 +260,9 @@ static int si7210_probe(struct i2c_client *client,
i2c_set_clientdata(client, indio_dev);
data->client = client;

mutex_init(&data->fetch_lock);
mutex_init(&data->otp_lock);

data->regmap = devm_regmap_init_i2c(client, &si7210_regmap_conf);
if (IS_ERR(data->regmap))
return dev_err_probe(&client->dev, PTR_ERR(data->regmap),
Expand Down

0 comments on commit 272d0e2

Please sign in to comment.