* [PATCH] Clean up sys_shutdown
@ 2009-04-07 22:36 Andi Kleen
2009-04-10 5:14 ` Andrew Morton
0 siblings, 1 reply; 3+ messages in thread
From: Andi Kleen @ 2009-04-07 22:36 UTC (permalink / raw)
To: linux-kernel
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.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
kernel/sys.c | 24 +++++++++---------------
1 file changed, 9 insertions(+), 15 deletions(-)
Index: linux/kernel/sys.c
===================================================================
--- linux.orig/kernel/sys.c 2009-04-07 16:09:58.000000000 +0200
+++ linux/kernel/sys.c 2009-04-07 16:43:17.000000000 +0200
@@ -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)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Clean up sys_shutdown
2009-04-07 22:36 [PATCH] Clean up sys_shutdown Andi Kleen
@ 2009-04-10 5:14 ` Andrew Morton
2009-04-10 8:38 ` Andi Kleen
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2009-04-10 5:14 UTC (permalink / raw)
To: Andi Kleen; +Cc: linux-kernel
On Wed, 8 Apr 2009 00:36:26 +0200 Andi Kleen <andi@firstfloor.org> wrote:
> Clean up sys_shutdown exit path
>
> Impact: cleanup, fix
>
> Clean up sys_shutdown exit path. Factor out common code.
OK.
> Return
> correct error code instead of always 0 on failure.
oh goody, that makes the patch a bugfix.
> --- linux.orig/kernel/sys.c 2009-04-07 16:09:58.000000000 +0200
> +++ linux/kernel/sys.c 2009-04-07 16:43:17.000000000 +0200
> @@ -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;
> }
I wonder why this code uses lock_kernel().
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Clean up sys_shutdown
2009-04-10 5:14 ` Andrew Morton
@ 2009-04-10 8:38 ` Andi Kleen
0 siblings, 0 replies; 3+ messages in thread
From: Andi Kleen @ 2009-04-10 8:38 UTC (permalink / raw)
To: Andrew Morton; +Cc: Andi Kleen, linux-kernel
On Thu, Apr 09, 2009 at 10:14:16PM -0700, Andrew Morton wrote:
> 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
--
ak@linux.intel.com -- Speaking for myself only.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-04-10 8:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-07 22:36 [PATCH] Clean up sys_shutdown Andi Kleen
2009-04-10 5:14 ` Andrew Morton
2009-04-10 8:38 ` Andi Kleen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).