From e8da821ba8aac627b9e07ba2dec42af2fcd587d1 Mon Sep 17 00:00:00 2001 From: Jianxiong Pan Date: Fri, 15 Feb 2019 20:07:42 +0800 Subject: [PATCH] printk: fix print_time bug when run dmesg [1/1] 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 --- kernel/printk/printk.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 8e236155157c..b8002bc6655c 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -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] ",