hwmon: pmbus: use more devres helpers
Shrink pmbus code by using devm_hwmon_device_register_with_groups() and devm_krealloc() instead of their non-managed variants. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Acked-by: Guenter Roeck <linux@roeck-us.net> Link: https://lore.kernel.org/r/20200824173859.4910-3-brgl@bgdev.pl Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
f82485722e
commit
bb19133fc8
|
@ -1018,9 +1018,9 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
|
|||
{
|
||||
if (data->num_attributes >= data->max_attributes - 1) {
|
||||
int new_max_attrs = data->max_attributes + PMBUS_ATTR_ALLOC_SIZE;
|
||||
void *new_attrs = krealloc(data->group.attrs,
|
||||
new_max_attrs * sizeof(void *),
|
||||
GFP_KERNEL);
|
||||
void *new_attrs = devm_krealloc(data->dev, data->group.attrs,
|
||||
new_max_attrs * sizeof(void *),
|
||||
GFP_KERNEL);
|
||||
if (!new_attrs)
|
||||
return -ENOMEM;
|
||||
data->group.attrs = new_attrs;
|
||||
|
@ -2534,7 +2534,7 @@ int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id,
|
|||
|
||||
ret = pmbus_find_attributes(client, data);
|
||||
if (ret)
|
||||
goto out_kfree;
|
||||
return ret;
|
||||
|
||||
/*
|
||||
* If there are no attributes, something is wrong.
|
||||
|
@ -2542,35 +2542,27 @@ int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id,
|
|||
*/
|
||||
if (!data->num_attributes) {
|
||||
dev_err(dev, "No attributes found\n");
|
||||
ret = -ENODEV;
|
||||
goto out_kfree;
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
data->groups[0] = &data->group;
|
||||
memcpy(data->groups + 1, info->groups, sizeof(void *) * groups_num);
|
||||
data->hwmon_dev = hwmon_device_register_with_groups(dev, client->name,
|
||||
data, data->groups);
|
||||
data->hwmon_dev = devm_hwmon_device_register_with_groups(dev,
|
||||
client->name, data, data->groups);
|
||||
if (IS_ERR(data->hwmon_dev)) {
|
||||
ret = PTR_ERR(data->hwmon_dev);
|
||||
dev_err(dev, "Failed to register hwmon device\n");
|
||||
goto out_kfree;
|
||||
return PTR_ERR(data->hwmon_dev);
|
||||
}
|
||||
|
||||
ret = pmbus_regulator_register(data);
|
||||
if (ret)
|
||||
goto out_unregister;
|
||||
return ret;
|
||||
|
||||
ret = pmbus_init_debugfs(client, data);
|
||||
if (ret)
|
||||
dev_warn(dev, "Failed to register debugfs\n");
|
||||
|
||||
return 0;
|
||||
|
||||
out_unregister:
|
||||
hwmon_device_unregister(data->hwmon_dev);
|
||||
out_kfree:
|
||||
kfree(data->group.attrs);
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(pmbus_do_probe);
|
||||
|
||||
|
@ -2580,8 +2572,6 @@ int pmbus_do_remove(struct i2c_client *client)
|
|||
|
||||
debugfs_remove_recursive(data->debugfs);
|
||||
|
||||
hwmon_device_unregister(data->hwmon_dev);
|
||||
kfree(data->group.attrs);
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(pmbus_do_remove);
|
||||
|
|
Loading…
Reference in New Issue