diff options
author | Andrew Morton <akpm@linux-foundation.org> | 2008-10-16 01:01:51 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-10-16 14:21:31 -0400 |
commit | 9679e4dd628743b9ef4375d60ae69923c3766173 (patch) | |
tree | 03d491b6dbcc66079d4015c585f156fc4d94c2ea | |
parent | 87988815073918134c0dae059cf247a4472d78ed (diff) |
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>
-rw-r--r-- | kernel/sys.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/kernel/sys.c b/kernel/sys.c index 558b035965aa..0bc8fa3c2288 100644 --- a/kernel/sys.c +++ b/kernel/sys.c | |||
@@ -1349,9 +1349,10 @@ asmlinkage long sys_sethostname(char __user *name, int len) | |||
1349 | down_write(&uts_sem); | 1349 | down_write(&uts_sem); |
1350 | errno = -EFAULT; | 1350 | errno = -EFAULT; |
1351 | if (!copy_from_user(tmp, name, len)) { | 1351 | if (!copy_from_user(tmp, name, len)) { |
1352 | memcpy(utsname()->nodename, tmp, len); | 1352 | struct new_utsname *u = utsname(); |
1353 | memset(utsname()->nodename + len, 0, | 1353 | |
1354 | sizeof(utsname()->nodename) - len); | 1354 | memcpy(u->nodename, tmp, len); |
1355 | memset(u->nodename + len, 0, sizeof(u->nodename) - len); | ||
1355 | errno = 0; | 1356 | errno = 0; |
1356 | } | 1357 | } |
1357 | up_write(&uts_sem); | 1358 | up_write(&uts_sem); |
@@ -1363,15 +1364,17 @@ asmlinkage long sys_sethostname(char __user *name, int len) | |||
1363 | asmlinkage long sys_gethostname(char __user *name, int len) | 1364 | asmlinkage long sys_gethostname(char __user *name, int len) |
1364 | { | 1365 | { |
1365 | int i, errno; | 1366 | int i, errno; |
1367 | struct new_utsname *u; | ||
1366 | 1368 | ||
1367 | if (len < 0) | 1369 | if (len < 0) |
1368 | return -EINVAL; | 1370 | return -EINVAL; |
1369 | down_read(&uts_sem); | 1371 | down_read(&uts_sem); |
1370 | i = 1 + strlen(utsname()->nodename); | 1372 | u = utsname(); |
1373 | i = 1 + strlen(u->nodename); | ||
1371 | if (i > len) | 1374 | if (i > len) |
1372 | i = len; | 1375 | i = len; |
1373 | errno = 0; | 1376 | errno = 0; |
1374 | if (copy_to_user(name, utsname()->nodename, i)) | 1377 | if (copy_to_user(name, u->nodename, i)) |
1375 | errno = -EFAULT; | 1378 | errno = -EFAULT; |
1376 | up_read(&uts_sem); | 1379 | up_read(&uts_sem); |
1377 | return errno; | 1380 | return errno; |
@@ -1396,9 +1399,10 @@ asmlinkage long sys_setdomainname(char __user *name, int len) | |||
1396 | down_write(&uts_sem); | 1399 | down_write(&uts_sem); |
1397 | errno = -EFAULT; | 1400 | errno = -EFAULT; |
1398 | if (!copy_from_user(tmp, name, len)) { | 1401 | if (!copy_from_user(tmp, name, len)) { |
1399 | memcpy(utsname()->domainname, tmp, len); | 1402 | struct new_utsname *u = utsname(); |
1400 | memset(utsname()->domainname + len, 0, | 1403 | |
1401 | sizeof(utsname()->domainname) - len); | 1404 | memcpy(u->domainname, tmp, len); |
1405 | memset(u->domainname + len, 0, sizeof(u->domainname) - len); | ||
1402 | errno = 0; | 1406 | errno = 0; |
1403 | } | 1407 | } |
1404 | up_write(&uts_sem); | 1408 | up_write(&uts_sem); |