Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754528AbbDGPA5 (ORCPT ); Tue, 7 Apr 2015 11:00:57 -0400 Received: from numascale.com ([213.162.240.84]:44877 "EHLO numascale.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754448AbbDGPAy (ORCPT ); Tue, 7 Apr 2015 11:00:54 -0400 Date: Tue, 07 Apr 2015 23:00:38 +0800 From: Daniel J Blueman Subject: Re: [PATCH] x86: Fix earlyprintk ttyS2/3 To: Joe Perches Cc: "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , x86@kernel.org, linux-kernel@vger.kernel.org, Steffen Persvold Message-Id: <1428418838.21947.0@cpanel21.proisp.no> In-Reply-To: <1428417548.20888.105.camel@perches.com> References: <1428417548.20888.105.camel@perches.com> X-Mailer: geary/0.8.3 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - cpanel21.proisp.no X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - numascale.com X-Get-Message-Sender-Via: cpanel21.proisp.no: authenticated_id: daniel@numascale.com X-Source: X-Source-Args: X-Source-Dir: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2525 Lines: 80 On Tue, Apr 7, 2015 at 10:39 PM, Joe Perches 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 --- 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]; } -- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/