* [PATCH] init: Fix printk format strings
@ 2007-10-11 6:17 Vegard Nossum
2007-10-11 15:40 ` Randy Dunlap
2007-10-11 17:21 ` Johannes Weiner
0 siblings, 2 replies; 8+ messages in thread
From: Vegard Nossum @ 2007-10-11 6:17 UTC (permalink / raw)
To: trivial; +Cc: linux-kernel
This makes sure printk format strings are string literals containing no
more than a single line.
Signed-off-by: Vegard Nossum <vegard.nossum@gmail.com>
---
init/calibrate.c | 4 +++-
init/do_mounts_initrd.c | 5 ++++-
init/main.c | 2 +-
3 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/init/calibrate.c b/init/calibrate.c
index 40ff3b4..2a35718 100644
--- a/init/calibrate.c
+++ b/init/calibrate.c
@@ -98,7 +98,9 @@ static unsigned long __devinit calibrate_delay_direct(void)
return (good_tsc_sum/good_tsc_count);
printk(KERN_WARNING "calibrate_delay_direct() failed to get a good "
- "estimate for loops_per_jiffy.\nProbably due to long platform interrupts. Consider using \"lpj=\" boot option.\n");
+ "estimate for loops_per_jiffy.\n");
+ printk(KERN_WARNING "Probably due to long platform interrupts. "
+ "Consider using \"lpj=\" boot option.\n");
return 0;
}
#else
diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
index fd4fc12..ad6174c 100644
--- a/init/do_mounts_initrd.c
+++ b/init/do_mounts_initrd.c
@@ -98,7 +98,10 @@ static void __init handle_initrd(void)
error = sys_ioctl(fd, BLKFLSBUF, 0);
sys_close(fd);
}
- printk(!error ? "okay\n" : "failed\n");
+ if(error)
+ printk("failed\n");
+ else
+ printk("okay\n");
}
}
diff --git a/init/main.c b/init/main.c
index 9def935..5491bba 100644
--- a/init/main.c
+++ b/init/main.c
@@ -537,7 +537,7 @@ asmlinkage void __init start_kernel(void)
boot_cpu_init();
page_address_init();
printk(KERN_NOTICE);
- printk(linux_banner);
+ printk("%s", linux_banner);
setup_arch(&command_line);
setup_command_line(command_line);
unwind_setup();
--
1.5.2.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] init: Fix printk format strings
2007-10-11 6:17 [PATCH] init: Fix printk format strings Vegard Nossum
@ 2007-10-11 15:40 ` Randy Dunlap
2007-10-11 15:55 ` Vegard Nossum
2007-10-11 17:21 ` Johannes Weiner
1 sibling, 1 reply; 8+ messages in thread
From: Randy Dunlap @ 2007-10-11 15:40 UTC (permalink / raw)
To: Vegard Nossum; +Cc: trivial, linux-kernel
On Thu, 11 Oct 2007 08:17:02 +0200 Vegard Nossum wrote:
> This makes sure printk format strings are string literals containing no
> more than a single line.
Each patch needs justification (unless it is blatantly obvious).
> Signed-off-by: Vegard Nossum <vegard.nossum@gmail.com>
> ---
> init/calibrate.c | 4 +++-
> init/do_mounts_initrd.c | 5 ++++-
> init/main.c | 2 +-
> 3 files changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
> index fd4fc12..ad6174c 100644
> --- a/init/do_mounts_initrd.c
> +++ b/init/do_mounts_initrd.c
> @@ -98,7 +98,10 @@ static void __init handle_initrd(void)
> error = sys_ioctl(fd, BLKFLSBUF, 0);
> sys_close(fd);
> }
> - printk(!error ? "okay\n" : "failed\n");
> + if(error)
> + printk("failed\n");
> + else
> + printk("okay\n");
> }
> }
Why this one?
and if it must change, use:
if (error)
but I see little need for the change.
---
~Randy
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] init: Fix printk format strings
2007-10-11 15:40 ` Randy Dunlap
@ 2007-10-11 15:55 ` Vegard Nossum
2007-10-11 16:01 ` Randy Dunlap
0 siblings, 1 reply; 8+ messages in thread
From: Vegard Nossum @ 2007-10-11 15:55 UTC (permalink / raw)
To: Randy Dunlap; +Cc: trivial, linux-kernel
On 10/11/07, Randy Dunlap <randy.dunlap@oracle.com> wrote:
> On Thu, 11 Oct 2007 08:17:02 +0200 Vegard Nossum wrote:
>
> > This makes sure printk format strings are string literals containing no
> > more than a single line.
>
> Each patch needs justification (unless it is blatantly obvious).
>
>
> > Signed-off-by: Vegard Nossum <vegard.nossum@gmail.com>
> > ---
> > init/calibrate.c | 4 +++-
> > init/do_mounts_initrd.c | 5 ++++-
> > init/main.c | 2 +-
> > 3 files changed, 8 insertions(+), 3 deletions(-)
> >
> > diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
> > index fd4fc12..ad6174c 100644
> > --- a/init/do_mounts_initrd.c
> > +++ b/init/do_mounts_initrd.c
> > @@ -98,7 +98,10 @@ static void __init handle_initrd(void)
> > error = sys_ioctl(fd, BLKFLSBUF, 0);
> > sys_close(fd);
> > }
> > - printk(!error ? "okay\n" : "failed\n");
> > + if(error)
> > + printk("failed\n");
> > + else
> > + printk("okay\n");
> > }
> > }
>
> Why this one?
> and if it must change, use:
> if (error)
> but I see little need for the change.
Oops about the space. And it's to make the format string a constant
literal. If it isn't, you are going to run into trouble with options
to remove printks at compile-time based on log-level token. I realize
it's not really an issue at this point in time, but I assume that it
will eventually make its way into the kernel in some way or another.
Vegard
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] init: Fix printk format strings
2007-10-11 15:55 ` Vegard Nossum
@ 2007-10-11 16:01 ` Randy Dunlap
2007-10-11 16:09 ` Vegard Nossum
0 siblings, 1 reply; 8+ messages in thread
From: Randy Dunlap @ 2007-10-11 16:01 UTC (permalink / raw)
To: Vegard Nossum; +Cc: trivial, linux-kernel
On Thu, 11 Oct 2007 17:55:16 +0200 Vegard Nossum wrote:
> On 10/11/07, Randy Dunlap <randy.dunlap@oracle.com> wrote:
> > On Thu, 11 Oct 2007 08:17:02 +0200 Vegard Nossum wrote:
> >
> > > This makes sure printk format strings are string literals containing no
> > > more than a single line.
> >
> > Each patch needs justification (unless it is blatantly obvious).
> >
> >
> > > Signed-off-by: Vegard Nossum <vegard.nossum@gmail.com>
> > > ---
> > > init/calibrate.c | 4 +++-
> > > init/do_mounts_initrd.c | 5 ++++-
> > > init/main.c | 2 +-
> > > 3 files changed, 8 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
> > > index fd4fc12..ad6174c 100644
> > > --- a/init/do_mounts_initrd.c
> > > +++ b/init/do_mounts_initrd.c
> > > @@ -98,7 +98,10 @@ static void __init handle_initrd(void)
> > > error = sys_ioctl(fd, BLKFLSBUF, 0);
> > > sys_close(fd);
> > > }
> > > - printk(!error ? "okay\n" : "failed\n");
> > > + if(error)
> > > + printk("failed\n");
> > > + else
> > > + printk("okay\n");
> > > }
> > > }
> >
> > Why this one?
> > and if it must change, use:
> > if (error)
> > but I see little need for the change.
>
> Oops about the space. And it's to make the format string a constant
> literal. If it isn't, you are going to run into trouble with options
> to remove printks at compile-time based on log-level token. I realize
> it's not really an issue at this point in time, but I assume that it
> will eventually make its way into the kernel in some way or another.
so would this be OK?
printk("%s\n", error ? "failed" : "okay");
---
~Randy
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] init: Fix printk format strings
2007-10-11 16:01 ` Randy Dunlap
@ 2007-10-11 16:09 ` Vegard Nossum
2007-10-11 16:20 ` Randy Dunlap
0 siblings, 1 reply; 8+ messages in thread
From: Vegard Nossum @ 2007-10-11 16:09 UTC (permalink / raw)
To: Randy Dunlap; +Cc: trivial, linux-kernel
On 10/11/07, Randy Dunlap <randy.dunlap@oracle.com> wrote:
> On Thu, 11 Oct 2007 17:55:16 +0200 Vegard Nossum wrote:
>
> > On 10/11/07, Randy Dunlap <randy.dunlap@oracle.com> wrote:
> > > On Thu, 11 Oct 2007 08:17:02 +0200 Vegard Nossum wrote:
> > >
> > > > This makes sure printk format strings are string literals containing no
> > > > more than a single line.
> > >
> > > Each patch needs justification (unless it is blatantly obvious).
> > >
> > >
> > > > Signed-off-by: Vegard Nossum <vegard.nossum@gmail.com>
> > > > ---
> > > > init/calibrate.c | 4 +++-
> > > > init/do_mounts_initrd.c | 5 ++++-
> > > > init/main.c | 2 +-
> > > > 3 files changed, 8 insertions(+), 3 deletions(-)
> > > >
> > > > diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
> > > > index fd4fc12..ad6174c 100644
> > > > --- a/init/do_mounts_initrd.c
> > > > +++ b/init/do_mounts_initrd.c
> > > > @@ -98,7 +98,10 @@ static void __init handle_initrd(void)
> > > > error = sys_ioctl(fd, BLKFLSBUF, 0);
> > > > sys_close(fd);
> > > > }
> > > > - printk(!error ? "okay\n" : "failed\n");
> > > > + if(error)
> > > > + printk("failed\n");
> > > > + else
> > > > + printk("okay\n");
> > > > }
> > > > }
> > >
> > > Why this one?
> > > and if it must change, use:
> > > if (error)
> > > but I see little need for the change.
> >
> > Oops about the space. And it's to make the format string a constant
> > literal. If it isn't, you are going to run into trouble with options
> > to remove printks at compile-time based on log-level token. I realize
> > it's not really an issue at this point in time, but I assume that it
> > will eventually make its way into the kernel in some way or another.
>
> so would this be OK?
>
> printk("%s\n", error ? "failed" : "okay");
It helps the filtering, but it doesn't help localisation very much, I
think. Since for that, you'd only translate the format string, which
in this case isn't much to translate. (I do realize that this is a
very, very tiny part of the kernel and probably hundreds of other
call-sites have much worse problems -- but every little helps, and now
that you're at it... :-))
Vegard
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] init: Fix printk format strings
2007-10-11 16:09 ` Vegard Nossum
@ 2007-10-11 16:20 ` Randy Dunlap
0 siblings, 0 replies; 8+ messages in thread
From: Randy Dunlap @ 2007-10-11 16:20 UTC (permalink / raw)
To: Vegard Nossum; +Cc: trivial, linux-kernel
On Thu, 11 Oct 2007 18:09:47 +0200 Vegard Nossum wrote:
> On 10/11/07, Randy Dunlap <randy.dunlap@oracle.com> wrote:
> > On Thu, 11 Oct 2007 17:55:16 +0200 Vegard Nossum wrote:
> >
> > > On 10/11/07, Randy Dunlap <randy.dunlap@oracle.com> wrote:
> > > > On Thu, 11 Oct 2007 08:17:02 +0200 Vegard Nossum wrote:
> > > >
> > > > > This makes sure printk format strings are string literals containing no
> > > > > more than a single line.
> > > >
> > > > Each patch needs justification (unless it is blatantly obvious).
> > > >
> > > >
> > > > > Signed-off-by: Vegard Nossum <vegard.nossum@gmail.com>
> > > > > ---
> > > > > init/calibrate.c | 4 +++-
> > > > > init/do_mounts_initrd.c | 5 ++++-
> > > > > init/main.c | 2 +-
> > > > > 3 files changed, 8 insertions(+), 3 deletions(-)
> > > > >
> > > > > diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
> > > > > index fd4fc12..ad6174c 100644
> > > > > --- a/init/do_mounts_initrd.c
> > > > > +++ b/init/do_mounts_initrd.c
> > > > > @@ -98,7 +98,10 @@ static void __init handle_initrd(void)
> > > > > error = sys_ioctl(fd, BLKFLSBUF, 0);
> > > > > sys_close(fd);
> > > > > }
> > > > > - printk(!error ? "okay\n" : "failed\n");
> > > > > + if(error)
> > > > > + printk("failed\n");
> > > > > + else
> > > > > + printk("okay\n");
> > > > > }
> > > > > }
> > > >
> > > > Why this one?
> > > > and if it must change, use:
> > > > if (error)
> > > > but I see little need for the change.
> > >
> > > Oops about the space. And it's to make the format string a constant
> > > literal. If it isn't, you are going to run into trouble with options
> > > to remove printks at compile-time based on log-level token. I realize
> > > it's not really an issue at this point in time, but I assume that it
> > > will eventually make its way into the kernel in some way or another.
> >
> > so would this be OK?
> >
> > printk("%s\n", error ? "failed" : "okay");
>
> It helps the filtering, but it doesn't help localisation very much, I
> think. Since for that, you'd only translate the format string, which
> in this case isn't much to translate. (I do realize that this is a
> very, very tiny part of the kernel and probably hundreds of other
> call-sites have much worse problems -- but every little helps, and now
> that you're at it... :-))
Oh well.
I find the proposed changes too restrictive, practically changing
a stream-oriented output into a variable-length block-oriented output.
---
~Randy
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] init: Fix printk format strings
2007-10-11 6:17 [PATCH] init: Fix printk format strings Vegard Nossum
2007-10-11 15:40 ` Randy Dunlap
@ 2007-10-11 17:21 ` Johannes Weiner
2007-10-11 19:15 ` Vegard Nossum
1 sibling, 1 reply; 8+ messages in thread
From: Johannes Weiner @ 2007-10-11 17:21 UTC (permalink / raw)
To: Vegard Nossum; +Cc: trivial, linux-kernel
Hi,
On Thu, Oct 11, 2007 at 08:17:02AM +0200, Vegard Nossum wrote:
> This makes sure printk format strings are string literals containing no
> more than a single line.
Perhaps you should write _why_ one-line printk()s are even needed, with
profound reasons instead of constantly talking about mysterious later changes
that you will propose any time soon.
Hannes
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] init: Fix printk format strings
2007-10-11 17:21 ` Johannes Weiner
@ 2007-10-11 19:15 ` Vegard Nossum
0 siblings, 0 replies; 8+ messages in thread
From: Vegard Nossum @ 2007-10-11 19:15 UTC (permalink / raw)
To: Johannes Weiner; +Cc: linux-kernel
On 10/11/07, Johannes Weiner <hannes-kernel@saeurebad.de> wrote:
> On Thu, Oct 11, 2007 at 08:17:02AM +0200, Vegard Nossum wrote:
> > This makes sure printk format strings are string literals containing no
> > more than a single line.
>
> Perhaps you should write _why_ one-line printk()s are even needed, with
> profound reasons instead of constantly talking about mysterious later changes
> that you will propose any time soon.
In short, the reason for disallowing multiple lines per call is that
printk() will be less complex, while not really changing the
complexity of the callers (a change in the code, yes, but the changes
are trivial, and, actually, not that many).
I think I see now, though, that my changes will not gain support if I
do not lift this restriction.
You can find my current "mysterious later changes" as patches, with
descriptions, at this address: http://folk.uio.no/vegardno/xprintf/
Thanks for the tip, though. I am quite new to the kernel business, so
bear with me :)
Kind regards,
Vegard Nossum
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2007-10-11 19:15 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-11 6:17 [PATCH] init: Fix printk format strings Vegard Nossum
2007-10-11 15:40 ` Randy Dunlap
2007-10-11 15:55 ` Vegard Nossum
2007-10-11 16:01 ` Randy Dunlap
2007-10-11 16:09 ` Vegard Nossum
2007-10-11 16:20 ` Randy Dunlap
2007-10-11 17:21 ` Johannes Weiner
2007-10-11 19:15 ` Vegard Nossum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox