printk: fix print_time bug when run dmesg [1/1]
authorJianxiong Pan <jianxiong.pan@amlogic.com>
Fri, 15 Feb 2019 12:07:42 +0000 (20:07 +0800)
committerJianxin Pan <jianxin.pan@amlogic.com>
Mon, 25 Feb 2019 06:21:41 +0000 (22:21 -0800)
PD#SWPL-4900

Problem:
printk_prefix() passes NULL buf to print_time() to get the length of
the time prefix; when printk times are enable, the current code just
return "snprint(NULL, 0, "[%5lu.000000]", (unsigned long)ts)"
but in the SMP case, we add cpu core id at the end of time prefix, the
format is "[%5lu, %06lu@%d]", this gives a wrong size(shorter).

this will make buf get out of boundary, when run dmesg.

Solution:
replace [%5lu.000000] with [%5lu.000000@0]

Verify:
g12a-u200

Change-Id: Ic74b9f466b5af5aac7e6569a1afc7a46d9594050
Signed-off-by: Jianxiong Pan <jianxiong.pan@amlogic.com>
kernel/printk/printk.c

index 8e23615..b8002bc 100644 (file)
@@ -1194,7 +1194,11 @@ static size_t print_time(u64 ts, char *buf)
        rem_nsec = do_div(ts, 1000000000);
 
        if (!buf)
+#ifdef CONFIG_AMLOGIC_MODIFY
+               return snprintf(NULL, 0, "[%5lu.000000@0] ", (unsigned long)ts);
+#else
                return snprintf(NULL, 0, "[%5lu.000000] ", (unsigned long)ts);
+#endif
 
 #if defined(CONFIG_SMP) && defined(CONFIG_AMLOGIC_DRIVER)
        return sprintf(buf, "[%5lu.%06lu@%d] ",