Commit 9679e4dd authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

kernel/sys.c: improve code generation

utsname() is quite expensive to calculate.  Cache it in a local.

          text    data     bss     dec     hex filename
before:  11136     720      16   11872    2e60 kernel/sys.o
after:   11096     720      16   11832    2e38 kernel/sys.o
Acked-by: default avatarVegard Nossum <vegard.nossum@gmail.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Acked-by: default avatar"Serge E. Hallyn" <serue@us.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 87988815
...@@ -1349,9 +1349,10 @@ asmlinkage long sys_sethostname(char __user *name, int len) ...@@ -1349,9 +1349,10 @@ asmlinkage long sys_sethostname(char __user *name, int len)
down_write(&uts_sem); down_write(&uts_sem);
errno = -EFAULT; errno = -EFAULT;
if (!copy_from_user(tmp, name, len)) { if (!copy_from_user(tmp, name, len)) {
memcpy(utsname()->nodename, tmp, len); struct new_utsname *u = utsname();
memset(utsname()->nodename + len, 0,
sizeof(utsname()->nodename) - len); memcpy(u->nodename, tmp, len);
memset(u->nodename + len, 0, sizeof(u->nodename) - len);
errno = 0; errno = 0;
} }
up_write(&uts_sem); up_write(&uts_sem);
...@@ -1363,15 +1364,17 @@ asmlinkage long sys_sethostname(char __user *name, int len) ...@@ -1363,15 +1364,17 @@ asmlinkage long sys_sethostname(char __user *name, int len)
asmlinkage long sys_gethostname(char __user *name, int len) asmlinkage long sys_gethostname(char __user *name, int len)
{ {
int i, errno; int i, errno;
struct new_utsname *u;
if (len < 0) if (len < 0)
return -EINVAL; return -EINVAL;
down_read(&uts_sem); down_read(&uts_sem);
i = 1 + strlen(utsname()->nodename); u = utsname();
i = 1 + strlen(u->nodename);
if (i > len) if (i > len)
i = len; i = len;
errno = 0; errno = 0;
if (copy_to_user(name, utsname()->nodename, i)) if (copy_to_user(name, u->nodename, i))
errno = -EFAULT; errno = -EFAULT;
up_read(&uts_sem); up_read(&uts_sem);
return errno; return errno;
...@@ -1396,9 +1399,10 @@ asmlinkage long sys_setdomainname(char __user *name, int len) ...@@ -1396,9 +1399,10 @@ asmlinkage long sys_setdomainname(char __user *name, int len)
down_write(&uts_sem); down_write(&uts_sem);
errno = -EFAULT; errno = -EFAULT;
if (!copy_from_user(tmp, name, len)) { if (!copy_from_user(tmp, name, len)) {
memcpy(utsname()->domainname, tmp, len); struct new_utsname *u = utsname();
memset(utsname()->domainname + len, 0,
sizeof(utsname()->domainname) - len); memcpy(u->domainname, tmp, len);
memset(u->domainname + len, 0, sizeof(u->domainname) - len);
errno = 0; errno = 0;
} }
up_write(&uts_sem); up_write(&uts_sem);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment