[RESEND,1/1] watchdog: simplify devm_watchdog_register_device

Message ID 1621581364-31734-1-git-send-email-tiantao6@hisilicon.com
State New
Headers show
Series
  • [RESEND,1/1] watchdog: simplify devm_watchdog_register_device
Related show

Commit Message

Tian Tao May 21, 2021, 7:16 a.m.
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(-)

Patch

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);