From: Guenter Roeck <linux@roeck-us.net>
To: Tian Tao <tiantao6@hisilicon.com>, wim@linux-watchdog.org
Cc: linux-watchdog@vger.kernel.org, Yicong Yang <yangyicong@hisilicon.com>
Subject: Re: [RESEND 1/1] watchdog: simplify devm_watchdog_register_device
Date: Fri, 21 May 2021 04:07:46 -0700 [thread overview]
Message-ID: <1652dd02-1fcd-43fa-46ee-308e80b1a018@roeck-us.net> (raw)
In-Reply-To: <1621581364-31734-1-git-send-email-tiantao6@hisilicon.com>
On 5/21/21 12:16 AM, Tian Tao wrote:
> Use devm_add_action_or_reset() instead of devres_alloc() and
> devres_add(), which works the same. This will simplify the
> code. There is no functional changes.
>
> Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
> Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
There is a functional change: With this patch applied, the watchdog
is registered first, before allocating memory, and then unregistered
if allocating that memory failed. I do not like that change,
and I think the code should remain as-is.
Guenter
> ---
> drivers/watchdog/watchdog_core.c | 21 ++++++---------------
> 1 file changed, 6 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/watchdog/watchdog_core.c b/drivers/watchdog/watchdog_core.c
> index 5df0a22..cea6080 100644
> --- a/drivers/watchdog/watchdog_core.c
> +++ b/drivers/watchdog/watchdog_core.c
> @@ -364,9 +364,9 @@ void watchdog_unregister_device(struct watchdog_device *wdd)
>
> EXPORT_SYMBOL_GPL(watchdog_unregister_device);
>
> -static void devm_watchdog_unregister_device(struct device *dev, void *res)
> +static void devm_watchdog_unregister_device(void *wdd)
> {
> - watchdog_unregister_device(*(struct watchdog_device **)res);
> + watchdog_unregister_device(wdd);
> }
>
> /**
> @@ -381,23 +381,14 @@ static void devm_watchdog_unregister_device(struct device *dev, void *res)
> int devm_watchdog_register_device(struct device *dev,
> struct watchdog_device *wdd)
> {
> - struct watchdog_device **rcwdd;
> int ret;
>
> - rcwdd = devres_alloc(devm_watchdog_unregister_device, sizeof(*rcwdd),
> - GFP_KERNEL);
> - if (!rcwdd)
> - return -ENOMEM;
> -
> ret = watchdog_register_device(wdd);
> - if (!ret) {
> - *rcwdd = wdd;
> - devres_add(dev, rcwdd);
> - } else {
> - devres_free(rcwdd);
> - }
> + if (ret)
> + return ret;
>
> - return ret;
> + return devm_add_action_or_reset(dev, devm_watchdog_unregister_device,
> + wdd);
> }
> EXPORT_SYMBOL_GPL(devm_watchdog_register_device);
>
>
prev parent reply other threads:[~2021-05-21 11:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-21 7:16 [RESEND 1/1] watchdog: simplify devm_watchdog_register_device Tian Tao
2021-05-21 11:07 ` 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=1652dd02-1fcd-43fa-46ee-308e80b1a018@roeck-us.net \
--to=linux@roeck-us.net \
--cc=linux-watchdog@vger.kernel.org \
--cc=tiantao6@hisilicon.com \
--cc=wim@linux-watchdog.org \
--cc=yangyicong@hisilicon.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).