Linux-Hwmon Archive on lore.kernel.org
 help / color / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Jonathan Corbet <corbet@lwn.net>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	Jean Delvare <jdelvare@suse.com>,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-hwmon@vger.kernel.org,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>
Subject: Re: [PATCH 5/5] hwmon: pmbus: use more devres helpers
Date: Fri, 26 Jun 2020 14:50:03 -0700
Message-ID: <20200626215003.GA254814@roeck-us.net> (raw)
In-Reply-To: <20200626165535.7662-6-brgl@bgdev.pl>

On Fri, Jun 26, 2020 at 06:55:35PM +0200, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> 
> 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>
> ---
>  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
> 

      reply index

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-26 16:55 [PATCH 0/5] devres: provide and use devm_krealloc() Bartosz Golaszewski
2020-06-26 16:55 ` [PATCH 1/5] devres: remove stray space from devm_kmalloc() definition Bartosz Golaszewski
2020-06-26 16:55 ` [PATCH 2/5] devres: move the size check from alloc_dr() into a separate function Bartosz Golaszewski
2020-06-26 16:55 ` [PATCH 3/5] device: remove 'extern' attribute from function prototypes in device.h Bartosz Golaszewski
2020-06-26 16:55 ` [PATCH 4/5] devres: provide devm_krealloc() Bartosz Golaszewski
2020-06-26 16:55 ` [PATCH 5/5] hwmon: pmbus: use more devres helpers Bartosz Golaszewski
2020-06-26 21:50   ` Guenter Roeck [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200626215003.GA254814@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=bgolaszewski@baylibre.com \
    --cc=brgl@bgdev.pl \
    --cc=corbet@lwn.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=jdelvare@suse.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-Hwmon Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-hwmon/0 linux-hwmon/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-hwmon linux-hwmon/ https://lore.kernel.org/linux-hwmon \
		linux-hwmon@vger.kernel.org
	public-inbox-index linux-hwmon

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-hwmon


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git