}
 EXPORT_SYMBOL_GPL(watchdog_init_timeout);
 
-static int watchdog_reboot_notifier(struct notifier_block *nb,
-                                   unsigned long code, void *data)
-{
-       struct watchdog_device *wdd = container_of(nb, struct watchdog_device,
-                                                  reboot_nb);
-
-       if (code == SYS_DOWN || code == SYS_HALT) {
-               if (watchdog_active(wdd)) {
-                       int ret;
-
-                       ret = wdd->ops->stop(wdd);
-                       if (ret)
-                               return NOTIFY_BAD;
-               }
-       }
-
-       return NOTIFY_DONE;
-}
-
 static int watchdog_restart_notifier(struct notifier_block *nb,
                                     unsigned long action, void *data)
 {
                }
        }
 
-       if (test_bit(WDOG_STOP_ON_REBOOT, &wdd->status)) {
-               wdd->reboot_nb.notifier_call = watchdog_reboot_notifier;
-
-               ret = register_reboot_notifier(&wdd->reboot_nb);
-               if (ret) {
-                       pr_err("watchdog%d: Cannot register reboot notifier (%d)\n",
-                              wdd->id, ret);
-                       watchdog_dev_unregister(wdd);
-                       ida_simple_remove(&watchdog_ida, wdd->id);
-                       return ret;
-               }
-       }
-
        if (wdd->ops->restart) {
                wdd->restart_nb.notifier_call = watchdog_restart_notifier;
 
        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);
 }
 
 #include <linux/miscdevice.h>  /* For handling misc devices */
 #include <linux/module.h>      /* For module stuff/... */
 #include <linux/mutex.h>       /* For mutexes */
+#include <linux/reboot.h>      /* For reboot notifier */
 #include <linux/slab.h>                /* For memory functions */
 #include <linux/types.h>       /* For standard types (like size_t) */
 #include <linux/watchdog.h>    /* For watchdog specific items */
        .dev_groups =   wdt_groups,
 };
 
+static int watchdog_reboot_notifier(struct notifier_block *nb,
+                                   unsigned long code, void *data)
+{
+       struct watchdog_device *wdd;
+
+       wdd = container_of(nb, struct watchdog_device, reboot_nb);
+       if (code == SYS_DOWN || code == SYS_HALT) {
+               if (watchdog_active(wdd)) {
+                       int ret;
+
+                       ret = wdd->ops->stop(wdd);
+                       if (ret)
+                               return NOTIFY_BAD;
+               }
+       }
+
+       return NOTIFY_DONE;
+}
+
 /*
  *     watchdog_dev_register: register a watchdog device
  *     @wdd: watchdog device
        if (ret) {
                device_destroy(&watchdog_class, devno);
                watchdog_cdev_unregister(wdd);
+               return ret;
+       }
+
+       if (test_bit(WDOG_STOP_ON_REBOOT, &wdd->status)) {
+               wdd->reboot_nb.notifier_call = watchdog_reboot_notifier;
+
+               ret = devm_register_reboot_notifier(dev, &wdd->reboot_nb);
+               if (ret) {
+                       pr_err("watchdog%d: Cannot register reboot notifier (%d)\n",
+                              wdd->id, ret);
+                       watchdog_dev_unregister(wdd);
+               }
        }
 
        return ret;