2014-01-27 18:12:17

by Heinrich Schuchardt

[permalink] [raw]
Subject: [PATCH 1/1] __init setup_early_printk: missing initialization

From: Heinrich Schuchardt <[email protected]>

If is based on uninitialized value keep_early.
This leads to unpredictable result.

Signed-off-by: Heinrich Schuchardt <[email protected]>
---
arch/unicore32/kernel/early_printk.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/unicore32/kernel/early_printk.c b/arch/unicore32/kernel/early_printk.c
index 9be0d5d..460a3b6 100644
--- a/arch/unicore32/kernel/early_printk.c
+++ b/arch/unicore32/kernel/early_printk.c
@@ -35,7 +35,7 @@ static struct console early_ocd_console = {

static int __init setup_early_printk(char *buf)
{
- int keep_early;
+ int keep_early = 0;

if (!buf || early_console)
return 0;
--
1.7.10.4


2014-01-27 21:50:03

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH 1/1] __init setup_early_printk: missing initialization

On Mon, 27 Jan 2014 19:10:24 +0100 [email protected] wrote:

> From: Heinrich Schuchardt <[email protected]>
>
> If is based on uninitialized value keep_early.
> This leads to unpredictable result.
>
> ...
>
> --- a/arch/unicore32/kernel/early_printk.c
> +++ b/arch/unicore32/kernel/early_printk.c
> @@ -35,7 +35,7 @@ static struct console early_ocd_console = {
>
> static int __init setup_early_printk(char *buf)
> {
> - int keep_early;
> + int keep_early = 0;
>
> if (!buf || early_console)
> return 0;

yup.

But that code is quite overcooked. How about this?

--- a/arch/unicore32/kernel/early_printk.c~arch-unicore32-kernel-early_printkc-setup_early_printk-missing-initialization-fix
+++ a/arch/unicore32/kernel/early_printk.c
@@ -35,17 +35,11 @@ static struct console early_ocd_console

static int __init setup_early_printk(char *buf)
{
- int keep_early = 0;
-
if (!buf || early_console)
return 0;

- if (strstr(buf, "keep"))
- keep_early = 1;
-
early_console = &early_ocd_console;
-
- if (keep_early)
+ if (strstr(buf, "keep"))
early_console->flags &= ~CON_BOOT;
else
early_console->flags |= CON_BOOT;
_

2014-01-27 22:59:00

by Heinrich Schuchardt

[permalink] [raw]
Subject: Re: [PATCH 1/1] __init setup_early_printk: missing initialization

On 27.01.2014 22:49, Andrew Morton wrote:
> On Mon, 27 Jan 2014 19:10:24 +0100 [email protected] wrote:
>
>> From: Heinrich Schuchardt <[email protected]>
>>
>> If is based on uninitialized value keep_early.
>> This leads to unpredictable result.
>>
>> ...
>>
>> --- a/arch/unicore32/kernel/early_printk.c
>> +++ b/arch/unicore32/kernel/early_printk.c
>> @@ -35,7 +35,7 @@ static struct console early_ocd_console = {
>>
>> static int __init setup_early_printk(char *buf)
>> {
>> - int keep_early;
>> + int keep_early = 0;
>>
>> if (!buf || early_console)
>> return 0;
>
> yup.
>
> But that code is quite overcooked. How about this?
>
> --- a/arch/unicore32/kernel/early_printk.c~arch-unicore32-kernel-early_printkc-setup_early_printk-missing-initialization-fix
> +++ a/arch/unicore32/kernel/early_printk.c
> @@ -35,17 +35,11 @@ static struct console early_ocd_console
>
> static int __init setup_early_printk(char *buf)
> {
> - int keep_early = 0;
> -
> if (!buf || early_console)
> return 0;
>
> - if (strstr(buf, "keep"))
> - keep_early = 1;
> -
> early_console = &early_ocd_console;
> -
> - if (keep_early)
> + if (strstr(buf, "keep"))
> early_console->flags &= ~CON_BOOT;
> else
> early_console->flags |= CON_BOOT;
> _
>
>

Your code is easier to read, and has same functionality.

2014-01-28 08:15:45

by Guan Xuetao

[permalink] [raw]
Subject: 回复: Re: [PATCH 1/ 1] __init setup_e arly_printk: missing initialization

Thanks.

Acked-by: Xuetao Guan <[email protected]>

----- Andrew Morton <[email protected]> 写道:
> On Mon, 27 Jan 2014 19:10:24 +0100 [email protected] wrote:
>
> > From: Heinrich Schuchardt <[email protected]>
> >
> > If is based on uninitialized value keep_early.
> > This leads to unpredictable result.
> >
> > ...
> >
> > --- a/arch/unicore32/kernel/early_printk.c
> > +++ b/arch/unicore32/kernel/early_printk.c
> > @@ -35,7 +35,7 @@ static struct console early_ocd_console = {
> >
> > static int __init setup_early_printk(char *buf)
> > {
> > - int keep_early;
> > + int keep_early = 0;
> >
> > if (!buf || early_console)
> > return 0;
>
> yup.
>
> But that code is quite overcooked. How about this?
>
> --- a/arch/unicore32/kernel/early_printk.c~arch-unicore32-kernel-early_printkc-setup_early_printk-missing-initialization-fix
> +++ a/arch/unicore32/kernel/early_printk.c
> @@ -35,17 +35,11 @@ static struct console early_ocd_console
>
> static int __init setup_early_printk(char *buf)
> {
> - int keep_early = 0;
> -
> if (!buf || early_console)
> return 0;
>
> - if (strstr(buf, "keep"))
> - keep_early = 1;
> -
> early_console = &early_ocd_console;
> -
> - if (keep_early)
> + if (strstr(buf, "keep"))
> early_console->flags &= ~CON_BOOT;
> else
> early_console->flags |= CON_BOOT;
> _
>