Commit 249771b8 authored by Alex Elder's avatar Alex Elder Committed by Linus Torvalds

printk: miscellaneous cleanups

Some small cleanups to kernel/printk/printk.c.  None of them should
cause any change in behavior.

  - When CONFIG_PRINTK is defined, parenthesize the value of LOG_LINE_MAX.
  - When CONFIG_PRINTK is *not* defined, there is an extra LOG_LINE_MAX
    definition; delete it.
  - Pull an assignment out of a conditional expression in console_setup().
  - Use isdigit() in console_setup() rather than open coding it.
  - In update_console_cmdline(), drop a NUL-termination assignment;
    the strlcpy() call that precedes it guarantees it's not needed.
  - Simplify some logic in printk_timed_ratelimit().
Signed-off-by: default avatarAlex Elder <elder@linaro.org>
Reviewed-by: default avatarPetr Mladek <pmladek@suse.cz>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Jan Kara <jack@suse.cz>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent e99aa461
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include <linux/poll.h> #include <linux/poll.h>
#include <linux/irq_work.h> #include <linux/irq_work.h>
#include <linux/utsname.h> #include <linux/utsname.h>
#include <linux/ctype.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
...@@ -257,7 +258,7 @@ static u64 clear_seq; ...@@ -257,7 +258,7 @@ static u64 clear_seq;
static u32 clear_idx; static u32 clear_idx;
#define PREFIX_MAX 32 #define PREFIX_MAX 32
#define LOG_LINE_MAX 1024 - PREFIX_MAX #define LOG_LINE_MAX (1024 - PREFIX_MAX)
/* record buffer */ /* record buffer */
#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
...@@ -1835,7 +1836,7 @@ EXPORT_SYMBOL(printk); ...@@ -1835,7 +1836,7 @@ EXPORT_SYMBOL(printk);
#define LOG_LINE_MAX 0 #define LOG_LINE_MAX 0
#define PREFIX_MAX 0 #define PREFIX_MAX 0
#define LOG_LINE_MAX 0
static u64 syslog_seq; static u64 syslog_seq;
static u32 syslog_idx; static u32 syslog_idx;
static u64 console_seq; static u64 console_seq;
...@@ -1936,7 +1937,8 @@ static int __init console_setup(char *str) ...@@ -1936,7 +1937,8 @@ static int __init console_setup(char *str)
strncpy(buf, str, sizeof(buf) - 1); strncpy(buf, str, sizeof(buf) - 1);
} }
buf[sizeof(buf) - 1] = 0; buf[sizeof(buf) - 1] = 0;
if ((options = strchr(str, ',')) != NULL) options = strchr(str, ',');
if (options)
*(options++) = 0; *(options++) = 0;
#ifdef __sparc__ #ifdef __sparc__
if (!strcmp(str, "ttya")) if (!strcmp(str, "ttya"))
...@@ -1945,7 +1947,7 @@ static int __init console_setup(char *str) ...@@ -1945,7 +1947,7 @@ static int __init console_setup(char *str)
strcpy(buf, "ttyS1"); strcpy(buf, "ttyS1");
#endif #endif
for (s = buf; *s; s++) for (s = buf; *s; s++)
if ((*s >= '0' && *s <= '9') || *s == ',') if (isdigit(*s) || *s == ',')
break; break;
idx = simple_strtoul(s, NULL, 10); idx = simple_strtoul(s, NULL, 10);
*s = 0; *s = 0;
...@@ -1984,7 +1986,6 @@ int update_console_cmdline(char *name, int idx, char *name_new, int idx_new, cha ...@@ -1984,7 +1986,6 @@ int update_console_cmdline(char *name, int idx, char *name_new, int idx_new, cha
i++, c++) i++, c++)
if (strcmp(c->name, name) == 0 && c->index == idx) { if (strcmp(c->name, name) == 0 && c->index == idx) {
strlcpy(c->name, name_new, sizeof(c->name)); strlcpy(c->name, name_new, sizeof(c->name));
c->name[sizeof(c->name) - 1] = 0;
c->options = options; c->options = options;
c->index = idx_new; c->index = idx_new;
return i; return i;
...@@ -2652,14 +2653,13 @@ EXPORT_SYMBOL(__printk_ratelimit); ...@@ -2652,14 +2653,13 @@ EXPORT_SYMBOL(__printk_ratelimit);
bool printk_timed_ratelimit(unsigned long *caller_jiffies, bool printk_timed_ratelimit(unsigned long *caller_jiffies,
unsigned int interval_msecs) unsigned int interval_msecs)
{ {
if (*caller_jiffies == 0 unsigned long elapsed = jiffies - *caller_jiffies;
|| !time_in_range(jiffies, *caller_jiffies,
*caller_jiffies if (*caller_jiffies && elapsed <= msecs_to_jiffies(interval_msecs))
+ msecs_to_jiffies(interval_msecs))) { return false;
*caller_jiffies = jiffies;
return true; *caller_jiffies = jiffies;
} return true;
return false;
} }
EXPORT_SYMBOL(printk_timed_ratelimit); EXPORT_SYMBOL(printk_timed_ratelimit);
......
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