mirror of https://gitee.com/openkylin/linux.git
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: Vegard Nossum <vegard.nossum@gmail.com> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Acked-by: "Serge E. Hallyn" <serue@us.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
8798881507
commit
9679e4dd62
20
kernel/sys.c
20
kernel/sys.c
|
@ -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)
|
||||||
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)
|
||||||
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);
|
||||||
|
|
Loading…
Reference in New Issue