Skip to contentSkip to conversation

watchdog: core: Make use of devm_register_reboot_notifier()

PATCH Superseded Andrey Smirnov 3 participants 5 messages Apr 4, 2017 Watchdog device drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 watchdog: core: Make use of devm_register_reboot_notifier()

Save a bit of cleanup code by leveraging newly added devm_register_reboot_notifier().

---

All:

This patch is a follow up to this thread
https://lkml.org/lkml/2017/3/20/671. I am not sure what's the best way to manager cross-tree dependency here, so, if there's something to be done, please let me know.

Thanks,
Andrey Smirnov

 drivers/watchdog/watchdog_core.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/watchdog/watchdog_core.c +2 -4
index 74265b2..9d868f1 100644
@@ -247,7 +247,8 @@ static int __watchdog_register_device(struct watchdog_device *wdd)
 	if (test_bit(WDOG_STOP_ON_REBOOT, &wdd->status)) {
 		wdd->reboot_nb.notifier_call = watchdog_reboot_notifier;
 
-		ret = register_reboot_notifier(&wdd->reboot_nb);
+		ret = devm_register_reboot_notifier(wdd->parent,
+						    &wdd->reboot_nb);
 		if (ret) {
 			pr_err("watchdog%d: Cannot register reboot notifier (%d)\n",
 			       wdd->id, ret);
@@ -302,9 +303,6 @@ static void __watchdog_unregister_device(struct watchdog_device *wdd)
 	if (wdd->ops->restart)
 		unregister_restart_handler(&wdd->restart_nb);
 
-	if (test_bit(WDOG_STOP_ON_REBOOT, &wdd->status))
-		unregister_reboot_notifier(&wdd->reboot_nb);
-
 	watchdog_dev_unregister(wdd);
 	ida_simple_remove(&watchdog_ida, wdd->id);
 }
Signature · 1 line
2.9.3
#1 lore raw

drivers/watchdog/watchdog_core.c static int __watchdog_register_device(struct watchdog_device *wdd) · line 252

Quoted 11 lines · Andrey Smirnov

Save a bit of cleanup code by leveraging newly added devm_register_reboot_notifier().

drivers/watchdog/watchdog_core.c +2 -1
@@ -247,7 +247,8 @@ static int __watchdog_register_device(struct watchdog_device *wdd)
        if (test_bit(WDOG_STOP_ON_REBOOT, &wdd->status)) {
                wdd->reboot_nb.notifier_call = watchdog_reboot_notifier;
 
-               ret = register_reboot_notifier(&wdd->reboot_nb);
 
+               ret = devm_register_reboot_notifier(wdd->parent,
+                                                   &wdd->reboot_nb);

I'm not sure it's logically correct. Perhaps binding to the actual watchdog device would be better.
Though, Guenter can correct me.

Could it be one line after all?

Quoted 10 lines
drivers/watchdog/watchdog_core.c +0 -0
                if (ret) {
                        pr_err("watchdog%d: Cannot register reboot notifier (%d)\n",
                               wdd->id, ret);
drivers/watchdog/watchdog_core.c +0 -3
@@ -302,9 +303,6 @@ static void __watchdog_unregister_device(struct watchdog_device *wdd)
        if (wdd->ops->restart)
                unregister_restart_handler(&wdd->restart_nb);
 
-       if (test_bit(WDOG_STOP_ON_REBOOT, &wdd->status))
-               unregister_reboot_notifier(&wdd->reboot_nb);
-
Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#2 lore raw
Quoted 8 lines · Andy Shevchenko
Quoted 7 lines · Andrey Smirnov

Save a bit of cleanup code by leveraging newly added devm_register_reboot_notifier().

drivers/watchdog/watchdog_core.c +0 -0
@@ -247,7 +247,8 @@ static int __watchdog_register_device(struct watchdog_device *wdd)
        if (test_bit(WDOG_STOP_ON_REBOOT, &wdd->status)) {
                wdd->reboot_nb.notifier_call = watchdog_reboot_notifier;
 
Quoted 9 lines

drivers/watchdog/watchdog_core.c static int __watchdog_register_device(struct watchdog_device *wdd) · line 251

Quoted 4 lines
drivers/watchdog/watchdog_core.c +2 -1
-               ret = register_reboot_notifier(&wdd->reboot_nb);
 
+               ret = devm_register_reboot_notifier(wdd->parent,
+                                                   &wdd->reboot_nb);

I'm not sure it's logically correct. Perhaps binding to the actual watchdog device would be better.
Though, Guenter can correct me.

As mentioned in my other reply, it doesn't work since wdd->parent can be NULL. It might be possible to move the code into watchdog_dev_register() and tie it to the watchdog device, but I have not explored what that would require.

Guenter

Quoted 13 lines

Could it be one line after all?

Quoted 10 lines
drivers/watchdog/watchdog_core.c +0 -0
                if (ret) {
                        pr_err("watchdog%d: Cannot register reboot notifier (%d)\n",
                               wdd->id, ret);
drivers/watchdog/watchdog_core.c +0 -3
@@ -302,9 +303,6 @@ static void __watchdog_unregister_device(struct watchdog_device *wdd)
        if (wdd->ops->restart)
                unregister_restart_handler(&wdd->restart_nb);
 
-       if (test_bit(WDOG_STOP_ON_REBOOT, &wdd->status))
-               unregister_reboot_notifier(&wdd->reboot_nb);
-
#3 lore raw
Quoted 13 lines · Guenter Roeck
Quoted 11 lines · Andy Shevchenko

drivers/watchdog/watchdog_core.c static int __watchdog_register_device(struct watchdog_device *wdd) · line 251

Quoted 2 lines · Andrey Smirnov
drivers/watchdog/watchdog_core.c +2 -0
+               ret = devm_register_reboot_notifier(wdd->parent,
+                                                   &wdd->reboot_nb);

I'm not sure it's logically correct. Perhaps binding to the actual watchdog device would be better.
Though, Guenter can correct me.

Quoted 5 lines

As mentioned in my other reply, it doesn't work since wdd->parent can be NULL.
It might be possible to move the code into watchdog_dev_register() and tie it
to the watchdog device, but I have not explored what that would require.

I would rather add device pointer to watchdoig struct, though it's your call :-) So, what you decide I'll agree with.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#4 lore raw
In reply to Andrey Smirnov
Quoted 29 lines · Andrey Smirnov

Save a bit of cleanup code by leveraging newly added devm_register_reboot_notifier().

---

All:

This patch is a follow up to this thread
https://lkml.org/lkml/2017/3/20/671. I am not sure what's the best way to manager cross-tree dependency here, so, if there's something to be done, please let me know.

Thanks,
Andrey Smirnov

 drivers/watchdog/watchdog_core.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/watchdog/watchdog_core.c +0 -0
index 74265b2..9d868f1 100644

drivers/watchdog/watchdog_core.c static int __watchdog_register_device(struct watchdog_device *wdd) · line 251

Quoted 6 lines
drivers/watchdog/watchdog_core.c +2 -1
@@ -247,7 +247,8 @@ static int __watchdog_register_device(struct watchdog_device *wdd)
 	if (test_bit(WDOG_STOP_ON_REBOOT, &wdd->status)) {
 		wdd->reboot_nb.notifier_call = watchdog_reboot_notifier;
 
-		ret = register_reboot_notifier(&wdd->reboot_nb);
+		ret = devm_register_reboot_notifier(wdd->parent,
+						    &wdd->reboot_nb);

I like the idea, but unfortunately wdd->parent can be NULL. Also, this would result in the notifier being removed _after_ the watchdog device has been removed, which would be bad as well.

Guenter

Quoted 14 lines
drivers/watchdog/watchdog_core.c +0 -3
 		if (ret) {
 			pr_err("watchdog%d: Cannot register reboot notifier (%d)\n",
 			       wdd->id, ret);
@@ -302,9 +303,6 @@ static void __watchdog_unregister_device(struct watchdog_device *wdd)
 	if (wdd->ops->restart)
 		unregister_restart_handler(&wdd->restart_nb);
 
-	if (test_bit(WDOG_STOP_ON_REBOOT, &wdd->status))
-		unregister_reboot_notifier(&wdd->reboot_nb);
-
 	watchdog_dev_unregister(wdd);
 	ida_simple_remove(&watchdog_ida, wdd->id);
 }