diff options
author | Dmitry Osipenko <dmitry.osipenko@collabora.com> | 2022-05-10 02:32:15 +0300 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2022-05-19 19:30:30 +0200 |
commit | 0e2110d2e910e44cc7cf23fce14613e232602602 (patch) | |
tree | d736c3c83351798e73fb3b00aa28210fb91e9ce2 /kernel | |
parent | 5d34b41aa420c3908793b43419a1097362ca2668 (diff) | |
download | linux-stable-0e2110d2e910e44cc7cf23fce14613e232602602.tar.gz linux-stable-0e2110d2e910e44cc7cf23fce14613e232602602.tar.bz2 linux-stable-0e2110d2e910e44cc7cf23fce14613e232602602.zip |
kernel/reboot: Add kernel_can_power_off()
Add kernel_can_power_off() helper that replaces open-coded checks of
the global pm_power_off variable. This is a necessary step towards
supporting chained power-off handlers.
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/reboot.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/kernel/reboot.c b/kernel/reboot.c index 7723aff4d09b..fb3f49350927 100644 --- a/kernel/reboot.c +++ b/kernel/reboot.c @@ -524,6 +524,18 @@ void do_kernel_power_off(void) } /** + * kernel_can_power_off - check whether system can be powered off + * + * Returns true if power-off handler is registered and system can be + * powered off, false otherwise. + */ +bool kernel_can_power_off(void) +{ + return !atomic_notifier_call_chain_is_empty(&power_off_handler_list); +} +EXPORT_SYMBOL_GPL(kernel_can_power_off); + +/** * kernel_power_off - power_off the system * * Shutdown everything and perform a clean system power_off. @@ -581,7 +593,7 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd, /* Instead of trying to make the power_off code look like * halt when pm_power_off is not set do it the easy way. */ - if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off) + if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !kernel_can_power_off()) cmd = LINUX_REBOOT_CMD_HALT; mutex_lock(&system_transition_mutex); |