Linux-Watchdog Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] watchdog: simplify devm_watchdog_register_device
@ 2021-04-08  1:13 Tian Tao
  0 siblings, 0 replies; only message in thread
From: Tian Tao @ 2021-04-08  1:13 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	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-08  1:13 [PATCH] watchdog: simplify devm_watchdog_register_device Tian Tao

Linux-Watchdog Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-watchdog/0 linux-watchdog/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-watchdog linux-watchdog/ https://lore.kernel.org/linux-watchdog \
		linux-watchdog@vger.kernel.org
	public-inbox-index linux-watchdog

Example config snippet for mirrors

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


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