Commit a406721d authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging

* 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging:
  hwmon: (max1111) Fix race condition causing NULL pointer exception
  hwmon: (it87) Fix label group removal
  hwmon: (asus_atk0110) Fix memory leak
parents f560f669 d3f684f2
...@@ -674,6 +674,7 @@ static int atk_debugfs_gitm_get(void *p, u64 *val) ...@@ -674,6 +674,7 @@ static int atk_debugfs_gitm_get(void *p, u64 *val)
else else
err = -EIO; err = -EIO;
ACPI_FREE(ret);
return err; return err;
} }
......
...@@ -1538,7 +1538,7 @@ static struct attribute *it87_attributes_label[] = { ...@@ -1538,7 +1538,7 @@ static struct attribute *it87_attributes_label[] = {
}; };
static const struct attribute_group it87_group_label = { static const struct attribute_group it87_group_label = {
.attrs = it87_attributes_vid, .attrs = it87_attributes_label,
}; };
/* SuperIO detection - will change isa_address if a chip is found */ /* SuperIO detection - will change isa_address if a chip is found */
......
...@@ -40,6 +40,8 @@ struct max1111_data { ...@@ -40,6 +40,8 @@ struct max1111_data {
struct spi_transfer xfer[2]; struct spi_transfer xfer[2];
uint8_t *tx_buf; uint8_t *tx_buf;
uint8_t *rx_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) static int max1111_read(struct device *dev, int channel)
...@@ -48,6 +50,9 @@ static int max1111_read(struct device *dev, int channel) ...@@ -48,6 +50,9 @@ static int max1111_read(struct device *dev, int channel)
uint8_t v1, v2; uint8_t v1, v2;
int err; 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) | data->tx_buf[0] = (channel << MAX1111_CTRL_SEL_SH) |
MAX1111_CTRL_PD0 | MAX1111_CTRL_PD1 | MAX1111_CTRL_PD0 | MAX1111_CTRL_PD1 |
MAX1111_CTRL_SGL | MAX1111_CTRL_UNI | MAX1111_CTRL_STR; MAX1111_CTRL_SGL | MAX1111_CTRL_UNI | MAX1111_CTRL_STR;
...@@ -55,12 +60,15 @@ static int max1111_read(struct device *dev, int channel) ...@@ -55,12 +60,15 @@ static int max1111_read(struct device *dev, int channel)
err = spi_sync(data->spi, &data->msg); err = spi_sync(data->spi, &data->msg);
if (err < 0) { if (err < 0) {
dev_err(dev, "spi_sync failed with %d\n", err); dev_err(dev, "spi_sync failed with %d\n", err);
mutex_unlock(&data->drvdata_lock);
return err; return err;
} }
v1 = data->rx_buf[0]; v1 = data->rx_buf[0];
v2 = data->rx_buf[1]; v2 = data->rx_buf[1];
mutex_unlock(&data->drvdata_lock);
if ((v1 & 0xc0) || (v2 & 0x3f)) if ((v1 & 0xc0) || (v2 & 0x3f))
return -EINVAL; return -EINVAL;
...@@ -176,6 +184,8 @@ static int __devinit max1111_probe(struct spi_device *spi) ...@@ -176,6 +184,8 @@ static int __devinit max1111_probe(struct spi_device *spi)
if (err) if (err)
goto err_free_data; goto err_free_data;
mutex_init(&data->drvdata_lock);
data->spi = spi; data->spi = spi;
spi_set_drvdata(spi, data); spi_set_drvdata(spi, data);
...@@ -213,6 +223,7 @@ static int __devexit max1111_remove(struct spi_device *spi) ...@@ -213,6 +223,7 @@ static int __devexit max1111_remove(struct spi_device *spi)
hwmon_device_unregister(data->hwmon_dev); hwmon_device_unregister(data->hwmon_dev);
sysfs_remove_group(&spi->dev.kobj, &max1111_attr_group); sysfs_remove_group(&spi->dev.kobj, &max1111_attr_group);
mutex_destroy(&data->drvdata_lock);
kfree(data->rx_buf); kfree(data->rx_buf);
kfree(data->tx_buf); kfree(data->tx_buf);
kfree(data); kfree(data);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment