All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: W_Armin@gmx.de, hdegoede@redhat.com
Cc: linux-hwmon@vger.kernel.org, jdelvare@suse.com
Subject: Re: [PATCH 1/4] hwmon: (sch56xx) Use devres functions for watchdog
Date: Fri, 7 May 2021 14:43:50 -0700	[thread overview]
Message-ID: <65ffae02-cef6-c3e8-6302-a0610fc4af53@roeck-us.net> (raw)
In-Reply-To: <20210507212404.6781-2-W_Armin@gmx.de>

On 5/7/21 2:24 PM, W_Armin@gmx.de wrote:
> From: Armin Wolf <W_Armin@gmx.de>
> 
> Use devm_kzalloc()/devm_watchdog_register() for
> watchdog registration since it allows us to remove
> the sch56xx_watchdog_data struct from the drivers
> own data structs.
> Remove sch56xx_watchdog_unregister since devres
> takes care of that now.
> 
> Signed-off-by: Armin Wolf <W_Armin@gmx.de>
> ---
>   drivers/hwmon/sch5627.c        | 12 +++---------
>   drivers/hwmon/sch5636.c        |  9 ++-------
>   drivers/hwmon/sch56xx-common.c | 13 +++----------
>   3 files changed, 8 insertions(+), 26 deletions(-)
> 
> diff --git a/drivers/hwmon/sch5627.c b/drivers/hwmon/sch5627.c
> index 4324a5dbc968..8a71fba33ea0 100644
> --- a/drivers/hwmon/sch5627.c
> +++ b/drivers/hwmon/sch5627.c
> @@ -64,7 +64,6 @@ static const char * const SCH5627_IN_LABELS[SCH5627_NO_IN] = {
> 
>   struct sch5627_data {
>   	unsigned short addr;
> -	struct sch56xx_watchdog_data *watchdog;
>   	u8 control;
>   	u8 temp_max[SCH5627_NO_TEMPS];
>   	u8 temp_crit[SCH5627_NO_TEMPS];
> @@ -359,11 +358,6 @@ static const struct hwmon_chip_info sch5627_chip_info = {
> 
>   static int sch5627_remove(struct platform_device *pdev)
>   {
> -	struct sch5627_data *data = platform_get_drvdata(pdev);
> -
> -	if (data->watchdog)
> -		sch56xx_watchdog_unregister(data->watchdog);
> -
>   	return 0;
>   }

This function is no longer necessary and can be dropped as well.

> 
> @@ -460,9 +454,9 @@ static int sch5627_probe(struct platform_device *pdev)
>   		return PTR_ERR(hwmon_dev);
> 
>   	/* Note failing to register the watchdog is not a fatal error */
> -	data->watchdog = sch56xx_watchdog_register(&pdev->dev, data->addr,
> -			(build_code << 24) | (build_id << 8) | hwmon_rev,
> -			&data->update_lock, 1);
> +	sch56xx_watchdog_register(&pdev->dev, data->addr,
> +				  (build_code << 24) | (build_id << 8) | hwmon_rev,
> +				  &data->update_lock, 1);
> 
>   	return 0;
>   }
> diff --git a/drivers/hwmon/sch5636.c b/drivers/hwmon/sch5636.c
> index 5683a38740f6..a5cd4de36575 100644
> --- a/drivers/hwmon/sch5636.c
> +++ b/drivers/hwmon/sch5636.c
> @@ -54,7 +54,6 @@ static const u16 SCH5636_REG_FAN_VAL[SCH5636_NO_FANS] = {
>   struct sch5636_data {
>   	unsigned short addr;
>   	struct device *hwmon_dev;
> -	struct sch56xx_watchdog_data *watchdog;
> 
>   	struct mutex update_lock;
>   	char valid;			/* !=0 if following fields are valid */
> @@ -372,9 +371,6 @@ static int sch5636_remove(struct platform_device *pdev)
>   	struct sch5636_data *data = platform_get_drvdata(pdev);
>   	int i;
> 
> -	if (data->watchdog)
> -		sch56xx_watchdog_unregister(data->watchdog);
> -
>   	if (data->hwmon_dev)
>   		hwmon_device_unregister(data->hwmon_dev);
> 
> @@ -495,9 +491,8 @@ static int sch5636_probe(struct platform_device *pdev)
>   	}
> 
>   	/* Note failing to register the watchdog is not a fatal error */
> -	data->watchdog = sch56xx_watchdog_register(&pdev->dev, data->addr,
> -					(revision[0] << 8) | revision[1],
> -					&data->update_lock, 0);
> +	sch56xx_watchdog_register(&pdev->dev, data->addr, (revision[0] << 8) | revision[1],
> +				  &data->update_lock, 0);
> 
>   	return 0;
> 
> diff --git a/drivers/hwmon/sch56xx-common.c b/drivers/hwmon/sch56xx-common.c
> index 6c84780e358e..9c884fd0beb2 100644
> --- a/drivers/hwmon/sch56xx-common.c
> +++ b/drivers/hwmon/sch56xx-common.c
> @@ -401,7 +401,7 @@ struct sch56xx_watchdog_data *sch56xx_watchdog_register(struct device *parent,
>   		return NULL;
>   	}
> 
> -	data = kzalloc(sizeof(struct sch56xx_watchdog_data), GFP_KERNEL);
> +	data = devm_kzalloc(parent, sizeof(struct sch56xx_watchdog_data), GFP_KERNEL);
>   	if (!data)
>   		return NULL;
> 
> @@ -438,10 +438,10 @@ struct sch56xx_watchdog_data *sch56xx_watchdog_register(struct device *parent,

Since the return value is no longer used, the function does not need
to return it anymore.

>   	data->watchdog_output_enable = output_enable;
> 
>   	watchdog_set_drvdata(&data->wddev, data);
> -	err = watchdog_register_device(&data->wddev);
> +	err = devm_watchdog_register_device(parent, &data->wddev);
>   	if (err) {
>   		pr_err("Registering watchdog chardev: %d\n", err);
> -		kfree(data);
> +		devm_kfree(parent, data);
>   		return NULL;
>   	}
> 
> @@ -449,13 +449,6 @@ struct sch56xx_watchdog_data *sch56xx_watchdog_register(struct device *parent,
>   }
>   EXPORT_SYMBOL(sch56xx_watchdog_register);
> 
> -void sch56xx_watchdog_unregister(struct sch56xx_watchdog_data *data)
> -{
> -	watchdog_unregister_device(&data->wddev);
> -	kfree(data);
> -}
> -EXPORT_SYMBOL(sch56xx_watchdog_unregister);
> -
>   /*
>    * platform dev find, add and remove functions
>    */
> --
> 2.20.1
> 


  reply	other threads:[~2021-05-07 21:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-07 21:24 [PATCH 0/4] hwmon: (sch56xx) Use devres for watchdog and platform_device_register_simple() W_Armin
2021-05-07 21:24 ` [PATCH 1/4] hwmon: (sch56xx) Use devres functions for watchdog W_Armin
2021-05-07 21:43   ` Guenter Roeck [this message]
2021-05-07 21:24 ` [PATCH 2/4] hwmon: (sch56xx-common) Use strscpy W_Armin
2021-05-07 21:24 ` [PATCH 3/4] hwmon: (sch56xx-common) Use helper function W_Armin
2021-05-07 21:24 ` [PATCH 4/4] hwmon: (sch56xx-common) Simplify sch56xx_device_add W_Armin
2021-05-08  8:59 ` [PATCH 0/4] hwmon: (sch56xx) Use devres for watchdog and platform_device_register_simple() Hans de Goede

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=65ffae02-cef6-c3e8-6302-a0610fc4af53@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=W_Armin@gmx.de \
    --cc=hdegoede@redhat.com \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.