sys: remove unnecesscary parameter of set_one_prio
PATCH 1/4 sys: remove unnecesscary parameter of set_one_prio
--- kernel/sys.c | 12 +++++------- 1 files changed, 5 insertions(+), 7 deletions(-)
kernel/sys.c +5 -7
@@ -151,9 +151,9 @@ static bool set_one_prio_perm(struct task_struct *p)* set the priority of a task * - the caller must hold the RCU read lock */ -static int set_one_prio (struct task_struct *p,int niceval,int error) +static int set_one_prio (struct task_struct *p,int niceval) { -int no_nice; +int no_nice, error =0 ;if (!set_one_prio_perm (p)) { error = -EPERM ;
@@ -168,8 +168,6 @@ static int set_one_prio(struct task_struct *p, int niceval, int error) error = no_nice; goto out; } -if (error == -ESRCH ) - error =0 ;set_user_nice (p, niceval); out:return error;
@@ -203,7 +201,7 @@ SYSCALL_DEFINE3(setpriority, int, which, int, who, int, niceval)else p = current;if (p) - error =set_one_prio (p, niceval, error); + error =set_one_prio (p, niceval);break ;case PRIO_PGRP :if (who)
@@ -211,7 +209,7 @@ SYSCALL_DEFINE3(setpriority, int, which, int, who, int, niceval)else pgrp =task_pgrp (current); do_each_pid_thread(pgrp, PIDTYPE_PGID, p) { - error =set_one_prio (p, niceval, error); + error =set_one_prio (p, niceval); }while_each_pid_thread (pgrp,PIDTYPE_PGID , p);break ;case PRIO_USER :
@@ -225,7 +223,7 @@ SYSCALL_DEFINE3(setpriority, int, which, int, who, int, niceval) do_each_thread(g, p) {if (uid_eq (task_uid (p), uid)) - error =set_one_prio (p, niceval, error); + error =set_one_prio (p, niceval); }while_each_thread (g, p);if (!uid_eq (uid, cred->uid))free_uid (user);/* For find_user() */
Signature · 1 line
1.7.2.5
PATCH 2/4 sys: remove kernel_shutdown_prepare's parameter
kernel_shutdown_prepare's parameter can be removed by checking global 'system_state', so, maybe we can save a register to be used :-).
--- kernel/sys.c | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)
kernel/sys.c +6 -5
@@ -382,11 +382,10 @@ void kernel_restart(char *cmd) }EXPORT_SYMBOL_GPL (kernel_restart); -static void kernel_shutdown_prepare (enum system_states state) +static void kernel_shutdown_prepare (void ) {blocking_notifier_call_chain (&reboot_notifier_list, - (state ==SYSTEM_HALT )?SYS_HALT :SYS_POWER_OFF ,NULL ); - system_state = state; + (system_state ==SYSTEM_HALT )?SYS_HALT :SYS_POWER_OFF ,NULL );usermodehelper_disable ();device_shutdown (); }
@@ -397,7 +396,7 @@ static void kernel_shutdown_prepare(enum system_states state)*/ void kernel_halt (void ) { -kernel_shutdown_prepare (SYSTEM_HALT ); +kernel_shutdown_prepare ();disable_nonboot_cpus ();syscore_shutdown ();printk (KERN_EMERG "System halted.\n" );
@@ -414,7 +413,7 @@ EXPORT_SYMBOL_GPL(kernel_halt);*/ void kernel_power_off (void ) { -kernel_shutdown_prepare (SYSTEM_POWER_OFF ); +kernel_shutdown_prepare ();if (pm_power_off_prepare)pm_power_off_prepare ();disable_nonboot_cpus ();
@@ -484,11 +483,13 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,break ;case LINUX_REBOOT_CMD_HALT : + system_state =SYSTEM_HALT ;kernel_halt ();do_exit (0 );panic ("cannot halt" );case LINUX_REBOOT_CMD_POWER_OFF : + system_state =SYSTEM_POWER_OFF ;kernel_power_off ();do_exit (0 );break ;
Signature · 1 line
1.7.2.5
Re: [PATCH 2/4] sys: remove kernel_shutdown_prepare's parameter
Quoted 42 lines · On Thu, 30 May 2013 15:58:04 +0800 liguang <[email protected]> wrote:
kernel_shutdown_prepare's parameter can be removed by checking global '
system_state', so, maybe we can save a register to be used :-).kernel/sys.c +4
-5@@ -382,11 +382,10 @@ void kernel_restart(char *cmd) }EXPORT_SYMBOL_GPL (kernel_restart); -static void kernel_shutdown_prepare (enum system_states state) +static void kernel_shutdown_prepare (void ) {blocking_notifier_call_chain (&reboot_notifier_list, - (state ==SYSTEM_HALT )?SYS_HALT :SYS_POWER_OFF ,NULL ); - system_state = state; + (system_state ==SYSTEM_HALT )?SYS_HALT :SYS_POWER_OFF ,NULL );usermodehelper_disable ();device_shutdown (); }@@ -397,7 +396,7 @@ static void kernel_shutdown_prepare(enum system_states state)*/ void kernel_halt (void ) { -kernel_shutdown_prepare (SYSTEM_HALT ); +kernel_shutdown_prepare ();disable_nonboot_cpus ();syscore_shutdown ();printk (KERN_EMERG "System halted.\n" );@@ -414,7 +413,7 @@ EXPORT_SYMBOL_GPL(kernel_halt);*/ void kernel_power_off (void ) { -kernel_shutdown_prepare (SYSTEM_POWER_OFF ); +kernel_shutdown_prepare ();if (pm_power_off_prepare)pm_power_off_prepare ();disable_nonboot_cpus ();@@ -484,11 +483,13 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,break ;case LINUX_REBOOT_CMD_HALT :
kernel/sys.c SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd, · line 495
Quoted 10 lines
kernel/sys.c +2
-0+ system_state =SYSTEM_HALT ;kernel_halt ();do_exit (0 );panic ("cannot halt" );case LINUX_REBOOT_CMD_POWER_OFF : + system_state =SYSTEM_POWER_OFF ;kernel_power_off ();do_exit (0 );break ;
No, this changes behavior for all other callers of kernel_halt() and kernel_power_off(): system_state will no longer be updated for those callers.
And passing an argument via a global variable is not nice :(
PATCH 3/4 sys/reboot: boolize C_A_D
In reply to liguang--- include/linux/reboot.h | 2 +- kernel/sys.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)
include/linux/reboot.h +1 -1
@@ -35,7 +35,7 @@ extern void kernel_restart(char *cmd);extern void kernel_halt (void );extern void kernel_power_off (void ); -extern int C_A_D ;/* for sysctl */ +extern bool C_A_D ;/* for sysctl */ void ctrl_alt_del (void );#define POWEROFF_CMD_PATH_LEN 256
kernel/sys.c +3 -3
@@ -119,7 +119,7 @@ EXPORT_SYMBOL(fs_overflowgid);* this indicates whether you can reboot with ctrl-alt-del: the default is yes */ -int C_A_D =1 ; +bool C_A_D = true;struct pid *cad_pid;EXPORT_SYMBOL (cad_pid);
@@ -475,11 +475,11 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,break ;case LINUX_REBOOT_CMD_CAD_ON : -C_A_D =1 ; +C_A_D = true;break ;case LINUX_REBOOT_CMD_CAD_OFF : -C_A_D =0 ; +C_A_D = false;break ;case LINUX_REBOOT_CMD_HALT :
Signature · 1 line
1.7.2.5
Re: [PATCH 3/4] sys/reboot: boolize C_A_D
include/linux/reboot.h extern void kernel_restart(char *cmd); · line 39
Quoted 9 lines · On Thu, 30 May 2013 15:58:05 +0800 liguang <[email protected]> wrote:
include/linux/reboot.h +1
-1@@ -35,7 +35,7 @@ extern void kernel_restart(char *cmd);extern void kernel_halt (void );extern void kernel_power_off (void ); -extern int C_A_D ;/* for sysctl */ +extern bool C_A_D ;/* for sysctl */ void ctrl_alt_del (void );
This means that the pointer in kernel/sysctl.c:kern_table.data now points at a bool but is declared to have size sizeof(int).
That happens to work with current gcc verions, but there's no rule which states that sizeof(bool) must equal sizeof(int).
And I'm not sure that changing kern_table to use sizeof(bool) is really worth all the bother.
Re: [PATCH 3/4] sys/reboot: boolize C_A_D
Quoted 15 lines · 在 2013-05-31五的 16:02 -0700,Andrew Morton写道:
include/linux/reboot.h extern void kernel_restart(char *cmd); · line 39
Quoted 9 lines · On Thu, 30 May 2013 15:58:05 +0800 liguang <[email protected]> wrote:
include/linux/reboot.h +1
-1@@ -35,7 +35,7 @@ extern void kernel_restart(char *cmd);extern void kernel_halt (void );extern void kernel_power_off (void ); -extern int C_A_D ;/* for sysctl */ +extern bool C_A_D ;/* for sysctl */ void ctrl_alt_del (void );This means that the pointer in kernel/sysctl.c:kern_table.data now points at a bool but is declared to have size sizeof(int).
Quoted 5 lines
That happens to work with current gcc verions, but there's no rule which states that sizeof(bool) must equal sizeof(int).
And I'm not sure that changing
kern_tableto use sizeof(bool) is really worth all the bother.
OK, got it,
Thanks!
Re: [PATCH 3/4] sys/reboot: boolize C_A_D
In reply to Andrew MortonQuoted 2 lines · Andrew Morton
there's no rule
which states that sizeof(bool) must equal sizeof(int).
For gcc, sizeof(_Bool) isn't sizeof(int) so it would work for one endian but not the other.
gcc has sizeof(_Bool) == sizeof(unsigned char)
PATCH 4/4 sys: fix malformed panic massage of reboot
In reply to liguangif LINUX_REBOOT_CMD_HALT for reboot failed,
message "cannot halt" will stay in same line
with next message, so append a '\n' for it.
--- kernel/sys.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/sys.c +1 -1
@@ -486,7 +486,7 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd, system_state =SYSTEM_HALT ;kernel_halt ();do_exit (0 ); -panic ("cannot halt" ); +panic ("cannot halt.\n" );case LINUX_REBOOT_CMD_POWER_OFF : system_state =SYSTEM_POWER_OFF ;
Signature · 1 line
1.7.2.5
On Thu, 2013-05-30 at 15:58 +0800, liguang wrote:
[]
kernel/sys.c
Quoted 1 line
kernel/sys.c +0
-0
[]
kernel/sys.c static bool set_one_prio_perm(struct task_struct *p) · line 154
Quoted 2 lines
kernel/sys.c +1
-1-static int set_one_prio (struct task_struct *p,int niceval,int error) +static int set_one_prio (struct task_struct *p,int niceval)
Umm, error is forwarded through do_each loops.
Are you sure you can do this without
changing any return code behaviors?
[]
Quoted 18 lines
kernel/sys.c +2
-2@@ -211,7 +209,7 @@ SYSCALL_DEFINE3(setpriority, int, which, int, who, int, niceval)else pgrp =task_pgrp (current); do_each_pid_thread(pgrp, PIDTYPE_PGID, p) { - error =set_one_prio (p, niceval, error); + error =set_one_prio (p, niceval); }while_each_pid_thread (pgrp,PIDTYPE_PGID , p);break ;case PRIO_USER :@@ -225,7 +223,7 @@ SYSCALL_DEFINE3(setpriority, int, which, int, who, int, niceval) do_each_thread(g, p) {if (uid_eq (task_uid (p), uid)) - error =set_one_prio (p, niceval, error); + error =set_one_prio (p, niceval); }while_each_thread (g, p);if (!uid_eq (uid, cred->uid))free_uid (user);/* For find_user() */
Quoted 11 lines · On Thu, 30 May 2013 01:08:25 -0700 Joe Perches <[email protected]> wrote:
On Thu, 2013-05-30 at 15:58 +0800, liguang wrote:
[]kernel/sys.c
Quoted 1 line
kernel/sys.c +0
-0[]
kernel/sys.c static bool set_one_prio_perm(struct task_struct *p) · line 154
Quoted 2 lines
kernel/sys.c +1
-1-static int set_one_prio (struct task_struct *p,int niceval,int error) +static int set_one_prio (struct task_struct *p,int niceval)Umm, error is forwarded through
do_eachloops.Are you sure you can do this without
changing any return code behaviors?
yes, you're right. The first time around, -ESRCH gets rewritten to 0 and the zero propagates, as long as nobody hits an error which isn't -ESRCH. I'm not sure this was the most straightforward possible implementation :(
Quoted 49 lines · On Thu, 30 May 2013 15:58:03 +0800 liguang <[email protected]> wrote:
Signed-off-by liguang <[email protected]>--- kernel/sys.c | 12 +++++------- 1 files changed, 5 insertions(+), 7 deletions(-)kernel/sys.c +4
-6@@ -151,9 +151,9 @@ static bool set_one_prio_perm(struct task_struct *p)* set the priority of a task * - the caller must hold the RCU read lock */ -static int set_one_prio (struct task_struct *p,int niceval,int error) +static int set_one_prio (struct task_struct *p,int niceval) { -int no_nice; +int no_nice, error =0 ;if (!set_one_prio_perm (p)) { error = -EPERM ;@@ -168,8 +168,6 @@ static int set_one_prio(struct task_struct *p, int niceval, int error) error = no_nice; goto out; } -if (error == -ESRCH ) - error =0 ;set_user_nice (p, niceval); out:return error;@@ -203,7 +201,7 @@ SYSCALL_DEFINE3(setpriority, int, which, int, who, int, niceval)else p = current;if (p) - error =set_one_prio (p, niceval, error); + error =set_one_prio (p, niceval);break ;case PRIO_PGRP :if (who)@@ -211,7 +209,7 @@ SYSCALL_DEFINE3(setpriority, int, which, int, who, int, niceval)else pgrp =task_pgrp (current); do_each_pid_thread(pgrp, PIDTYPE_PGID, p) { - error =set_one_prio (p, niceval, error); + error =set_one_prio (p, niceval); }while_each_pid_thread (pgrp,PIDTYPE_PGID , p);break ;case PRIO_USER :
kernel/sys.c SYSCALL_DEFINE3(setpriority, int, which, int, who, int, niceval) · line 229
Quoted 8 lines
kernel/sys.c +1
-1@@ -225,7 +223,7 @@ SYSCALL_DEFINE3(setpriority, int, which, int, who, int, niceval) do_each_thread(g, p) {if (uid_eq (task_uid (p), uid)) - error =set_one_prio (p, niceval, error); + error =set_one_prio (p, niceval); }while_each_thread (g, p);if (!uid_eq (uid, cred->uid))free_uid (user);/* For find_user() */
Yes, that apepars to be an evuivalent change, but only because security_task_setnice() cannot return -ESRCH. The existing code is rather awkward.
A couple of changes:
From: Andrew Morton <[email protected]>
Subject: kernel-sysc-remove-unnecessary-parameter-of-set_one_prio-fix
clean up definitions, remove unneeded assignment
---
kernel/sys.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/sys.c renamed from kernel/sys.c~kernel-sysc-remove-unnecessary-parameter-of-set_one_prio-fix +2 -2
@@ -153,7 +153,8 @@ static bool set_one_prio_perm(struct tas*/ static int set_one_prio (struct task_struct *p,int niceval) { -int no_nice, error =0 ; +int no_nice; +int error =0 ;if (!set_one_prio_perm (p)) { error = -EPERM ;
@@ -186,7 +187,6 @@ SYSCALL_DEFINE3(setpriority, int, which, goto out;/* normalize: avoid signed division (rounding problems) */ - error = -ESRCH ;if (niceval <-20 ) niceval =-20 ;if (niceval >19 )
_