* [PATCH] x86: Fix earlyprintk ttyS2/3 @ 2015-04-07 14:29 Daniel J Blueman 2015-04-07 14:39 ` Joe Perches 2015-04-07 14:45 ` Ingo Molnar 0 siblings, 2 replies; 4+ messages in thread From: Daniel J Blueman @ 2015-04-07 14:29 UTC (permalink / raw) To: H. Peter Anvin, Thomas Gleixner, Ingo Molnar Cc: x86, linux-kernel, Steffen Persvold, Daniel J Blueman Quite a few platforms use ttyS2 for their serial-over-LAN, so fix early printk support for ttyS2 and 3, avoiding the need to hard-code the IO port. Signed-off-by: Daniel J Blueman <daniel@numascale.com> --- arch/x86/boot/early_serial_console.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/x86/boot/early_serial_console.c b/arch/x86/boot/early_serial_console.c index 5df2869..4f4c2e6 100644 --- a/arch/x86/boot/early_serial_console.c +++ b/arch/x86/boot/early_serial_console.c @@ -71,15 +71,16 @@ static void parse_earlyprintk(void) else pos = e - arg; } else if (!strncmp(arg + pos, "ttyS", 4)) { - static const int bases[] = { 0x3f8, 0x2f8 }; - int idx = 0; + static const int bases[] = {0x3f8, 0x2f8, 0x3e8, 0x2e8}; + unsigned idx = 0; if (!strncmp(arg + pos, "ttyS", 4)) pos += 4; - if (arg[pos++] == '1') - idx = 1; + if ((arg[pos] - '0') < (sizeof(bases) / sizeof(bases[0]))) + idx = arg[pos] - '0'; + pos++; port = bases[idx]; } -- 2.1.0 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] x86: Fix earlyprintk ttyS2/3 2015-04-07 14:29 [PATCH] x86: Fix earlyprintk ttyS2/3 Daniel J Blueman @ 2015-04-07 14:39 ` Joe Perches 2015-04-07 15:00 ` Daniel J Blueman 2015-04-07 14:45 ` Ingo Molnar 1 sibling, 1 reply; 4+ messages in thread From: Joe Perches @ 2015-04-07 14:39 UTC (permalink / raw) To: Daniel J Blueman Cc: H. Peter Anvin, Thomas Gleixner, Ingo Molnar, x86, linux-kernel, Steffen Persvold On Tue, 2015-04-07 at 22:29 +0800, Daniel J Blueman wrote: > Quite a few platforms use ttyS2 for their serial-over-LAN, so fix early > printk support for ttyS2 and 3, avoiding the need to hard-code the IO port. [] > diff --git a/arch/x86/boot/early_serial_console.c b/arch/x86/boot/early_serial_console.c [] > @@ -71,15 +71,16 @@ static void parse_earlyprintk(void) > else > pos = e - arg; > } else if (!strncmp(arg + pos, "ttyS", 4)) { > - static const int bases[] = { 0x3f8, 0x2f8 }; > - int idx = 0; > + static const int bases[] = {0x3f8, 0x2f8, 0x3e8, 0x2e8}; > + unsigned idx = 0; > > if (!strncmp(arg + pos, "ttyS", 4)) > pos += 4; > > - if (arg[pos++] == '1') > - idx = 1; > + if ((arg[pos] - '0') < (sizeof(bases) / sizeof(bases[0]))) > + idx = arg[pos] - '0'; This doesn't prevent negative indexing in case someone does something like shift key typo "ttyS!" for "ttyS1". I've done that. ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] x86: Fix earlyprintk ttyS2/3 2015-04-07 14:39 ` Joe Perches @ 2015-04-07 15:00 ` Daniel J Blueman 0 siblings, 0 replies; 4+ messages in thread From: Daniel J Blueman @ 2015-04-07 15:00 UTC (permalink / raw) To: Joe Perches Cc: H. Peter Anvin, Thomas Gleixner, Ingo Molnar, x86, linux-kernel, Steffen Persvold On Tue, Apr 7, 2015 at 10:39 PM, Joe Perches <joe@perches.com> wrote: > On Tue, 2015-04-07 at 22:29 +0800, Daniel J Blueman wrote: >> Quite a few platforms use ttyS2 for their serial-over-LAN, so fix >> early >> printk support for ttyS2 and 3, avoiding the need to hard-code the >> IO port. > [] >> diff --git a/arch/x86/boot/early_serial_console.c >> b/arch/x86/boot/early_serial_console.c > [] >> @@ -71,15 +71,16 @@ static void parse_earlyprintk(void) >> else >> pos = e - arg; >> } else if (!strncmp(arg + pos, "ttyS", 4)) { >> - static const int bases[] = { 0x3f8, 0x2f8 }; >> - int idx = 0; >> + static const int bases[] = {0x3f8, 0x2f8, 0x3e8, 0x2e8}; >> + unsigned idx = 0; >> >> if (!strncmp(arg + pos, "ttyS", 4)) >> pos += 4; >> >> - if (arg[pos++] == '1') >> - idx = 1; >> + if ((arg[pos] - '0') < (sizeof(bases) / sizeof(bases[0]))) >> + idx = arg[pos] - '0'; > > This doesn't prevent negative indexing in case someone > does something like shift key typo "ttyS!" for "ttyS1". > > I've done that. Gah; late night coding syndrome. Adding the missing cast in the first case only: Subject: [PATCH v2] x86: Fix earlyprintk ttyS2/3 Quite a few platforms use ttyS2 for their serial-over-LAN, so fix early printk support for ttyS2 and 3, avoiding the need to hard-code the IO port. v2: Add missing unsigned cast to correct range check Signed-off-by: Daniel J Blueman <daniel@numascale.com> --- arch/x86/boot/early_serial_console.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/x86/boot/early_serial_console.c b/arch/x86/boot/early_serial_console.c index 5df2869..3d7f112 100644 --- a/arch/x86/boot/early_serial_console.c +++ b/arch/x86/boot/early_serial_console.c @@ -71,15 +71,16 @@ static void parse_earlyprintk(void) else pos = e - arg; } else if (!strncmp(arg + pos, "ttyS", 4)) { - static const int bases[] = { 0x3f8, 0x2f8 }; + static const int bases[] = {0x3f8, 0x2f8, 0x3e8, 0x2e8}; int idx = 0; if (!strncmp(arg + pos, "ttyS", 4)) pos += 4; - if (arg[pos++] == '1') - idx = 1; + if ((unsigned)(arg[pos] - '0') < (sizeof(bases) / sizeof(bases[0]))) + idx = arg[pos] - '0'; + pos++; port = bases[idx]; } -- ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] x86: Fix earlyprintk ttyS2/3 2015-04-07 14:29 [PATCH] x86: Fix earlyprintk ttyS2/3 Daniel J Blueman 2015-04-07 14:39 ` Joe Perches @ 2015-04-07 14:45 ` Ingo Molnar 1 sibling, 0 replies; 4+ messages in thread From: Ingo Molnar @ 2015-04-07 14:45 UTC (permalink / raw) To: Daniel J Blueman Cc: H. Peter Anvin, Thomas Gleixner, Ingo Molnar, x86, linux-kernel, Steffen Persvold * Daniel J Blueman <daniel@numascale.com> wrote: > Quite a few platforms use ttyS2 for their serial-over-LAN, so fix early > printk support for ttyS2 and 3, avoiding the need to hard-code the IO port. Nice. > > Signed-off-by: Daniel J Blueman <daniel@numascale.com> > --- > arch/x86/boot/early_serial_console.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/arch/x86/boot/early_serial_console.c b/arch/x86/boot/early_serial_console.c > index 5df2869..4f4c2e6 100644 > --- a/arch/x86/boot/early_serial_console.c > +++ b/arch/x86/boot/early_serial_console.c > @@ -71,15 +71,16 @@ static void parse_earlyprintk(void) > else > pos = e - arg; > } else if (!strncmp(arg + pos, "ttyS", 4)) { > - static const int bases[] = { 0x3f8, 0x2f8 }; > - int idx = 0; > + static const int bases[] = {0x3f8, 0x2f8, 0x3e8, 0x2e8}; > + unsigned idx = 0; > > if (!strncmp(arg + pos, "ttyS", 4)) > pos += 4; Btw., that's a weird pattern: why do the strncmp() twice? We already know that we matched, in this branch. Could be written as: pos += 4; ? > > - if (arg[pos++] == '1') > - idx = 1; > + if ((arg[pos] - '0') < (sizeof(bases) / sizeof(bases[0]))) > + idx = arg[pos] - '0'; Nit: use ARRAY_SIZE()? Not so nit: with your change, a typo in boot parameters like "ttyS-" would underflow the index and dereference randomly around bases[] with a negative index: Also, higher indices like "ttyS4" will overflow beyond the end of the array. Please add proper bounds checking and warning messages. > > + pos++; > port = bases[idx]; > } Thanks, Ingo ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-04-07 15:00 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2015-04-07 14:29 [PATCH] x86: Fix earlyprintk ttyS2/3 Daniel J Blueman 2015-04-07 14:39 ` Joe Perches 2015-04-07 15:00 ` Daniel J Blueman 2015-04-07 14:45 ` Ingo Molnar
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox