Commit c12c507d authored by Axel Lin's avatar Axel Lin Committed by Jean Delvare

hwmon: (ads7871) Fix ads7871_probe error paths

1. remove 'status' variable
2. remove unneeded initialization of 'err' variable
3. return missing error code if sysfs_create_group fail.
4. fix the init sequence as:
   - check hardware existence
   - kzalloc for ads7871_data
   - sysfs_create_group
   - hwmon_device_register
Signed-off-by: default avatarAxel Lin <axel.lin@gmail.com>
Cc: stable@kernel.org
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
parent 45ff34d3
...@@ -160,30 +160,12 @@ static const struct attribute_group ads7871_group = { ...@@ -160,30 +160,12 @@ static const struct attribute_group ads7871_group = {
static int __devinit ads7871_probe(struct spi_device *spi) static int __devinit ads7871_probe(struct spi_device *spi)
{ {
int status, ret, err = 0; int ret, err;
uint8_t val; uint8_t val;
struct ads7871_data *pdata; struct ads7871_data *pdata;
dev_dbg(&spi->dev, "probe\n"); dev_dbg(&spi->dev, "probe\n");
pdata = kzalloc(sizeof(struct ads7871_data), GFP_KERNEL);
if (!pdata) {
err = -ENOMEM;
goto exit;
}
status = sysfs_create_group(&spi->dev.kobj, &ads7871_group);
if (status < 0)
goto error_free;
pdata->hwmon_dev = hwmon_device_register(&spi->dev);
if (IS_ERR(pdata->hwmon_dev)) {
err = PTR_ERR(pdata->hwmon_dev);
goto error_remove;
}
spi_set_drvdata(spi, pdata);
/* Configure the SPI bus */ /* Configure the SPI bus */
spi->mode = (SPI_MODE_0); spi->mode = (SPI_MODE_0);
spi->bits_per_word = 8; spi->bits_per_word = 8;
...@@ -201,6 +183,24 @@ static int __devinit ads7871_probe(struct spi_device *spi) ...@@ -201,6 +183,24 @@ static int __devinit ads7871_probe(struct spi_device *spi)
we need to make sure we really have a chip*/ we need to make sure we really have a chip*/
if (val != ret) { if (val != ret) {
err = -ENODEV; err = -ENODEV;
goto exit;
}
pdata = kzalloc(sizeof(struct ads7871_data), GFP_KERNEL);
if (!pdata) {
err = -ENOMEM;
goto exit;
}
err = sysfs_create_group(&spi->dev.kobj, &ads7871_group);
if (err < 0)
goto error_free;
spi_set_drvdata(spi, pdata);
pdata->hwmon_dev = hwmon_device_register(&spi->dev);
if (IS_ERR(pdata->hwmon_dev)) {
err = PTR_ERR(pdata->hwmon_dev);
goto error_remove; goto error_remove;
} }
......
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