Commit 077a1cc0 authored by Nikitas Angelinas's avatar Nikitas Angelinas Committed by Petr Mladek

printk: Clean up do_syslog() error handling

The error variable in do_syslog() is preemptively set to the error code
before the error condition is checked, and then set to 0 if the error
condition is not encountered. This is not necessary, as it is likely
simpler to return immediately upon encountering the error condition. A
redundant set of the error variable to 0 is also removed.

This patch has been build-tested on x86_64, but not tested for
functionality.

Link: http://lkml.kernel.org/r/20170730033636.GA935@vostro
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: default avatarNikitas Angelinas <nikitas.angelinas@gmail.com>
Reviewed-by: default avatarSergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: default avatarPetr Mladek <pmladek@suse.com>
parent 5a814231
...@@ -1435,7 +1435,7 @@ int do_syslog(int type, char __user *buf, int len, int source) ...@@ -1435,7 +1435,7 @@ int do_syslog(int type, char __user *buf, int len, int source)
error = check_syslog_permissions(type, source); error = check_syslog_permissions(type, source);
if (error) if (error)
goto out; return error;
switch (type) { switch (type) {
case SYSLOG_ACTION_CLOSE: /* Close log */ case SYSLOG_ACTION_CLOSE: /* Close log */
...@@ -1443,20 +1443,16 @@ int do_syslog(int type, char __user *buf, int len, int source) ...@@ -1443,20 +1443,16 @@ int do_syslog(int type, char __user *buf, int len, int source)
case SYSLOG_ACTION_OPEN: /* Open log */ case SYSLOG_ACTION_OPEN: /* Open log */
break; break;
case SYSLOG_ACTION_READ: /* Read from log */ case SYSLOG_ACTION_READ: /* Read from log */
error = -EINVAL;
if (!buf || len < 0) if (!buf || len < 0)
goto out; return -EINVAL;
error = 0;
if (!len) if (!len)
goto out; return 0;
if (!access_ok(VERIFY_WRITE, buf, len)) { if (!access_ok(VERIFY_WRITE, buf, len))
error = -EFAULT; return -EFAULT;
goto out;
}
error = wait_event_interruptible(log_wait, error = wait_event_interruptible(log_wait,
syslog_seq != log_next_seq); syslog_seq != log_next_seq);
if (error) if (error)
goto out; return error;
error = syslog_print(buf, len); error = syslog_print(buf, len);
break; break;
/* Read/clear last kernel messages */ /* Read/clear last kernel messages */
...@@ -1465,16 +1461,12 @@ int do_syslog(int type, char __user *buf, int len, int source) ...@@ -1465,16 +1461,12 @@ int do_syslog(int type, char __user *buf, int len, int source)
/* FALL THRU */ /* FALL THRU */
/* Read last kernel messages */ /* Read last kernel messages */
case SYSLOG_ACTION_READ_ALL: case SYSLOG_ACTION_READ_ALL:
error = -EINVAL;
if (!buf || len < 0) if (!buf || len < 0)
goto out; return -EINVAL;
error = 0;
if (!len) if (!len)
goto out; return 0;
if (!access_ok(VERIFY_WRITE, buf, len)) { if (!access_ok(VERIFY_WRITE, buf, len))
error = -EFAULT; return -EFAULT;
goto out;
}
error = syslog_print_all(buf, len, clear); error = syslog_print_all(buf, len, clear);
break; break;
/* Clear ring buffer */ /* Clear ring buffer */
...@@ -1496,15 +1488,13 @@ int do_syslog(int type, char __user *buf, int len, int source) ...@@ -1496,15 +1488,13 @@ int do_syslog(int type, char __user *buf, int len, int source)
break; break;
/* Set level of messages printed to console */ /* Set level of messages printed to console */
case SYSLOG_ACTION_CONSOLE_LEVEL: case SYSLOG_ACTION_CONSOLE_LEVEL:
error = -EINVAL;
if (len < 1 || len > 8) if (len < 1 || len > 8)
goto out; return -EINVAL;
if (len < minimum_console_loglevel) if (len < minimum_console_loglevel)
len = minimum_console_loglevel; len = minimum_console_loglevel;
console_loglevel = len; console_loglevel = len;
/* Implicitly re-enable logging to console */ /* Implicitly re-enable logging to console */
saved_console_loglevel = LOGLEVEL_DEFAULT; saved_console_loglevel = LOGLEVEL_DEFAULT;
error = 0;
break; break;
/* Number of chars in the log buffer */ /* Number of chars in the log buffer */
case SYSLOG_ACTION_SIZE_UNREAD: case SYSLOG_ACTION_SIZE_UNREAD:
...@@ -1526,7 +1516,6 @@ int do_syslog(int type, char __user *buf, int len, int source) ...@@ -1526,7 +1516,6 @@ int do_syslog(int type, char __user *buf, int len, int source)
u64 seq = syslog_seq; u64 seq = syslog_seq;
u32 idx = syslog_idx; u32 idx = syslog_idx;
error = 0;
while (seq < log_next_seq) { while (seq < log_next_seq) {
struct printk_log *msg = log_from_idx(idx); struct printk_log *msg = log_from_idx(idx);
...@@ -1546,7 +1535,7 @@ int do_syslog(int type, char __user *buf, int len, int source) ...@@ -1546,7 +1535,7 @@ int do_syslog(int type, char __user *buf, int len, int source)
error = -EINVAL; error = -EINVAL;
break; break;
} }
out:
return error; return error;
} }
......
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