Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp931492rdg; Wed, 11 Oct 2023 09:17:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHJqE7MADW6ZTKZ4Shybpf3i9nENWd6vMCUjzZZvLaJTpHSAIk8th3lG/cX+f0WDTKh8Za8 X-Received: by 2002:a05:6358:716:b0:143:70a1:afcd with SMTP id e22-20020a056358071600b0014370a1afcdmr21611868rwj.1.1697041067715; Wed, 11 Oct 2023 09:17:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697041067; cv=none; d=google.com; s=arc-20160816; b=TQjJeQsOoJRKSKHOSdAVOUafu2r9YqVFjvHApcGCn4AsmByF5el/YdvkiB9c2yVcj/ avyNOtZOB3AfTHqxD/R2j6N/35oIDcEp7EUZ76FwixRH53oAUQuCzx0b1+UjggqljzYO EE1yVTa3fqTOcOjbYUJXl3Sh8OhcqqCUhoscoL9/+XHwLpvCQr8imc9Pjol96LVNzxmC BK3OiNJxjNz6K2gSpseKLvlj92qPcAwilSrTy0B+bABh9rwiUgOqrEZE1zIHPR9iwIPQ juwtkpqdtIGD1C1WF3ejvel+Tqt0Yv++yQwgbX9yuNgTSChoA1vDDAQiCGiprda1GW5l zPdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=EvgnqGaMtBsDt2iLejaznl3AarVTVJkoIxAuKCuAUCk=; fh=PTad2+bWCqustH66OeJI8xsRVLORxP41REVp2iUefLc=; b=ieeaJPv2Zs6P1oZqygE2MXLN9zeaB7b3oCqYKSrHUKZmqTtuzi8UbUf7u83CiBKUQw qoVgLGCjWrZA/jAdmP7yaKCosRuWqbtyZuBcQeYbBzcga5AuN2wuIt5kgbgHDCpigDC5 0n4gi2W/6uIltaNX3j/zSLFbN0UP65iWsE2m1OkePQl1ThjEroxfu8bNGgejYac6K2DB M/uIraNCsHOHGfOjsqDrt5a2g49/nYUSc5z0ipjHCS4EHCfo/EDciM59qDwbfgUsQZCE 5LnavKWGQebTEpeP5zXeXmwkE08qPACcFekqCL37P39b+BDDpatbdrDQdXQ7g9ZFbzR2 QZiQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id z19-20020a63e113000000b0057d600d2069si101014pgh.418.2023.10.11.09.17.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 09:17:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id C4C69809B450; Wed, 11 Oct 2023 09:17:31 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231495AbjJKQRS (ORCPT + 99 others); Wed, 11 Oct 2023 12:17:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232902AbjJKQRR (ORCPT ); Wed, 11 Oct 2023 12:17:17 -0400 Received: from muru.com (muru.com [72.249.23.125]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B8B40B0 for ; Wed, 11 Oct 2023 09:17:15 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTPS id CC56080E1; Wed, 11 Oct 2023 16:17:14 +0000 (UTC) Date: Wed, 11 Oct 2023 19:17:13 +0300 From: Tony Lindgren To: Petr Mladek Cc: Greg Kroah-Hartman , Steven Rostedt , John Ogness , Sergey Senozhatsky , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/2] printk: Check valid console index for preferred console Message-ID: <20231011161713.GE34982@atomide.com> References: <20231011074330.14487-1-tony@atomide.com> <2023101131-maroon-stubborn-1364@gregkh> <20231011091803.GC34982@atomide.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=2.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 11 Oct 2023 09:17:32 -0700 (PDT) X-Spam-Level: ** * Petr Mladek [231011 15:26]: > On Wed 2023-10-11 12:18:03, Tony Lindgren wrote: > > * Greg Kroah-Hartman [231011 07:53]: > > > On Wed, Oct 11, 2023 at 10:43:25AM +0300, Tony Lindgren wrote: > > > > Let's check for valid console index values to avoid bogus console index > > > > numbers from kernel command line. While struct console uses short for > > > > index, and negative index values are used by some device drivers, we do > > > > not want to allow negative values for preferred console. > > > > > > What drivers use a negative index for the console? > > > > This is based on grepping with $ git grep "co->index =" drivers/tty/ > > > > Not sure what all might be stopping making struct console index unsigned. > > The value -1 is used for initializing struct console, see: > > $> git grep -A10 "struct console.*=" | \ > grep -e "struct console" -e index | \ > grep -B1 index > [...] > drivers/tty/serial/8250/8250_core.c:static struct console univ8250_console = { > drivers/tty/serial/8250/8250_core.c- .index = -1, > [...] > drivers/tty/serial/imx.c:static struct console imx_uart_console = { > drivers/tty/serial/imx.c- .index = -1, > drivers/tty/serial/ip22zilog.c:static struct console ip22zilog_console = { > drivers/tty/serial/ip22zilog.c- .index = -1, > drivers/tty/serial/kgdb_nmi.c:static struct console kgdb_nmi_console = { > drivers/tty/serial/kgdb_nmi.c- .index = -1, > drivers/tty/serial/lantiq.c:static struct console lqasc_console = { > drivers/tty/serial/lantiq.c- .index = -1, > drivers/tty/serial/liteuart.c:static struct console liteuart_console = { > drivers/tty/serial/liteuart.c- .index = -1, > drivers/tty/serial/lpc32xx_hs.c:static struct console lpc32xx_hsuart_console = { > drivers/tty/serial/lpc32xx_hs.c- .index = -1, > drivers/tty/serial/ma35d1_serial.c:static struct console ma35d1serial_console = { > drivers/tty/serial/ma35d1_serial.c- .index = -1, > drivers/tty/serial/mcf.c:static struct console mcf_console = { > drivers/tty/serial/mcf.c- .index = -1, > [...] > > It means that the index still has be get assigned. For example, it is > used here: > > static int try_enable_preferred_console(struct console *newcon, > bool user_specified) > { > [...] > if (newcon->index < 0) > newcon->index = c->index; > [...] OK > Resume: > > 1. We must either keep signed short in struct console or > use another check for non-yet assigned index. OK thanks for clarifying the usage for it. > 2. We should fix the commit message and the comment. We should > explain that negative value is used in struct console > to distinguish a non-yet-registered/assigned index/port. I'll send v3 patches tomorrow with updated commit message and comments. Thanks, Tony