[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190731123922.14056-1-geert+renesas@glider.be>
Date: Wed, 31 Jul 2019 14:39:22 +0200
From: Geert Uytterhoeven <geert+renesas@...der.be>
To: Petr Mladek <pmladek@...e.com>,
Sergey Senozhatsky <sergey.senozhatsky@...il.com>
Cc: Steven Rostedt <rostedt@...dmis.org>, linux-kernel@...r.kernel.org,
Geert Uytterhoeven <geert+renesas@...der.be>
Subject: [PATCH] printk: Use strlen/sizeof instead of hardcoded constants
Replace hardcoded string length or size constants by proper strlen() or
sizeof() constructs. As the strings are constant, gcc will reduce the
lengths or sizes to constants again.
Signed-off-by: Geert Uytterhoeven <geert+renesas@...der.be>
---
Assembler output before/after compared: no change in generated code.
---
include/linux/printk.h | 3 +--
kernel/printk/printk.c | 12 ++++++------
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/include/linux/printk.h b/include/linux/printk.h
index cefd374c47b1f88e..9a85d2eb6ff63460 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -77,8 +77,7 @@ static inline void console_verbose(void)
console_loglevel = CONSOLE_LOGLEVEL_MOTORMOUTH;
}
-/* strlen("ratelimit") + 1 */
-#define DEVKMSG_STR_MAX_SIZE 10
+#define DEVKMSG_STR_MAX_SIZE sizeof("ratelimit")
extern char devkmsg_log_str[];
struct ctl_table;
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 1888f6a3b694cb88..e8f332f0ae3595e8 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -121,15 +121,15 @@ static int __control_devkmsg(char *str)
if (!str)
return -EINVAL;
- if (!strncmp(str, "on", 2)) {
+ if (!strncmp(str, "on", strlen("on"))) {
devkmsg_log = DEVKMSG_LOG_MASK_ON;
- return 2;
- } else if (!strncmp(str, "off", 3)) {
+ return strlen("on");
+ } else if (!strncmp(str, "off", strlen("off"))) {
devkmsg_log = DEVKMSG_LOG_MASK_OFF;
- return 3;
- } else if (!strncmp(str, "ratelimit", 9)) {
+ return strlen("off");
+ } else if (!strncmp(str, "ratelimit", strlen("ratelimit"))) {
devkmsg_log = DEVKMSG_LOG_MASK_DEFAULT;
- return 9;
+ return strlen("ratelimit");
}
return -EINVAL;
}
--
2.17.1
Powered by blists - more mailing lists