mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-29 19:21:31 -04:00
watchdog: core: add reboot notifier support
Many watchdog drivers register a reboot notifier in order to stop the watchdog on system reboot. Thus we can factorize this code in the watchdog core. For that purpose, a new notifier block is added in watchdog_device for internal use only, as well as a new watchdog_stop_on_reboot helper function. If this helper is called, watchdog core registers the related notifier block and will stop the watchdog when SYS_HALT or SYS_DOWN is received. Since this operation can be critical on some platforms, abort the device registration if the reboot notifier registration fails. Suggested-by: Vivien Didelot <[email protected]> Signed-off-by: Damien Riegel <[email protected]> Reviewed-by: Vivien Didelot <[email protected]> Signed-off-by: Guenter Roeck <[email protected]> Signed-off-by: Wim Van Sebroeck <[email protected]>
This commit is contained in:
parent
0ebad1e5e5
commit
e131319669
3 changed files with 54 additions and 0 deletions
|
|
@ -138,6 +138,25 @@ int watchdog_init_timeout(struct watchdog_device *wdd,
|
|||
}
|
||||
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)
|
||||
{
|
||||
|
|
@ -238,6 +257,21 @@ static int __watchdog_register_device(struct watchdog_device *wdd)
|
|||
return ret;
|
||||
}
|
||||
|
||||
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) {
|
||||
dev_err(wdd->dev, "Cannot register reboot notifier (%d)\n",
|
||||
ret);
|
||||
watchdog_dev_unregister(wdd);
|
||||
device_destroy(watchdog_class, devno);
|
||||
ida_simple_remove(&watchdog_ida, wdd->id);
|
||||
wdd->dev = NULL;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
if (wdd->ops->restart) {
|
||||
wdd->restart_nb.notifier_call = watchdog_restart_notifier;
|
||||
|
||||
|
|
@ -286,6 +320,9 @@ 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);
|
||||
|
||||
devno = wdd->cdev.dev;
|
||||
ret = watchdog_dev_unregister(wdd);
|
||||
if (ret)
|
||||
|
|
|
|||
Loading…
Reference in a new issue