Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 254978
b: refs/heads/master
c: d3f684f
h: refs/heads/master
v: v3
  • Loading branch information
Pavel Herrmann authored and Jean Delvare committed Jul 17, 2011
1 parent 0ccdcbb commit 31bdae2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: fa8b69758e65b406c8010936b541cd00deef804d
refs/heads/master: d3f684f2820a7f42acef68bea6622d9032127fb2
11 changes: 11 additions & 0 deletions trunk/drivers/hwmon/max1111.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ struct max1111_data {
struct spi_transfer xfer[2];
uint8_t *tx_buf;
uint8_t *rx_buf;
struct mutex drvdata_lock;
/* protect msg, xfer and buffers from multiple access */
};

static int max1111_read(struct device *dev, int channel)
Expand All @@ -48,19 +50,25 @@ static int max1111_read(struct device *dev, int channel)
uint8_t v1, v2;
int err;

/* writing to drvdata struct is not thread safe, wait on mutex */
mutex_lock(&data->drvdata_lock);

data->tx_buf[0] = (channel << MAX1111_CTRL_SEL_SH) |
MAX1111_CTRL_PD0 | MAX1111_CTRL_PD1 |
MAX1111_CTRL_SGL | MAX1111_CTRL_UNI | MAX1111_CTRL_STR;

err = spi_sync(data->spi, &data->msg);
if (err < 0) {
dev_err(dev, "spi_sync failed with %d\n", err);
mutex_unlock(&data->drvdata_lock);
return err;
}

v1 = data->rx_buf[0];
v2 = data->rx_buf[1];

mutex_unlock(&data->drvdata_lock);

if ((v1 & 0xc0) || (v2 & 0x3f))
return -EINVAL;

Expand Down Expand Up @@ -176,6 +184,8 @@ static int __devinit max1111_probe(struct spi_device *spi)
if (err)
goto err_free_data;

mutex_init(&data->drvdata_lock);

data->spi = spi;
spi_set_drvdata(spi, data);

Expand Down Expand Up @@ -213,6 +223,7 @@ static int __devexit max1111_remove(struct spi_device *spi)

hwmon_device_unregister(data->hwmon_dev);
sysfs_remove_group(&spi->dev.kobj, &max1111_attr_group);
mutex_destroy(&data->drvdata_lock);
kfree(data->rx_buf);
kfree(data->tx_buf);
kfree(data);
Expand Down

0 comments on commit 31bdae2

Please sign in to comment.