[PATCH] kernel/sys: initialize return codes when declaringvariables

From: Davidlohr Bueso
Date: Thu Sep 06 2012 - 19:52:23 EST


Trivially initialize return codes with default values when
the variable is declared.

Signed-off-by: Davidlohr Bueso <dave@xxxxxxx>
---
kernel/sys.c | 9 +++------
1 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/kernel/sys.c b/kernel/sys.c
index 241507f..b3b2ef7 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1364,7 +1364,7 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)

SYSCALL_DEFINE2(sethostname, char __user *, name, int, len)
{
- int errno;
+ int errno = -EFAULT;
char tmp[__NEW_UTS_LEN];

if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
@@ -1373,7 +1373,6 @@ SYSCALL_DEFINE2(sethostname, char __user *, name, int, len)
if (len < 0 || len > __NEW_UTS_LEN)
return -EINVAL;
down_write(&uts_sem);
- errno = -EFAULT;
if (!copy_from_user(tmp, name, len)) {
struct new_utsname *u = utsname();

@@ -1390,7 +1389,7 @@ SYSCALL_DEFINE2(sethostname, char __user *, name, int, len)

SYSCALL_DEFINE2(gethostname, char __user *, name, int, len)
{
- int i, errno;
+ int i, errno = 0;
struct new_utsname *u;

if (len < 0)
@@ -1400,7 +1399,6 @@ SYSCALL_DEFINE2(gethostname, char __user *, name, int, len)
i = 1 + strlen(u->nodename);
if (i > len)
i = len;
- errno = 0;
if (copy_to_user(name, u->nodename, i))
errno = -EFAULT;
up_read(&uts_sem);
@@ -1415,7 +1413,7 @@ SYSCALL_DEFINE2(gethostname, char __user *, name, int, len)
*/
SYSCALL_DEFINE2(setdomainname, char __user *, name, int, len)
{
- int errno;
+ int errno = -EFAULT;
char tmp[__NEW_UTS_LEN];

if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
@@ -1424,7 +1422,6 @@ SYSCALL_DEFINE2(setdomainname, char __user *, name, int, len)
return -EINVAL;

down_write(&uts_sem);
- errno = -EFAULT;
if (!copy_from_user(tmp, name, len)) {
struct new_utsname *u = utsname();

--
1.7.5.4



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/