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 <[email protected]>
---
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

Reply via email to