mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daniel J Blueman <daniel@numascale.com>
To: Joe Perches <joe@perches.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>,
	x86@kernel.org, linux-kernel@vger.kernel.org,
	Steffen Persvold <sp@numascale.com>
Subject: Re: [PATCH] x86: Fix earlyprintk ttyS2/3
Date: Tue, 07 Apr 2015 23:00:38 +0800	[thread overview]
Message-ID: <1428418838.21947.0@cpanel21.proisp.no> (raw)
In-Reply-To: <1428417548.20888.105.camel@perches.com>

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];
 		}

-- 


  reply	other threads:[~2015-04-07 15:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-07 14:29 Daniel J Blueman
2015-04-07 14:39 ` Joe Perches
2015-04-07 15:00   ` Daniel J Blueman [this message]
2015-04-07 14:45 ` Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1428418838.21947.0@cpanel21.proisp.no \
    --to=daniel@numascale.com \
    --cc=hpa@zytor.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=sp@numascale.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome