diff options
author | Guenter Roeck <linux@roeck-us.net> | 2012-02-22 11:56:43 -0500 |
---|---|---|
committer | Guenter Roeck <guenter.roeck@ericsson.com> | 2012-03-18 21:27:45 -0400 |
commit | 8b313ca7f1b98263ce22519b25a9c2a362eeb898 (patch) | |
tree | 36c4e576662996be3fcac1f34d339dcd53e569e3 /drivers/hwmon | |
parent | 07404aab52f5106ec436692474cf8f40978f5dac (diff) |
hwmon: (pmbus) Convert pmbus drivers to use devm_kzalloc
Marginally less code and eliminate the possibility of memory leaks.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/pmbus/adm1275.c | 16 | ||||
-rw-r--r-- | drivers/hwmon/pmbus/lm25066.c | 26 | ||||
-rw-r--r-- | drivers/hwmon/pmbus/ltc2978.c | 30 | ||||
-rw-r--r-- | drivers/hwmon/pmbus/pmbus.c | 17 | ||||
-rw-r--r-- | drivers/hwmon/pmbus/pmbus_core.c | 54 | ||||
-rw-r--r-- | drivers/hwmon/pmbus/ucd9000.c | 26 | ||||
-rw-r--r-- | drivers/hwmon/pmbus/ucd9200.c | 22 | ||||
-rw-r--r-- | drivers/hwmon/pmbus/zl6100.c | 19 |
8 files changed, 56 insertions, 154 deletions
diff --git a/drivers/hwmon/pmbus/adm1275.c b/drivers/hwmon/pmbus/adm1275.c index fe52c3cf87ba..f81cb4adaeba 100644 --- a/drivers/hwmon/pmbus/adm1275.c +++ b/drivers/hwmon/pmbus/adm1275.c | |||
@@ -229,7 +229,8 @@ static int adm1275_probe(struct i2c_client *client, | |||
229 | if (device_config < 0) | 229 | if (device_config < 0) |
230 | return device_config; | 230 | return device_config; |
231 | 231 | ||
232 | data = kzalloc(sizeof(struct adm1275_data), GFP_KERNEL); | 232 | data = devm_kzalloc(&client->dev, sizeof(struct adm1275_data), |
233 | GFP_KERNEL); | ||
233 | if (!data) | 234 | if (!data) |
234 | return -ENOMEM; | 235 | return -ENOMEM; |
235 | 236 | ||
@@ -297,23 +298,12 @@ static int adm1275_probe(struct i2c_client *client, | |||
297 | break; | 298 | break; |
298 | } | 299 | } |
299 | 300 | ||
300 | ret = pmbus_do_probe(client, id, info); | 301 | return pmbus_do_probe(client, id, info); |
301 | if (ret) | ||
302 | goto err_mem; | ||
303 | return 0; | ||
304 | |||
305 | err_mem: | ||
306 | kfree(data); | ||
307 | return ret; | ||
308 | } | 302 | } |
309 | 303 | ||
310 | static int adm1275_remove(struct i2c_client *client) | 304 | static int adm1275_remove(struct i2c_client *client) |
311 | { | 305 | { |
312 | const struct pmbus_driver_info *info = pmbus_get_driver_info(client); | ||
313 | const struct adm1275_data *data = to_adm1275_data(info); | ||
314 | |||
315 | pmbus_do_remove(client); | 306 | pmbus_do_remove(client); |
316 | kfree(data); | ||
317 | return 0; | 307 | return 0; |
318 | } | 308 | } |
319 | 309 | ||
diff --git a/drivers/hwmon/pmbus/lm25066.c b/drivers/hwmon/pmbus/lm25066.c index 86ac15ade6ab..e70d4ca14fbe 100644 --- a/drivers/hwmon/pmbus/lm25066.c +++ b/drivers/hwmon/pmbus/lm25066.c | |||
@@ -176,7 +176,6 @@ static int lm25066_probe(struct i2c_client *client, | |||
176 | const struct i2c_device_id *id) | 176 | const struct i2c_device_id *id) |
177 | { | 177 | { |
178 | int config; | 178 | int config; |
179 | int ret; | ||
180 | struct lm25066_data *data; | 179 | struct lm25066_data *data; |
181 | struct pmbus_driver_info *info; | 180 | struct pmbus_driver_info *info; |
182 | 181 | ||
@@ -184,15 +183,14 @@ static int lm25066_probe(struct i2c_client *client, | |||
184 | I2C_FUNC_SMBUS_READ_BYTE_DATA)) | 183 | I2C_FUNC_SMBUS_READ_BYTE_DATA)) |
185 | return -ENODEV; | 184 | return -ENODEV; |
186 | 185 | ||
187 | data = kzalloc(sizeof(struct lm25066_data), GFP_KERNEL); | 186 | data = devm_kzalloc(&client->dev, sizeof(struct lm25066_data), |
187 | GFP_KERNEL); | ||
188 | if (!data) | 188 | if (!data) |
189 | return -ENOMEM; | 189 | return -ENOMEM; |
190 | 190 | ||
191 | config = i2c_smbus_read_byte_data(client, LM25066_DEVICE_SETUP); | 191 | config = i2c_smbus_read_byte_data(client, LM25066_DEVICE_SETUP); |
192 | if (config < 0) { | 192 | if (config < 0) |
193 | ret = config; | 193 | return config; |
194 | goto err_mem; | ||
195 | } | ||
196 | 194 | ||
197 | data->id = id->driver_data; | 195 | data->id = id->driver_data; |
198 | info = &data->info; | 196 | info = &data->info; |
@@ -291,27 +289,15 @@ static int lm25066_probe(struct i2c_client *client, | |||
291 | } | 289 | } |
292 | break; | 290 | break; |
293 | default: | 291 | default: |
294 | ret = -ENODEV; | 292 | return -ENODEV; |
295 | goto err_mem; | ||
296 | } | 293 | } |
297 | 294 | ||
298 | ret = pmbus_do_probe(client, id, info); | 295 | return pmbus_do_probe(client, id, info); |
299 | if (ret) | ||
300 | goto err_mem; | ||
301 | return 0; | ||
302 | |||
303 | err_mem: | ||
304 | kfree(data); | ||
305 | return ret; | ||
306 | } | 296 | } |
307 | 297 | ||
308 | static int lm25066_remove(struct i2c_client *client) | 298 | static int lm25066_remove(struct i2c_client *client) |
309 | { | 299 | { |
310 | const struct pmbus_driver_info *info = pmbus_get_driver_info(client); | ||
311 | const struct lm25066_data *data = to_lm25066_data(info); | ||
312 | |||
313 | pmbus_do_remove(client); | 300 | pmbus_do_remove(client); |
314 | kfree(data); | ||
315 | return 0; | 301 | return 0; |
316 | } | 302 | } |
317 | 303 | ||
diff --git a/drivers/hwmon/pmbus/ltc2978.c b/drivers/hwmon/pmbus/ltc2978.c index c9e4dd20bf9c..5e07a363b3e9 100644 --- a/drivers/hwmon/pmbus/ltc2978.c +++ b/drivers/hwmon/pmbus/ltc2978.c | |||
@@ -287,7 +287,7 @@ MODULE_DEVICE_TABLE(i2c, ltc2978_id); | |||
287 | static int ltc2978_probe(struct i2c_client *client, | 287 | static int ltc2978_probe(struct i2c_client *client, |
288 | const struct i2c_device_id *id) | 288 | const struct i2c_device_id *id) |
289 | { | 289 | { |
290 | int chip_id, ret, i; | 290 | int chip_id, i; |
291 | struct ltc2978_data *data; | 291 | struct ltc2978_data *data; |
292 | struct pmbus_driver_info *info; | 292 | struct pmbus_driver_info *info; |
293 | 293 | ||
@@ -295,15 +295,14 @@ static int ltc2978_probe(struct i2c_client *client, | |||
295 | I2C_FUNC_SMBUS_READ_WORD_DATA)) | 295 | I2C_FUNC_SMBUS_READ_WORD_DATA)) |
296 | return -ENODEV; | 296 | return -ENODEV; |
297 | 297 | ||
298 | data = kzalloc(sizeof(struct ltc2978_data), GFP_KERNEL); | 298 | data = devm_kzalloc(&client->dev, sizeof(struct ltc2978_data), |
299 | GFP_KERNEL); | ||
299 | if (!data) | 300 | if (!data) |
300 | return -ENOMEM; | 301 | return -ENOMEM; |
301 | 302 | ||
302 | chip_id = i2c_smbus_read_word_data(client, LTC2978_MFR_SPECIAL_ID); | 303 | chip_id = i2c_smbus_read_word_data(client, LTC2978_MFR_SPECIAL_ID); |
303 | if (chip_id < 0) { | 304 | if (chip_id < 0) |
304 | ret = chip_id; | 305 | return chip_id; |
305 | goto err_mem; | ||
306 | } | ||
307 | 306 | ||
308 | if (chip_id == LTC2978_ID_REV1 || chip_id == LTC2978_ID_REV2) { | 307 | if (chip_id == LTC2978_ID_REV1 || chip_id == LTC2978_ID_REV2) { |
309 | data->id = ltc2978; | 308 | data->id = ltc2978; |
@@ -311,8 +310,7 @@ static int ltc2978_probe(struct i2c_client *client, | |||
311 | data->id = ltc3880; | 310 | data->id = ltc3880; |
312 | } else { | 311 | } else { |
313 | dev_err(&client->dev, "Unsupported chip ID 0x%x\n", chip_id); | 312 | dev_err(&client->dev, "Unsupported chip ID 0x%x\n", chip_id); |
314 | ret = -ENODEV; | 313 | return -ENODEV; |
315 | goto err_mem; | ||
316 | } | 314 | } |
317 | if (data->id != id->driver_data) | 315 | if (data->id != id->driver_data) |
318 | dev_warn(&client->dev, | 316 | dev_warn(&client->dev, |
@@ -357,27 +355,15 @@ static int ltc2978_probe(struct i2c_client *client, | |||
357 | data->vout_min[1] = 0xffff; | 355 | data->vout_min[1] = 0xffff; |
358 | break; | 356 | break; |
359 | default: | 357 | default: |
360 | ret = -ENODEV; | 358 | return -ENODEV; |
361 | goto err_mem; | ||
362 | } | 359 | } |
363 | 360 | ||
364 | ret = pmbus_do_probe(client, id, info); | 361 | return pmbus_do_probe(client, id, info); |
365 | if (ret) | ||
366 | goto err_mem; | ||
367 | return 0; | ||
368 | |||
369 | err_mem: | ||
370 | kfree(data); | ||
371 | return ret; | ||
372 | } | 362 | } |
373 | 363 | ||
374 | static int ltc2978_remove(struct i2c_client *client) | 364 | static int ltc2978_remove(struct i2c_client *client) |
375 | { | 365 | { |
376 | const struct pmbus_driver_info *info = pmbus_get_driver_info(client); | ||
377 | const struct ltc2978_data *data = to_ltc2978_data(info); | ||
378 | |||
379 | pmbus_do_remove(client); | 366 | pmbus_do_remove(client); |
380 | kfree(data); | ||
381 | return 0; | 367 | return 0; |
382 | } | 368 | } |
383 | 369 | ||
diff --git a/drivers/hwmon/pmbus/pmbus.c b/drivers/hwmon/pmbus/pmbus.c index da5fe361a940..b94bec23d95c 100644 --- a/drivers/hwmon/pmbus/pmbus.c +++ b/drivers/hwmon/pmbus/pmbus.c | |||
@@ -166,32 +166,21 @@ static int pmbus_probe(struct i2c_client *client, | |||
166 | const struct i2c_device_id *id) | 166 | const struct i2c_device_id *id) |
167 | { | 167 | { |
168 | struct pmbus_driver_info *info; | 168 | struct pmbus_driver_info *info; |
169 | int ret; | ||
170 | 169 | ||
171 | info = kzalloc(sizeof(struct pmbus_driver_info), GFP_KERNEL); | 170 | info = devm_kzalloc(&client->dev, sizeof(struct pmbus_driver_info), |
171 | GFP_KERNEL); | ||
172 | if (!info) | 172 | if (!info) |
173 | return -ENOMEM; | 173 | return -ENOMEM; |
174 | 174 | ||
175 | info->pages = id->driver_data; | 175 | info->pages = id->driver_data; |
176 | info->identify = pmbus_identify; | 176 | info->identify = pmbus_identify; |
177 | 177 | ||
178 | ret = pmbus_do_probe(client, id, info); | 178 | return pmbus_do_probe(client, id, info); |
179 | if (ret < 0) | ||
180 | goto out; | ||
181 | return 0; | ||
182 | |||
183 | out: | ||
184 | kfree(info); | ||
185 | return ret; | ||
186 | } | 179 | } |
187 | 180 | ||
188 | static int pmbus_remove(struct i2c_client *client) | 181 | static int pmbus_remove(struct i2c_client *client) |
189 | { | 182 | { |
190 | const struct pmbus_driver_info *info; | ||
191 | |||
192 | info = pmbus_get_driver_info(client); | ||
193 | pmbus_do_remove(client); | 183 | pmbus_do_remove(client); |
194 | kfree(info); | ||
195 | return 0; | 184 | return 0; |
196 | } | 185 | } |
197 | 186 | ||
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index f571388d88fd..26b6542a90cd 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c | |||
@@ -1676,7 +1676,7 @@ int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id, | |||
1676 | | I2C_FUNC_SMBUS_WORD_DATA)) | 1676 | | I2C_FUNC_SMBUS_WORD_DATA)) |
1677 | return -ENODEV; | 1677 | return -ENODEV; |
1678 | 1678 | ||
1679 | data = kzalloc(sizeof(*data), GFP_KERNEL); | 1679 | data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); |
1680 | if (!data) { | 1680 | if (!data) { |
1681 | dev_err(&client->dev, "No memory to allocate driver data\n"); | 1681 | dev_err(&client->dev, "No memory to allocate driver data\n"); |
1682 | return -ENOMEM; | 1682 | return -ENOMEM; |
@@ -1688,8 +1688,7 @@ int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id, | |||
1688 | /* Bail out if PMBus status register does not exist. */ | 1688 | /* Bail out if PMBus status register does not exist. */ |
1689 | if (i2c_smbus_read_byte_data(client, PMBUS_STATUS_BYTE) < 0) { | 1689 | if (i2c_smbus_read_byte_data(client, PMBUS_STATUS_BYTE) < 0) { |
1690 | dev_err(&client->dev, "PMBus status register not found\n"); | 1690 | dev_err(&client->dev, "PMBus status register not found\n"); |
1691 | ret = -ENODEV; | 1691 | return -ENODEV; |
1692 | goto out_data; | ||
1693 | } | 1692 | } |
1694 | 1693 | ||
1695 | if (pdata) | 1694 | if (pdata) |
@@ -1702,50 +1701,49 @@ int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id, | |||
1702 | ret = (*info->identify)(client, info); | 1701 | ret = (*info->identify)(client, info); |
1703 | if (ret < 0) { | 1702 | if (ret < 0) { |
1704 | dev_err(&client->dev, "Chip identification failed\n"); | 1703 | dev_err(&client->dev, "Chip identification failed\n"); |
1705 | goto out_data; | 1704 | return ret; |
1706 | } | 1705 | } |
1707 | } | 1706 | } |
1708 | 1707 | ||
1709 | if (info->pages <= 0 || info->pages > PMBUS_PAGES) { | 1708 | if (info->pages <= 0 || info->pages > PMBUS_PAGES) { |
1710 | dev_err(&client->dev, "Bad number of PMBus pages: %d\n", | 1709 | dev_err(&client->dev, "Bad number of PMBus pages: %d\n", |
1711 | info->pages); | 1710 | info->pages); |
1712 | ret = -ENODEV; | 1711 | return -ENODEV; |
1713 | goto out_data; | ||
1714 | } | 1712 | } |
1715 | 1713 | ||
1716 | ret = pmbus_identify_common(client, data); | 1714 | ret = pmbus_identify_common(client, data); |
1717 | if (ret < 0) { | 1715 | if (ret < 0) { |
1718 | dev_err(&client->dev, "Failed to identify chip capabilities\n"); | 1716 | dev_err(&client->dev, "Failed to identify chip capabilities\n"); |
1719 | goto out_data; | 1717 | return ret; |
1720 | } | 1718 | } |
1721 | 1719 | ||
1722 | ret = -ENOMEM; | 1720 | ret = -ENOMEM; |
1723 | data->sensors = kzalloc(sizeof(struct pmbus_sensor) * data->max_sensors, | 1721 | data->sensors = devm_kzalloc(&client->dev, sizeof(struct pmbus_sensor) |
1724 | GFP_KERNEL); | 1722 | * data->max_sensors, GFP_KERNEL); |
1725 | if (!data->sensors) { | 1723 | if (!data->sensors) { |
1726 | dev_err(&client->dev, "No memory to allocate sensor data\n"); | 1724 | dev_err(&client->dev, "No memory to allocate sensor data\n"); |
1727 | goto out_data; | 1725 | return -ENOMEM; |
1728 | } | 1726 | } |
1729 | 1727 | ||
1730 | data->booleans = kzalloc(sizeof(struct pmbus_boolean) | 1728 | data->booleans = devm_kzalloc(&client->dev, sizeof(struct pmbus_boolean) |
1731 | * data->max_booleans, GFP_KERNEL); | 1729 | * data->max_booleans, GFP_KERNEL); |
1732 | if (!data->booleans) { | 1730 | if (!data->booleans) { |
1733 | dev_err(&client->dev, "No memory to allocate boolean data\n"); | 1731 | dev_err(&client->dev, "No memory to allocate boolean data\n"); |
1734 | goto out_sensors; | 1732 | return -ENOMEM; |
1735 | } | 1733 | } |
1736 | 1734 | ||
1737 | data->labels = kzalloc(sizeof(struct pmbus_label) * data->max_labels, | 1735 | data->labels = devm_kzalloc(&client->dev, sizeof(struct pmbus_label) |
1738 | GFP_KERNEL); | 1736 | * data->max_labels, GFP_KERNEL); |
1739 | if (!data->labels) { | 1737 | if (!data->labels) { |
1740 | dev_err(&client->dev, "No memory to allocate label data\n"); | 1738 | dev_err(&client->dev, "No memory to allocate label data\n"); |
1741 | goto out_booleans; | 1739 | return -ENOMEM; |
1742 | } | 1740 | } |
1743 | 1741 | ||
1744 | data->attributes = kzalloc(sizeof(struct attribute *) | 1742 | data->attributes = devm_kzalloc(&client->dev, sizeof(struct attribute *) |
1745 | * data->max_attributes, GFP_KERNEL); | 1743 | * data->max_attributes, GFP_KERNEL); |
1746 | if (!data->attributes) { | 1744 | if (!data->attributes) { |
1747 | dev_err(&client->dev, "No memory to allocate attribute data\n"); | 1745 | dev_err(&client->dev, "No memory to allocate attribute data\n"); |
1748 | goto out_labels; | 1746 | return -ENOMEM; |
1749 | } | 1747 | } |
1750 | 1748 | ||
1751 | pmbus_find_attributes(client, data); | 1749 | pmbus_find_attributes(client, data); |
@@ -1756,8 +1754,7 @@ int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id, | |||
1756 | */ | 1754 | */ |
1757 | if (!data->num_attributes) { | 1755 | if (!data->num_attributes) { |
1758 | dev_err(&client->dev, "No attributes found\n"); | 1756 | dev_err(&client->dev, "No attributes found\n"); |
1759 | ret = -ENODEV; | 1757 | return -ENODEV; |
1760 | goto out_attributes; | ||
1761 | } | 1758 | } |
1762 | 1759 | ||
1763 | /* Register sysfs hooks */ | 1760 | /* Register sysfs hooks */ |
@@ -1765,7 +1762,7 @@ int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id, | |||
1765 | ret = sysfs_create_group(&client->dev.kobj, &data->group); | 1762 | ret = sysfs_create_group(&client->dev.kobj, &data->group); |
1766 | if (ret) { | 1763 | if (ret) { |
1767 | dev_err(&client->dev, "Failed to create sysfs entries\n"); | 1764 | dev_err(&client->dev, "Failed to create sysfs entries\n"); |
1768 | goto out_attributes; | 1765 | return ret; |
1769 | } | 1766 | } |
1770 | data->hwmon_dev = hwmon_device_register(&client->dev); | 1767 | data->hwmon_dev = hwmon_device_register(&client->dev); |
1771 | if (IS_ERR(data->hwmon_dev)) { | 1768 | if (IS_ERR(data->hwmon_dev)) { |
@@ -1777,16 +1774,6 @@ int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id, | |||
1777 | 1774 | ||
1778 | out_hwmon_device_register: | 1775 | out_hwmon_device_register: |
1779 | sysfs_remove_group(&client->dev.kobj, &data->group); | 1776 | sysfs_remove_group(&client->dev.kobj, &data->group); |
1780 | out_attributes: | ||
1781 | kfree(data->attributes); | ||
1782 | out_labels: | ||
1783 | kfree(data->labels); | ||
1784 | out_booleans: | ||
1785 | kfree(data->booleans); | ||
1786 | out_sensors: | ||
1787 | kfree(data->sensors); | ||
1788 | out_data: | ||
1789 | kfree(data); | ||
1790 | return ret; | 1777 | return ret; |
1791 | } | 1778 | } |
1792 | EXPORT_SYMBOL_GPL(pmbus_do_probe); | 1779 | EXPORT_SYMBOL_GPL(pmbus_do_probe); |
@@ -1796,11 +1783,6 @@ void pmbus_do_remove(struct i2c_client *client) | |||
1796 | struct pmbus_data *data = i2c_get_clientdata(client); | 1783 | struct pmbus_data *data = i2c_get_clientdata(client); |
1797 | hwmon_device_unregister(data->hwmon_dev); | 1784 | hwmon_device_unregister(data->hwmon_dev); |
1798 | sysfs_remove_group(&client->dev.kobj, &data->group); | 1785 | sysfs_remove_group(&client->dev.kobj, &data->group); |
1799 | kfree(data->attributes); | ||
1800 | kfree(data->labels); | ||
1801 | kfree(data->booleans); | ||
1802 | kfree(data->sensors); | ||
1803 | kfree(data); | ||
1804 | } | 1786 | } |
1805 | EXPORT_SYMBOL_GPL(pmbus_do_remove); | 1787 | EXPORT_SYMBOL_GPL(pmbus_do_remove); |
1806 | 1788 | ||
diff --git a/drivers/hwmon/pmbus/ucd9000.c b/drivers/hwmon/pmbus/ucd9000.c index 759a563de636..e0573459447c 100644 --- a/drivers/hwmon/pmbus/ucd9000.c +++ b/drivers/hwmon/pmbus/ucd9000.c | |||
@@ -155,7 +155,8 @@ static int ucd9000_probe(struct i2c_client *client, | |||
155 | "Device mismatch: Configured %s, detected %s\n", | 155 | "Device mismatch: Configured %s, detected %s\n", |
156 | id->name, mid->name); | 156 | id->name, mid->name); |
157 | 157 | ||
158 | data = kzalloc(sizeof(struct ucd9000_data), GFP_KERNEL); | 158 | data = devm_kzalloc(&client->dev, sizeof(struct ucd9000_data), |
159 | GFP_KERNEL); | ||
159 | if (!data) | 160 | if (!data) |
160 | return -ENOMEM; | 161 | return -ENOMEM; |
161 | info = &data->info; | 162 | info = &data->info; |
@@ -164,13 +165,12 @@ static int ucd9000_probe(struct i2c_client *client, | |||
164 | if (ret < 0) { | 165 | if (ret < 0) { |
165 | dev_err(&client->dev, | 166 | dev_err(&client->dev, |
166 | "Failed to read number of active pages\n"); | 167 | "Failed to read number of active pages\n"); |
167 | goto out; | 168 | return ret; |
168 | } | 169 | } |
169 | info->pages = ret; | 170 | info->pages = ret; |
170 | if (!info->pages) { | 171 | if (!info->pages) { |
171 | dev_err(&client->dev, "No pages configured\n"); | 172 | dev_err(&client->dev, "No pages configured\n"); |
172 | ret = -ENODEV; | 173 | return -ENODEV; |
173 | goto out; | ||
174 | } | 174 | } |
175 | 175 | ||
176 | /* The internal temperature sensor is always active */ | 176 | /* The internal temperature sensor is always active */ |
@@ -181,8 +181,7 @@ static int ucd9000_probe(struct i2c_client *client, | |||
181 | block_buffer); | 181 | block_buffer); |
182 | if (ret <= 0) { | 182 | if (ret <= 0) { |
183 | dev_err(&client->dev, "Failed to read configuration data\n"); | 183 | dev_err(&client->dev, "Failed to read configuration data\n"); |
184 | ret = -ENODEV; | 184 | return -ENODEV; |
185 | goto out; | ||
186 | } | 185 | } |
187 | for (i = 0; i < ret; i++) { | 186 | for (i = 0; i < ret; i++) { |
188 | int page = UCD9000_MON_PAGE(block_buffer[i]); | 187 | int page = UCD9000_MON_PAGE(block_buffer[i]); |
@@ -218,7 +217,7 @@ static int ucd9000_probe(struct i2c_client *client, | |||
218 | UCD9000_FAN_CONFIG, | 217 | UCD9000_FAN_CONFIG, |
219 | data->fan_data[i]); | 218 | data->fan_data[i]); |
220 | if (ret < 0) | 219 | if (ret < 0) |
221 | goto out; | 220 | return ret; |
222 | } | 221 | } |
223 | i2c_smbus_write_byte_data(client, UCD9000_FAN_CONFIG_INDEX, 0); | 222 | i2c_smbus_write_byte_data(client, UCD9000_FAN_CONFIG_INDEX, 0); |
224 | 223 | ||
@@ -227,23 +226,12 @@ static int ucd9000_probe(struct i2c_client *client, | |||
227 | | PMBUS_HAVE_FAN34 | PMBUS_HAVE_STATUS_FAN34; | 226 | | PMBUS_HAVE_FAN34 | PMBUS_HAVE_STATUS_FAN34; |
228 | } | 227 | } |
229 | 228 | ||
230 | ret = pmbus_do_probe(client, mid, info); | 229 | return pmbus_do_probe(client, mid, info); |
231 | if (ret < 0) | ||
232 | goto out; | ||
233 | return 0; | ||
234 | |||
235 | out: | ||
236 | kfree(data); | ||
237 | return ret; | ||
238 | } | 230 | } |
239 | 231 | ||
240 | static int ucd9000_remove(struct i2c_client *client) | 232 | static int ucd9000_remove(struct i2c_client *client) |
241 | { | 233 | { |
242 | struct ucd9000_data *data; | ||
243 | |||
244 | data = to_ucd9000_data(pmbus_get_driver_info(client)); | ||
245 | pmbus_do_remove(client); | 234 | pmbus_do_remove(client); |
246 | kfree(data); | ||
247 | return 0; | 235 | return 0; |
248 | } | 236 | } |
249 | 237 | ||
diff --git a/drivers/hwmon/pmbus/ucd9200.c b/drivers/hwmon/pmbus/ucd9200.c index 629d0c93cac6..c0d41b993a53 100644 --- a/drivers/hwmon/pmbus/ucd9200.c +++ b/drivers/hwmon/pmbus/ucd9200.c | |||
@@ -81,7 +81,8 @@ static int ucd9200_probe(struct i2c_client *client, | |||
81 | "Device mismatch: Configured %s, detected %s\n", | 81 | "Device mismatch: Configured %s, detected %s\n", |
82 | id->name, mid->name); | 82 | id->name, mid->name); |
83 | 83 | ||
84 | info = kzalloc(sizeof(struct pmbus_driver_info), GFP_KERNEL); | 84 | info = devm_kzalloc(&client->dev, sizeof(struct pmbus_driver_info), |
85 | GFP_KERNEL); | ||
85 | if (!info) | 86 | if (!info) |
86 | return -ENOMEM; | 87 | return -ENOMEM; |
87 | 88 | ||
@@ -89,7 +90,7 @@ static int ucd9200_probe(struct i2c_client *client, | |||
89 | block_buffer); | 90 | block_buffer); |
90 | if (ret < 0) { | 91 | if (ret < 0) { |
91 | dev_err(&client->dev, "Failed to read phase information\n"); | 92 | dev_err(&client->dev, "Failed to read phase information\n"); |
92 | goto out; | 93 | return ret; |
93 | } | 94 | } |
94 | 95 | ||
95 | /* | 96 | /* |
@@ -106,8 +107,7 @@ static int ucd9200_probe(struct i2c_client *client, | |||
106 | } | 107 | } |
107 | if (!info->pages) { | 108 | if (!info->pages) { |
108 | dev_err(&client->dev, "No rails configured\n"); | 109 | dev_err(&client->dev, "No rails configured\n"); |
109 | ret = -ENODEV; | 110 | return -ENODEV; |
110 | goto out; | ||
111 | } | 111 | } |
112 | dev_info(&client->dev, "%d rails configured\n", info->pages); | 112 | dev_info(&client->dev, "%d rails configured\n", info->pages); |
113 | 113 | ||
@@ -137,7 +137,7 @@ static int ucd9200_probe(struct i2c_client *client, | |||
137 | if (ret < 0) { | 137 | if (ret < 0) { |
138 | dev_err(&client->dev, | 138 | dev_err(&client->dev, |
139 | "Failed to initialize PHASE registers\n"); | 139 | "Failed to initialize PHASE registers\n"); |
140 | goto out; | 140 | return ret; |
141 | } | 141 | } |
142 | } | 142 | } |
143 | if (info->pages > 1) | 143 | if (info->pages > 1) |
@@ -160,22 +160,12 @@ static int ucd9200_probe(struct i2c_client *client, | |||
160 | if (mid->driver_data == ucd9240) | 160 | if (mid->driver_data == ucd9240) |
161 | info->func[0] |= PMBUS_HAVE_FAN12 | PMBUS_HAVE_STATUS_FAN12; | 161 | info->func[0] |= PMBUS_HAVE_FAN12 | PMBUS_HAVE_STATUS_FAN12; |
162 | 162 | ||
163 | ret = pmbus_do_probe(client, mid, info); | 163 | return pmbus_do_probe(client, mid, info); |
164 | if (ret < 0) | ||
165 | goto out; | ||
166 | return 0; | ||
167 | out: | ||
168 | kfree(info); | ||
169 | return ret; | ||
170 | } | 164 | } |
171 | 165 | ||
172 | static int ucd9200_remove(struct i2c_client *client) | 166 | static int ucd9200_remove(struct i2c_client *client) |
173 | { | 167 | { |
174 | const struct pmbus_driver_info *info; | ||
175 | |||
176 | info = pmbus_get_driver_info(client); | ||
177 | pmbus_do_remove(client); | 168 | pmbus_do_remove(client); |
178 | kfree(info); | ||
179 | return 0; | 169 | return 0; |
180 | } | 170 | } |
181 | 171 | ||
diff --git a/drivers/hwmon/pmbus/zl6100.c b/drivers/hwmon/pmbus/zl6100.c index 8ae658118bec..9d3b84535e73 100644 --- a/drivers/hwmon/pmbus/zl6100.c +++ b/drivers/hwmon/pmbus/zl6100.c | |||
@@ -193,7 +193,8 @@ static int zl6100_probe(struct i2c_client *client, | |||
193 | "Device mismatch: Configured %s, detected %s\n", | 193 | "Device mismatch: Configured %s, detected %s\n", |
194 | id->name, mid->name); | 194 | id->name, mid->name); |
195 | 195 | ||
196 | data = kzalloc(sizeof(struct zl6100_data), GFP_KERNEL); | 196 | data = devm_kzalloc(&client->dev, sizeof(struct zl6100_data), |
197 | GFP_KERNEL); | ||
197 | if (!data) | 198 | if (!data) |
198 | return -ENOMEM; | 199 | return -ENOMEM; |
199 | 200 | ||
@@ -223,7 +224,8 @@ static int zl6100_probe(struct i2c_client *client, | |||
223 | 224 | ||
224 | ret = i2c_smbus_read_word_data(client, ZL6100_MFR_CONFIG); | 225 | ret = i2c_smbus_read_word_data(client, ZL6100_MFR_CONFIG); |
225 | if (ret < 0) | 226 | if (ret < 0) |
226 | goto err_mem; | 227 | return ret; |
228 | |||
227 | if (ret & ZL6100_MFR_XTEMP_ENABLE) | 229 | if (ret & ZL6100_MFR_XTEMP_ENABLE) |
228 | info->func[0] |= PMBUS_HAVE_TEMP2; | 230 | info->func[0] |= PMBUS_HAVE_TEMP2; |
229 | 231 | ||
@@ -235,23 +237,12 @@ static int zl6100_probe(struct i2c_client *client, | |||
235 | info->write_word_data = zl6100_write_word_data; | 237 | info->write_word_data = zl6100_write_word_data; |
236 | info->write_byte = zl6100_write_byte; | 238 | info->write_byte = zl6100_write_byte; |
237 | 239 | ||
238 | ret = pmbus_do_probe(client, mid, info); | 240 | return pmbus_do_probe(client, mid, info); |
239 | if (ret) | ||
240 | goto err_mem; | ||
241 | return 0; | ||
242 | |||
243 | err_mem: | ||
244 | kfree(data); | ||
245 | return ret; | ||
246 | } | 241 | } |
247 | 242 | ||
248 | static int zl6100_remove(struct i2c_client *client) | 243 | static int zl6100_remove(struct i2c_client *client) |
249 | { | 244 | { |
250 | const struct pmbus_driver_info *info = pmbus_get_driver_info(client); | ||
251 | const struct zl6100_data *data = to_zl6100_data(info); | ||
252 | |||
253 | pmbus_do_remove(client); | 245 | pmbus_do_remove(client); |
254 | kfree(data); | ||
255 | return 0; | 246 | return 0; |
256 | } | 247 | } |
257 | 248 | ||