watchdog: Fix potential dereferencing of null pointer
[linux-2.6-microblaze.git] / drivers / watchdog / watchdog_core.c
index 861daf4..0e9a995 100644 (file)
 
 static DEFINE_IDA(watchdog_ida);
 
+static int stop_on_reboot = -1;
+module_param(stop_on_reboot, int, 0444);
+MODULE_PARM_DESC(stop_on_reboot, "Stop watchdogs on reboot (0=keep watching, 1=stop)");
+
 /*
  * Deferred Registration infrastructure.
  *
@@ -254,16 +258,28 @@ 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;
+       /* Module parameter to force watchdog policy on reboot. */
+       if (stop_on_reboot != -1) {
+               if (stop_on_reboot)
+                       set_bit(WDOG_STOP_ON_REBOOT, &wdd->status);
+               else
+                       clear_bit(WDOG_STOP_ON_REBOOT, &wdd->status);
+       }
 
-               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, id);
-                       return ret;
+       if (test_bit(WDOG_STOP_ON_REBOOT, &wdd->status)) {
+               if (!wdd->ops->stop)
+                       pr_warn("watchdog%d: stop_on_reboot not supported\n", wdd->id);
+               else {
+                       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, id);
+                               return ret;
+                       }
                }
        }