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>
diff --git a/drivers/hwmon/pmbus/ucd9200.c b/drivers/hwmon/pmbus/ucd9200.c
index 629d0c9..c0d41b9 100644
--- a/drivers/hwmon/pmbus/ucd9200.c
+++ b/drivers/hwmon/pmbus/ucd9200.c
@@ -81,7 +81,8 @@
"Device mismatch: Configured %s, detected %s\n",
id->name, mid->name);
- info = kzalloc(sizeof(struct pmbus_driver_info), GFP_KERNEL);
+ info = devm_kzalloc(&client->dev, sizeof(struct pmbus_driver_info),
+ GFP_KERNEL);
if (!info)
return -ENOMEM;
@@ -89,7 +90,7 @@
block_buffer);
if (ret < 0) {
dev_err(&client->dev, "Failed to read phase information\n");
- goto out;
+ return ret;
}
/*
@@ -106,8 +107,7 @@
}
if (!info->pages) {
dev_err(&client->dev, "No rails configured\n");
- ret = -ENODEV;
- goto out;
+ return -ENODEV;
}
dev_info(&client->dev, "%d rails configured\n", info->pages);
@@ -137,7 +137,7 @@
if (ret < 0) {
dev_err(&client->dev,
"Failed to initialize PHASE registers\n");
- goto out;
+ return ret;
}
}
if (info->pages > 1)
@@ -160,22 +160,12 @@
if (mid->driver_data == ucd9240)
info->func[0] |= PMBUS_HAVE_FAN12 | PMBUS_HAVE_STATUS_FAN12;
- ret = pmbus_do_probe(client, mid, info);
- if (ret < 0)
- goto out;
- return 0;
-out:
- kfree(info);
- return ret;
+ return pmbus_do_probe(client, mid, info);
}
static int ucd9200_remove(struct i2c_client *client)
{
- const struct pmbus_driver_info *info;
-
- info = pmbus_get_driver_info(client);
pmbus_do_remove(client);
- kfree(info);
return 0;
}