* [patch] printk: remove some dead code
@ 2012-07-03 10:45 Dan Carpenter
2012-07-03 11:21 ` Kay Sievers
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Dan Carpenter @ 2012-07-03 10:45 UTC (permalink / raw)
To: Kay Sievers
Cc: Greg Kroah-Hartman, Andrew Morton, Peter Zijlstra, Ingo Molnar,
linux-kernel, kernel-janitors
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.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/kernel/printk.c b/kernel/printk.c
index 660ba72..3edc531 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -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);
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [patch] printk: remove some dead code
2012-07-03 10:45 [patch] printk: remove some dead code Dan Carpenter
@ 2012-07-03 11:21 ` Kay Sievers
2012-07-03 17:59 ` Kay Sievers
2012-07-03 18:43 ` walter harms
2012-07-03 19:34 ` Kay Sievers
2 siblings, 1 reply; 5+ messages in thread
From: Kay Sievers @ 2012-07-03 11:21 UTC (permalink / raw)
To: Dan Carpenter
Cc: Greg Kroah-Hartman, Andrew Morton, Peter Zijlstra, Ingo Molnar,
linux-kernel, kernel-janitors
On Tue, Jul 3, 2012 at 12:45 PM, Dan Carpenter <dan.carpenter@oracle.com> wrote:
> 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.
We should do that for the facility value, now that level is split up
in separate fields. I'll prepare a fix.
Thanks,
Kay
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch] printk: remove some dead code
2012-07-03 11:21 ` Kay Sievers
@ 2012-07-03 17:59 ` Kay Sievers
0 siblings, 0 replies; 5+ messages in thread
From: Kay Sievers @ 2012-07-03 17:59 UTC (permalink / raw)
To: Dan Carpenter
Cc: Greg Kroah-Hartman, Andrew Morton, Peter Zijlstra, Ingo Molnar,
linux-kernel, kernel-janitors
On Tue, 2012-07-03 at 13:21 +0200, Kay Sievers wrote:
> On Tue, Jul 3, 2012 at 12:45 PM, Dan Carpenter <dan.carpenter@oracle.com> wrote:
> > 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.
>
> 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 <kay@vrfy.org>
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.
On Tue, Jul 3, 2012 at 12:45 PM, Dan Carpenter <dan.carpenter@oracle.com> wrote:
> 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.
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Kay Sievers <kay@vrfy.org>
---
kernel/printk.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -818,15 +818,16 @@ static size_t print_time(u64 ts, char *b
static 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++;
}
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch] printk: remove some dead code
2012-07-03 10:45 [patch] printk: remove some dead code Dan Carpenter
2012-07-03 11:21 ` Kay Sievers
@ 2012-07-03 18:43 ` walter harms
2012-07-03 19:34 ` Kay Sievers
2 siblings, 0 replies; 5+ messages in thread
From: walter harms @ 2012-07-03 18:43 UTC (permalink / raw)
To: kernel-janitors
Am 03.07.2012 19:59, schrieb Kay Sievers:
> On Tue, 2012-07-03 at 13:21 +0200, Kay Sievers wrote:
>> On Tue, Jul 3, 2012 at 12:45 PM, Dan Carpenter <dan.carpenter@oracle.com> wrote:
>>> 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.
>>
>> 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 <kay@vrfy.org>
> 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.
>
> On Tue, Jul 3, 2012 at 12:45 PM, Dan Carpenter <dan.carpenter@oracle.com> wrote:
>> 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.
>
> Cc: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Kay Sievers <kay@vrfy.org>
> ---
> kernel/printk.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> --- a/kernel/printk.c
> +++ b/kernel/printk.c
> @@ -818,15 +818,16 @@ static size_t print_time(u64 ts, char *b
> static 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++;
> }
> }
>
>
just for my curiosity: why not len+=5 and forget the rest ?
re,
wh
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch] printk: remove some dead code
2012-07-03 10:45 [patch] printk: remove some dead code Dan Carpenter
2012-07-03 11:21 ` Kay Sievers
2012-07-03 18:43 ` walter harms
@ 2012-07-03 19:34 ` Kay Sievers
2 siblings, 0 replies; 5+ messages in thread
From: Kay Sievers @ 2012-07-03 19:34 UTC (permalink / raw)
To: kernel-janitors
On Tue, 2012-07-03 at 20:43 +0200, walter harms wrote:
> > } 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 ?
It's a possibly multi-digit decimal number, and the length should be
actual length not the maximum.
Kay
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-07-03 19:34 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-03 10:45 [patch] printk: remove some dead code Dan Carpenter
2012-07-03 11:21 ` Kay Sievers
2012-07-03 17:59 ` Kay Sievers
2012-07-03 18:43 ` walter harms
2012-07-03 19:34 ` Kay Sievers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox