printk: remove some dead code
PATCH 1/1 printk: remove some dead code
Static checkers complain about the impossible condition here.
In 084681d14e ('printk: flush continuation lines immediately to console'), we changed msg->level from being a u16 to being an unsigned 3 bit bitfield. That means we can remove the code here to handle log levels which are in the tens or hundreds column.
kernel/printk.c +2 -7
@@ -822,15 +822,10 @@ static size_t print_prefix(const struct log *msg, bool syslog, char *buf)size_t len =0 ;if (syslog) { -if (buf) { +if (buf) len +=sprintf (buf,"<%u>" , msg->level); - }else { +else len +=3 ; -if (msg->level >9 ) - len++; -if (msg->level >99 ) - len++; - } } len +=print_time (msg->ts_nsec, buf ? buf + len :NULL );
Quoted 6 lines · Dan Carpenter
Static checkers complain about the impossible condition here.
In
084681d14e('printk: flush continuation lines immediately to console'), we changedmsg->levelfrom being a u16 to being an unsigned 3 bit bitfield. That means we can remove the code here to handle log levels which are in the tens or hundreds column.
We should do that for the facility value, now that level is split up in separate fields. I'll prepare a fix.
Thanks,
Kay
Quoted 10 lines · Kay Sievers
Quoted 6 lines · Dan Carpenter
Static checkers complain about the impossible condition here.
In
084681d14e('printk: flush continuation lines immediately to console'), we changedmsg->levelfrom being a u16 to being an unsigned 3 bit bitfield. That means we can remove the code here to handle log levels which are in the tens or hundreds column.We should do that for the facility value, now that level is split up in separate fields. I'll prepare a fix.
Here it is. Nice tool, very useful.
Thanks again,
Kay
From: Kay Sievers <[email protected]>
Subject: kmsg: add the facility number to the syslog prefix
After the recent split of facility and level into separate variables, we miss the facility value (always 0 for kernel-originated messages) in the syslog prefix.
Quoted 5 lines · Dan Carpenter
Static checkers complain about the impossible condition here.
In
084681d14e('printk: flush continuation lines immediately to console'), we changedmsg->levelfrom being a u16 to being an unsigned 3 bit bitfield.
--- kernel/printk.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
kernel/printk.c +4 -3
@@ -818,15 +818,16 @@ static size_t print_time(u64 ts, char *bstatic size_t print_prefix (const struct log *msg,bool syslog,char *buf) {size_t len =0 ; +unsigned int prefix = (msg->facility <<3 ) | msg->level;if (syslog) {if (buf) { - len +=sprintf (buf,"<%u>" , msg->level); + len +=sprintf (buf,"<%u>" , prefix); }else { len +=3 ; -if (msg->level >9 ) +if (prefix >9 ) len++; -if (msg->level >99 ) +if (prefix >99 ) len++; } }
Am 03.07.2012 19:59, schrieb Kay Sievers:
Quoted 52 lines · Kay Sievers
Quoted 10 lines · Dan Carpenter
Quoted 6 lines
Static checkers complain about the impossible condition here.
In
084681d14e('printk: flush continuation lines immediately to console'), we changedmsg->levelfrom being a u16 to being an unsigned 3 bit bitfield. That means we can remove the code here to handle log levels which are in the tens or hundreds column.We should do that for the facility value, now that level is split up in separate fields. I'll prepare a fix.
Here it is. Nice tool, very useful.
Thanks again,
KayFrom: Kay Sievers <[email protected]>
Subject: kmsg: add the facility number to the syslog prefixAfter the recent split of facility and level into separate variables, we miss the facility value (always 0 for kernel-originated messages) in the syslog prefix.
Quoted 5 lines · Dan Carpenter
Static checkers complain about the impossible condition here.
In
084681d14e('printk: flush continuation lines immediately to console'), we changedmsg->levelfrom being a u16 to being an unsigned 3 bit bitfield.Cc Dan Carpenter <[email protected]>Signed-off-by Kay Sievers <[email protected]>--- kernel/printk.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)kernel/printk.c +2
-1@@ -818,15 +818,16 @@ static size_t print_time(u64 ts, char *bstatic size_t print_prefix (const struct log *msg,bool syslog,char *buf) {size_t len =0 ; +unsigned int prefix = (msg->facility <<3 ) | msg->level;if (syslog) {if (buf) { - len +=sprintf (buf,"<%u>" , msg->level); + len +=sprintf (buf,"<%u>" , prefix);
kernel/printk.c static size_t print_time(u64 ts, char *b · line 833
Quoted 10 lines
kernel/printk.c +2
-2}else { len +=3 ; -if (msg->level >9 ) +if (prefix >9 ) len++; -if (msg->level >99 ) +if (prefix >99 ) len++; } }
just for my curiosity: why not len+=5 and forget the rest ?
re,
wh
Quoted 6 lines · walter harms
Quoted 6 lines
kernel/printk.c +1
-2}else { len +=3 ; -if (msg->level >9 ) +if (prefix >9 ) len++; -if (msg->level >99 )
Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +1
-0+ if (prefix > 99) len++; } }just for my curiosity: why not len+=5 and forget the rest ?
It's a possibly multi-digit decimal number, and the length should be actual length not the maximum.
Kay