Skip to content

Commit 077a1cc

Browse files
Nikitas Angelinaspmladek
authored andcommitted
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 <[email protected]> Cc: [email protected] Signed-off-by: Nikitas Angelinas <[email protected]> Reviewed-by: Sergey Senozhatsky <[email protected]> Signed-off-by: Petr Mladek <[email protected]>
1 parent 5a81423 commit 077a1cc

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

kernel/printk/printk.c

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,28 +1435,24 @@ int do_syslog(int type, char __user *buf, int len, int source)
14351435

14361436
error = check_syslog_permissions(type, source);
14371437
if (error)
1438-
goto out;
1438+
return error;
14391439

14401440
switch (type) {
14411441
case SYSLOG_ACTION_CLOSE: /* Close log */
14421442
break;
14431443
case SYSLOG_ACTION_OPEN: /* Open log */
14441444
break;
14451445
case SYSLOG_ACTION_READ: /* Read from log */
1446-
error = -EINVAL;
14471446
if (!buf || len < 0)
1448-
goto out;
1449-
error = 0;
1447+
return -EINVAL;
14501448
if (!len)
1451-
goto out;
1452-
if (!access_ok(VERIFY_WRITE, buf, len)) {
1453-
error = -EFAULT;
1454-
goto out;
1455-
}
1449+
return 0;
1450+
if (!access_ok(VERIFY_WRITE, buf, len))
1451+
return -EFAULT;
14561452
error = wait_event_interruptible(log_wait,
14571453
syslog_seq != log_next_seq);
14581454
if (error)
1459-
goto out;
1455+
return error;
14601456
error = syslog_print(buf, len);
14611457
break;
14621458
/* Read/clear last kernel messages */
@@ -1465,16 +1461,12 @@ int do_syslog(int type, char __user *buf, int len, int source)
14651461
/* FALL THRU */
14661462
/* Read last kernel messages */
14671463
case SYSLOG_ACTION_READ_ALL:
1468-
error = -EINVAL;
14691464
if (!buf || len < 0)
1470-
goto out;
1471-
error = 0;
1465+
return -EINVAL;
14721466
if (!len)
1473-
goto out;
1474-
if (!access_ok(VERIFY_WRITE, buf, len)) {
1475-
error = -EFAULT;
1476-
goto out;
1477-
}
1467+
return 0;
1468+
if (!access_ok(VERIFY_WRITE, buf, len))
1469+
return -EFAULT;
14781470
error = syslog_print_all(buf, len, clear);
14791471
break;
14801472
/* Clear ring buffer */
@@ -1496,15 +1488,13 @@ int do_syslog(int type, char __user *buf, int len, int source)
14961488
break;
14971489
/* Set level of messages printed to console */
14981490
case SYSLOG_ACTION_CONSOLE_LEVEL:
1499-
error = -EINVAL;
15001491
if (len < 1 || len > 8)
1501-
goto out;
1492+
return -EINVAL;
15021493
if (len < minimum_console_loglevel)
15031494
len = minimum_console_loglevel;
15041495
console_loglevel = len;
15051496
/* Implicitly re-enable logging to console */
15061497
saved_console_loglevel = LOGLEVEL_DEFAULT;
1507-
error = 0;
15081498
break;
15091499
/* Number of chars in the log buffer */
15101500
case SYSLOG_ACTION_SIZE_UNREAD:
@@ -1526,7 +1516,6 @@ int do_syslog(int type, char __user *buf, int len, int source)
15261516
u64 seq = syslog_seq;
15271517
u32 idx = syslog_idx;
15281518

1529-
error = 0;
15301519
while (seq < log_next_seq) {
15311520
struct printk_log *msg = log_from_idx(idx);
15321521

@@ -1546,7 +1535,7 @@ int do_syslog(int type, char __user *buf, int len, int source)
15461535
error = -EINVAL;
15471536
break;
15481537
}
1549-
out:
1538+
15501539
return error;
15511540
}
15521541

0 commit comments

Comments
 (0)