Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Axel Lin <axel.lin@gmail.com>
Cc: stable@kernel.org
Signed-off-by: Jean Delvare <khali@linux-fr.org>

authored by

Axel Lin and committed by
Jean Delvare
c12c507d 45ff34d3

+19 -19
+19 -19
drivers/hwmon/ads7871.c
··· 160 160 161 161 static int __devinit ads7871_probe(struct spi_device *spi) 162 162 { 163 - int status, ret, err = 0; 163 + int ret, err; 164 164 uint8_t val; 165 165 struct ads7871_data *pdata; 166 166 167 167 dev_dbg(&spi->dev, "probe\n"); 168 - 169 - pdata = kzalloc(sizeof(struct ads7871_data), GFP_KERNEL); 170 - if (!pdata) { 171 - err = -ENOMEM; 172 - goto exit; 173 - } 174 - 175 - status = sysfs_create_group(&spi->dev.kobj, &ads7871_group); 176 - if (status < 0) 177 - goto error_free; 178 - 179 - pdata->hwmon_dev = hwmon_device_register(&spi->dev); 180 - if (IS_ERR(pdata->hwmon_dev)) { 181 - err = PTR_ERR(pdata->hwmon_dev); 182 - goto error_remove; 183 - } 184 - 185 - spi_set_drvdata(spi, pdata); 186 168 187 169 /* Configure the SPI bus */ 188 170 spi->mode = (SPI_MODE_0); ··· 183 201 we need to make sure we really have a chip*/ 184 202 if (val != ret) { 185 203 err = -ENODEV; 204 + goto exit; 205 + } 206 + 207 + pdata = kzalloc(sizeof(struct ads7871_data), GFP_KERNEL); 208 + if (!pdata) { 209 + err = -ENOMEM; 210 + goto exit; 211 + } 212 + 213 + err = sysfs_create_group(&spi->dev.kobj, &ads7871_group); 214 + if (err < 0) 215 + goto error_free; 216 + 217 + spi_set_drvdata(spi, pdata); 218 + 219 + pdata->hwmon_dev = hwmon_device_register(&spi->dev); 220 + if (IS_ERR(pdata->hwmon_dev)) { 221 + err = PTR_ERR(pdata->hwmon_dev); 186 222 goto error_remove; 187 223 } 188 224