* [RESEND 1/1] watchdog: simplify devm_watchdog_register_device
@ 2021-05-21 7:16 Tian Tao
2021-05-21 11:07 ` Guenter Roeck
0 siblings, 1 reply; 2+ messages in thread
From: Tian Tao @ 2021-05-21 7:16 UTC (permalink / raw)
To: wim, linux; +Cc: linux-watchdog, Tian Tao, Yicong Yang
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>
---
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);
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [RESEND 1/1] watchdog: simplify devm_watchdog_register_device
2021-05-21 7:16 [RESEND 1/1] watchdog: simplify devm_watchdog_register_device Tian Tao
@ 2021-05-21 11:07 ` Guenter Roeck
0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2021-05-21 11:07 UTC (permalink / raw)
To: Tian Tao, wim; +Cc: linux-watchdog, Yicong Yang
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);
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-05-21 11:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-21 7:16 [RESEND 1/1] watchdog: simplify devm_watchdog_register_device Tian Tao
2021-05-21 11:07 ` Guenter Roeck
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.