aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/printk/printk.c
diff options
context:
space:
mode:
authorTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>2018-12-11 04:49:05 -0500
committerPetr Mladek <pmladek@suse.com>2018-12-12 05:21:14 -0500
commit07c17732bd687567802aaa5fa5c101c2776565d1 (patch)
tree275be05af0872ec5ab06592d9a3a12ddd0868b90 /kernel/printk/printk.c
parente80c1a9d5f514ce5134c6c4263a11607341466c9 (diff)
printk: Remove print_prefix() calls with NULL buffer.
We can save lines/size by removing print_prefix() with buf == NULL. This patch makes no functional change. Link: http://lkml.kernel.org/r/1544521745-11925-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp To: Steven Rostedt <rostedt@goodmis.org> Cc: linux-kernel@vger.kernel.org Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Signed-off-by: Petr Mladek <pmladek@suse.com>
Diffstat (limited to 'kernel/printk/printk.c')
-rw-r--r--kernel/printk/printk.c39
1 files changed, 14 insertions, 25 deletions
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index c7d217764db3..91db332ccf4d 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1228,13 +1228,15 @@ static inline void boot_delay_msec(int level)
1228static bool printk_time = IS_ENABLED(CONFIG_PRINTK_TIME); 1228static bool printk_time = IS_ENABLED(CONFIG_PRINTK_TIME);
1229module_param_named(time, printk_time, bool, S_IRUGO | S_IWUSR); 1229module_param_named(time, printk_time, bool, S_IRUGO | S_IWUSR);
1230 1230
1231static size_t print_syslog(unsigned int level, char *buf)
1232{
1233 return sprintf(buf, "<%u>", level);
1234}
1235
1231static size_t print_time(u64 ts, char *buf) 1236static size_t print_time(u64 ts, char *buf)
1232{ 1237{
1233 unsigned long rem_nsec = do_div(ts, 1000000000); 1238 unsigned long rem_nsec = do_div(ts, 1000000000);
1234 1239
1235 if (!buf)
1236 return snprintf(NULL, 0, "[%5lu.000000] ", (unsigned long)ts);
1237
1238 return sprintf(buf, "[%5lu.%06lu] ", 1240 return sprintf(buf, "[%5lu.%06lu] ",
1239 (unsigned long)ts, rem_nsec / 1000); 1241 (unsigned long)ts, rem_nsec / 1000);
1240} 1242}
@@ -1243,24 +1245,11 @@ static size_t print_prefix(const struct printk_log *msg, bool syslog,
1243 bool time, char *buf) 1245 bool time, char *buf)
1244{ 1246{
1245 size_t len = 0; 1247 size_t len = 0;
1246 unsigned int prefix = (msg->facility << 3) | msg->level;
1247
1248 if (syslog) {
1249 if (buf) {
1250 len += sprintf(buf, "<%u>", prefix);
1251 } else {
1252 len += 3;
1253 if (prefix > 999)
1254 len += 3;
1255 else if (prefix > 99)
1256 len += 2;
1257 else if (prefix > 9)
1258 len++;
1259 }
1260 }
1261 1248
1249 if (syslog)
1250 len = print_syslog((msg->facility << 3) | msg->level, buf);
1262 if (time) 1251 if (time)
1263 len += print_time(msg->ts_nsec, buf ? buf + len : NULL); 1252 len += print_time(msg->ts_nsec, buf + len);
1264 return len; 1253 return len;
1265} 1254}
1266 1255
@@ -1270,6 +1259,8 @@ static size_t msg_print_text(const struct printk_log *msg, bool syslog,
1270 const char *text = log_text(msg); 1259 const char *text = log_text(msg);
1271 size_t text_size = msg->text_len; 1260 size_t text_size = msg->text_len;
1272 size_t len = 0; 1261 size_t len = 0;
1262 char prefix[PREFIX_MAX];
1263 const size_t prefix_len = print_prefix(msg, syslog, time, prefix);
1273 1264
1274 do { 1265 do {
1275 const char *next = memchr(text, '\n', text_size); 1266 const char *next = memchr(text, '\n', text_size);
@@ -1284,19 +1275,17 @@ static size_t msg_print_text(const struct printk_log *msg, bool syslog,
1284 } 1275 }
1285 1276
1286 if (buf) { 1277 if (buf) {
1287 if (print_prefix(msg, syslog, time, NULL) + 1278 if (prefix_len + text_len + 1 >= size - len)
1288 text_len + 1 >= size - len)
1289 break; 1279 break;
1290 1280
1291 len += print_prefix(msg, syslog, time, buf + len); 1281 memcpy(buf + len, prefix, prefix_len);
1282 len += prefix_len;
1292 memcpy(buf + len, text, text_len); 1283 memcpy(buf + len, text, text_len);
1293 len += text_len; 1284 len += text_len;
1294 buf[len++] = '\n'; 1285 buf[len++] = '\n';
1295 } else { 1286 } else {
1296 /* SYSLOG_ACTION_* buffer size only calculation */ 1287 /* SYSLOG_ACTION_* buffer size only calculation */
1297 len += print_prefix(msg, syslog, time, NULL); 1288 len += prefix_len + text_len + 1;
1298 len += text_len;
1299 len++;
1300 } 1289 }
1301 1290
1302 text = next; 1291 text = next;