Skip to content

Commit da007f1

Browse files
digetxrafaeljw
authored andcommitted
kernel/reboot: Change registration order of legacy power-off handler
We're unconditionally registering sys-off handler for the legacy pm_power_off() callback, this causes problem for platforms that don't use power-off handlers at all and should be halted. Now reboot syscall assumes that there is a power-off handler installed and tries to power off system instead of halting it. To fix the trouble, move the handler's registration to the reboot syscall and check the pm_power_off() presence. Fixes: 0e2110d ("kernel/reboot: Add kernel_can_power_off()") Reported-by: Geert Uytterhoeven <[email protected]> Tested-by: Geert Uytterhoeven <[email protected]> Signed-off-by: Dmitry Osipenko <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent cfd6d63 commit da007f1

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

kernel/reboot.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -569,22 +569,6 @@ static int legacy_pm_power_off(struct sys_off_data *data)
569569
return NOTIFY_DONE;
570570
}
571571

572-
/*
573-
* Register sys-off handlers for legacy PM callbacks. This allows legacy
574-
* PM callbacks co-exist with the new sys-off API.
575-
*
576-
* TODO: Remove legacy handlers once all legacy PM users will be switched
577-
* to the sys-off based APIs.
578-
*/
579-
static int __init legacy_pm_init(void)
580-
{
581-
register_sys_off_handler(SYS_OFF_MODE_POWER_OFF, SYS_OFF_PRIO_DEFAULT,
582-
legacy_pm_power_off, NULL);
583-
584-
return 0;
585-
}
586-
core_initcall(legacy_pm_init);
587-
588572
static void do_kernel_power_off_prepare(void)
589573
{
590574
blocking_notifier_call_chain(&power_off_prep_handler_list, 0, NULL);
@@ -646,6 +630,7 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
646630
void __user *, arg)
647631
{
648632
struct pid_namespace *pid_ns = task_active_pid_ns(current);
633+
struct sys_off_handler *sys_off = NULL;
649634
char buffer[256];
650635
int ret = 0;
651636

@@ -670,6 +655,21 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
670655
if (ret)
671656
return ret;
672657

658+
/*
659+
* Register sys-off handlers for legacy PM callback. This allows
660+
* legacy PM callbacks temporary co-exist with the new sys-off API.
661+
*
662+
* TODO: Remove legacy handlers once all legacy PM users will be
663+
* switched to the sys-off based APIs.
664+
*/
665+
if (pm_power_off) {
666+
sys_off = register_sys_off_handler(SYS_OFF_MODE_POWER_OFF,
667+
SYS_OFF_PRIO_DEFAULT,
668+
legacy_pm_power_off, NULL);
669+
if (IS_ERR(sys_off))
670+
return PTR_ERR(sys_off);
671+
}
672+
673673
/* Instead of trying to make the power_off code look like
674674
* halt when pm_power_off is not set do it the easy way.
675675
*/
@@ -727,6 +727,7 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
727727
break;
728728
}
729729
mutex_unlock(&system_transition_mutex);
730+
unregister_sys_off_handler(sys_off);
730731
return ret;
731732
}
732733

0 commit comments

Comments
 (0)