Clean up sys_shutdown
PATCH 1/1 Clean up sys_shutdown
Clean up sys_shutdown exit path
Impact: cleanup, fix
Clean up sys_shutdown exit path. Factor out common code. Return correct error code instead of always 0 on failure.
--- kernel/sys.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-)
kernel/sys.c +9 -15
@@ -360,6 +360,7 @@ void __user *, arg) {char buffer[256 ]; +int ret =0 ;/* We only trust the superuser with rebooting the system. */ if (!capable (CAP_SYS_BOOT ))
@@ -397,7 +398,7 @@kernel_halt ();unlock_kernel ();do_exit (0 ); -break ; +panic ("cannot halt" );case LINUX_REBOOT_CMD_POWER_OFF :kernel_power_off ();
@@ -417,29 +418,22 @@#ifdef CONFIG_KEXEC case LINUX_REBOOT_CMD_KEXEC : - { -int ret; - ret =kernel_kexec (); -unlock_kernel (); -return ret; - } + ret =kernel_kexec (); +break ;#endif #ifdef CONFIG_HIBERNATION case LINUX_REBOOT_CMD_SW_SUSPEND : - { -int ret =hibernate (); -unlock_kernel (); -return ret; - } + ret =hibernate (); +break ;#endif default : -unlock_kernel (); -return -EINVAL ; + ret = -EINVAL ; +break ; }unlock_kernel (); -return 0 ; +return ret; }static void deferred_cad (struct work_struct *dummy)
Quoted 5 lines · On Wed, 8 Apr 2009 00:36:26 +0200 Andi Kleen <[email protected]> wrote:
Clean up
sys_shutdownexit pathImpact: cleanup, fix
Clean up
sys_shutdownexit path. Factor out common code.
OK.
Quoted 2 lines
Return
correct error code instead of always 0 on failure.
oh goody, that makes the patch a bugfix.
Quoted 44 lines
kernel/sys.c +6
-12@@ -360,6 +360,7 @@ void __user *, arg) {char buffer[256 ]; +int ret =0 ;/* We only trust the superuser with rebooting the system. */ if (!capable (CAP_SYS_BOOT ))@@ -397,7 +398,7 @@kernel_halt ();unlock_kernel ();do_exit (0 ); -break ; +panic ("cannot halt" );case LINUX_REBOOT_CMD_POWER_OFF :kernel_power_off ();@@ -417,29 +418,22 @@#ifdef CONFIG_KEXEC case LINUX_REBOOT_CMD_KEXEC : - { -int ret; - ret =kernel_kexec (); -unlock_kernel (); -return ret; - } + ret =kernel_kexec (); +break ;#endif #ifdef CONFIG_HIBERNATION case LINUX_REBOOT_CMD_SW_SUSPEND : - { -int ret =hibernate (); -unlock_kernel (); -return ret; - } + ret =hibernate (); +break ;#endif
kernel/sys.c line 437
Quoted 10 lines
kernel/sys.c +3
-3default : -unlock_kernel (); -return -EINVAL ; + ret = -EINVAL ; +break ; }unlock_kernel (); -return 0 ; +return ret; }
I wonder why this code uses lock_kernel().
Quoted 1 line · Andrew Morton
I wonder why this code uses
lock_kernel().
I suspect because there's no other lock and parallel shutdowns would be bad, but I wouldn't be surprised if there aren't some caller without.
We could just convert it to a new global mutex or something. I think it would be safe on x86, but I'm not sure about all the other architectures.
Actually a simple flag would be enough that returns when one is already in progress (that wouldn't work if parallel ones fail, but that's presumably unlikely)
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.