Re: [PATCH 5/5] hwmon: pmbus: use more devres helpers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jun 26, 2020 at 06:55:35PM +0200, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bgolaszewski@xxxxxxxxxxxx>
> 
> 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@xxxxxxxxxxxx>
> ---
>  drivers/hwmon/pmbus/pmbus_core.c | 27 +++++++++------------------
>  1 file changed, 9 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
> index a420877ba533..af74504647b8 100644
> --- a/drivers/hwmon/pmbus/pmbus_core.c
> +++ b/drivers/hwmon/pmbus/pmbus_core.c
> @@ -1022,9 +1022,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;
> @@ -2538,7 +2538,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.
> @@ -2546,35 +2546,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);
>  
> @@ -2585,7 +2577,6 @@ int pmbus_do_remove(struct i2c_client *client)
>  	debugfs_remove_recursive(data->debugfs);
>  
>  	hwmon_device_unregister(data->hwmon_dev);

This is now wrong.

> -	kfree(data->group.attrs);
>  	return 0;
>  }
>  EXPORT_SYMBOL_GPL(pmbus_do_remove);
> -- 
> 2.26.1
> 



[Index of Archives]     [LM Sensors]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux