Re: [RESEND 1/1] watchdog: simplify devm_watchdog_register_device

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxx>
Signed-off-by: Yicong Yang <yangyicong@xxxxxxxxxxxxx>

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




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux