Skip to content

Commit

Permalink
Merge branch 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
Linus Torvalds committed Jul 18, 2011
2 parents f560f66 + d3f684f commit a406721
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions drivers/hwmon/asus_atk0110.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ static int atk_debugfs_gitm_get(void *p, u64 *val)
else
err = -EIO;

ACPI_FREE(ret);
return err;
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/hwmon/it87.c
Original file line number Diff line number Diff line change
Expand Up @@ -1538,7 +1538,7 @@ static struct attribute *it87_attributes_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 */
Expand Down
11 changes: 11 additions & 0 deletions 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 a406721

Please sign in to comment.