Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

watchdog: alim7101: register restart handler with kernel restart handler

The kernel core now provides an API to trigger a system restart. Register
with it to restart the system instead of misusing the reboot notifier.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Acked-by: Heiko Stuebner <heiko@sntech.de>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jonas Jensen <jonas.jensen@gmail.com>
Cc: Maxime Ripard <maxime.ripard@free-electrons.com>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Tomasz Figa <t.figa@samsung.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Wim Van Sebroeck <wim@iguana.be>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

+32 -10
+32 -10
drivers/watchdog/alim7101_wdt.c
··· 301 301 .fops = &wdt_fops, 302 302 }; 303 303 304 + static int wdt_restart_handle(struct notifier_block *this, unsigned long mode, 305 + void *cmd) 306 + { 307 + /* 308 + * Cobalt devices have no way of rebooting themselves other 309 + * than getting the watchdog to pull reset, so we restart the 310 + * watchdog on reboot with no heartbeat. 311 + */ 312 + wdt_change(WDT_ENABLE); 313 + 314 + /* loop until the watchdog fires */ 315 + while (true) 316 + ; 317 + 318 + return NOTIFY_DONE; 319 + } 320 + 321 + static struct notifier_block wdt_restart_handler = { 322 + .notifier_call = wdt_restart_handle, 323 + .priority = 128, 324 + }; 325 + 304 326 /* 305 327 * Notifier for system down 306 328 */ ··· 333 311 if (code == SYS_DOWN || code == SYS_HALT) 334 312 wdt_turnoff(); 335 313 336 - if (code == SYS_RESTART) { 337 - /* 338 - * Cobalt devices have no way of rebooting themselves other 339 - * than getting the watchdog to pull reset, so we restart the 340 - * watchdog on reboot with no heartbeat 341 - */ 342 - wdt_change(WDT_ENABLE); 343 - pr_info("Watchdog timer is now enabled with no heartbeat - should reboot in ~1 second\n"); 344 - } 345 314 return NOTIFY_DONE; 346 315 } 347 316 ··· 351 338 /* Deregister */ 352 339 misc_deregister(&wdt_miscdev); 353 340 unregister_reboot_notifier(&wdt_notifier); 341 + unregister_restart_handler(&wdt_restart_handler); 354 342 pci_dev_put(alim7101_pmu); 355 343 } 356 344 ··· 404 390 goto err_out; 405 391 } 406 392 393 + rc = register_restart_handler(&wdt_restart_handler); 394 + if (rc) { 395 + pr_err("cannot register restart handler (err=%d)\n", rc); 396 + goto err_out_reboot; 397 + } 398 + 407 399 rc = misc_register(&wdt_miscdev); 408 400 if (rc) { 409 401 pr_err("cannot register miscdev on minor=%d (err=%d)\n", 410 402 wdt_miscdev.minor, rc); 411 - goto err_out_reboot; 403 + goto err_out_restart; 412 404 } 413 405 414 406 if (nowayout) ··· 424 404 timeout, nowayout); 425 405 return 0; 426 406 407 + err_out_restart: 408 + unregister_restart_handler(&wdt_restart_handler); 427 409 err_out_reboot: 428 410 unregister_reboot_notifier(&wdt_notifier); 429 411 err_out: