From patchwork Thu Oct 12 06:42:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 151782 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1027241vqb; Wed, 11 Oct 2023 23:43:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFqCTMNNVfqGvLZe882Yozg1BziPBi+td75O96b9VTY6DJ7vhvYImXfPLllTRXeSQLuB0pa X-Received: by 2002:a05:6a00:3916:b0:68e:2fd4:288a with SMTP id fh22-20020a056a00391600b0068e2fd4288amr26210819pfb.3.1697092994310; Wed, 11 Oct 2023 23:43:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697092994; cv=none; d=google.com; s=arc-20160816; b=MlQyyrvTrrSL5fWI9vj9KgNDd2Om65qxhv6upUTO59xRg5rF0aJ0LKOJ92HF2NYUs1 OR9/Tc8bXT75aPuZapja672hbEnzotV8gJTj7qxK3M2WiXXQG/YE48PqbK0w5WPoPZJM lfjyydXXaacM4oZ7zAi7moMZEBba207J1XRvkaC8yirH/Zq6FwLG6gCmbS807ymkJSFz t458M/RTNKfRHR720zMNc2QVDZ0mFBdzLmpFz6oDnCiB4tfdcilxDvF1S8P1zjrNF8SU FrvK2g3WWblksdr+vPFpeUi8TSksTFTqtLBvIOC19j5M9VJ9tHHlV8/Oph0J0Q/DQapp 1gzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=drPfUsCKbe6hAgrbaie1cpXtpWCZB3OmIUxuFTq635g=; fh=o8Wp60O6t9aGNhRKrDSNhfZE8Iko7nroMui1s7mpLf8=; b=ny4X2gDTAqlKcSfpXV4r+daaOwZlN05aI1+LP2ysq8U85/mfWY58iF/K4iy/L248/B 8m+aIDoGXWwjM3VysIyX/PUT00prczNRWnm9XposCeIUp/RMJj463MKcG9NuRwXRSf2r 6i4Is1zQiun/V3SZdykt2wKczoam4/bU21kUlzCwDPL1hnpwVYAMVs0yZstVxCHr9IzG dBWV03y3QCf66NYaRhI01HPXJLszLsbxZXw1DtJtYPv2st60r62XmTPOqhpVTw6ZWScI 4in0UtzmZYk/bcuJoA1YmKJm7s3Lb6urKBs64wkDxhHFd8RkLG2FT/aUsT9spXj/UHPt d03g== 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:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id f18-20020a056a001ad200b0068fdb060072si7587731pfv.341.2023.10.11.23.43.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 23:43:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 9D5938213F18; Wed, 11 Oct 2023 23:43:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377465AbjJLGnI (ORCPT + 19 others); Thu, 12 Oct 2023 02:43:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343563AbjJLGnH (ORCPT ); Thu, 12 Oct 2023 02:43:07 -0400 Received: from muru.com (muru.com [72.249.23.125]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F1A6ECC for ; Wed, 11 Oct 2023 23:43:05 -0700 (PDT) Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 7663F80A3; Thu, 12 Oct 2023 06:43:04 +0000 (UTC) From: Tony Lindgren To: Greg Kroah-Hartman , Petr Mladek , Steven Rostedt , John Ogness , Sergey Senozhatsky Cc: Jiri Slaby , linux-kernel@vger.kernel.org Subject: [PATCH 1/2] printk: Check valid console index for preferred console Date: Thu, 12 Oct 2023 09:42:56 +0300 Message-ID: <20231012064300.50221-1-tony@atomide.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Wed, 11 Oct 2023 23:43:13 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778814544878849423 X-GMAIL-MSGID: 1779530983686090577 Let's check for valid console index values for preferred console to avoid bogus console index numbers from kernel command line. Let's also return an error for negative index numbers for the preferred console. Unlike for device drivers, a negative index is not valid for the preferred console. Let's also constify idx while at it. Signed-off-by: Tony Lindgren Reviewed-by: Greg Kroah-Hartman Reviewed-by: Petr Mladek --- Changes since v2: - Fix a mismerge for const char *name while changing the patch order as noted by Jiri - Clarify patch description and code comments for struct console negative index usage as noted by Petr Changes since v1: - Use const short idx and return an error on negative values --- include/linux/console.h | 2 +- kernel/printk/printk.c | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h --- a/include/linux/console.h +++ b/include/linux/console.h @@ -340,7 +340,7 @@ enum con_flush_mode { CONSOLE_REPLAY_ALL, }; -extern int add_preferred_console(char *name, int idx, char *options); +extern int add_preferred_console(char *name, const short idx, char *options); extern void console_force_preferred_locked(struct console *con); extern void register_console(struct console *); extern int unregister_console(struct console *); diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2404,12 +2404,20 @@ static void set_user_specified(struct console_cmdline *c, bool user_specified) console_set_on_cmdline = 1; } -static int __add_preferred_console(char *name, int idx, char *options, +static int __add_preferred_console(char *name, const short idx, char *options, char *brl_options, bool user_specified) { struct console_cmdline *c; int i; + /* + * We use a signed short index for struct console for device drivers to + * indicate a not yet assigned index or port. However, a negative index + * value is not valid for preferred console. + */ + if (idx < 0) + return -EINVAL; + /* * See if this tty is not yet registered, and * if we have a slot free. @@ -2513,7 +2521,7 @@ __setup("console=", console_setup); * commonly to provide a default console (ie from PROM variables) when * the user has not supplied one. */ -int add_preferred_console(char *name, int idx, char *options) +int add_preferred_console(char *name, const short idx, char *options) { return __add_preferred_console(name, idx, options, NULL, false); } From patchwork Thu Oct 12 06:42:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 151783 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1027321vqb; Wed, 11 Oct 2023 23:43:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF7esoQDt56kBMH9QwvPTP17Gk75nsoWKmgCf26pYbCxV2kFYiQ/5qpz+th46iNVbwlk3f3 X-Received: by 2002:a17:90a:9f83:b0:27c:fbf8:6c43 with SMTP id o3-20020a17090a9f8300b0027cfbf86c43mr5203966pjp.1.1697093011804; Wed, 11 Oct 2023 23:43:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697093011; cv=none; d=google.com; s=arc-20160816; b=uYR90ighU/VCSUbTnVeqomBFdOUdm+w3qFLMEwvATf2+8gRMFNWU0MBsjt7+vjBOum 2MZ/tXeY8hYtmsjHYmQXFcwlH0qyp2q1SVd4ypb70fP+WBbN1MIb/7sh3EkgOIi9wbTu +QZZEGMZixjvYV/jzeE1GSgR6DwXAR0st9nec2xMXt0zfrQ09kRAtlhpBN/PUEPgixdv ELSd1cwGoSrxKditcmxHOUdzMG5XvBAOLfw4OAZuWq/ELCiHrAC//P7gJMsv0mkhfcGI c9kmqvVkql4mksWnCVXSEpYz7GGCSBwTPlRSd21AMn3n/IaEIVFGWSRqQud1OYzJRZUD Qo3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=+Sx1x42UmLXQyg7VCwWcrYHa8lBglXzKaKcHQBJ7thU=; fh=o8Wp60O6t9aGNhRKrDSNhfZE8Iko7nroMui1s7mpLf8=; b=XtQ5GPkWAOwckIasttZWYWW6oFckJCaPaiZS69+IH/PXjmFZfsos5Nly6faE0gr07p t2XW6WU/4MBfnwkOj7s5Ko62Rm8C+42ohol6wtQ0qb7nTlbXrDH6xTEvwUz63ercM3KC b8ncukDVLV+pj+N7cDOALwuEoJlPsmbvSgxqjrQu6PPYlLYif1p06u4quTzq6pMlWwm+ tVojNlKua5gbxnX5EZg8MnSxtDmZyspuyUtzbgtqm9XuJ9dPlhlcvRxVlMP3dP91VEap awkWTqjXPpFv7kLk4/3j9tjgSwa7PIUwMnek75MiDb9U7dnltaiFFQrtE+8ABnwGURkB 0q4g== 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:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id bb19-20020a17090b009300b002776e57a5d5si1618341pjb.94.2023.10.11.23.43.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 23:43:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id C9B9281130DE; Wed, 11 Oct 2023 23:43:29 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347090AbjJLGnO (ORCPT + 19 others); Thu, 12 Oct 2023 02:43:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347082AbjJLGnL (ORCPT ); Thu, 12 Oct 2023 02:43:11 -0400 Received: from muru.com (muru.com [72.249.23.125]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D36CFBE for ; Wed, 11 Oct 2023 23:43:09 -0700 (PDT) Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 44A428107; Thu, 12 Oct 2023 06:43:08 +0000 (UTC) From: Tony Lindgren To: Greg Kroah-Hartman , Petr Mladek , Steven Rostedt , John Ogness , Sergey Senozhatsky Cc: Jiri Slaby , linux-kernel@vger.kernel.org Subject: [PATCH 2/2] printk: Constify name for add_preferred_console() Date: Thu, 12 Oct 2023 09:42:57 +0300 Message-ID: <20231012064300.50221-2-tony@atomide.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231012064300.50221-1-tony@atomide.com> References: <20231012064300.50221-1-tony@atomide.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Wed, 11 Oct 2023 23:43:29 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779531002020757957 X-GMAIL-MSGID: 1779531002020757957 While adding a preferred console handling for serial_core for serial port hardware based device addressing, Jiri suggested we constify name for add_preferred_console(). The name gets copied anyways. This allows serial core to add a preferred console using serial drv->dev_name without copying it. Note that constifying options causes changes all over the place because of struct console for match(). Suggested-by: Jiri Slaby Reviewed-by: Petr Mladek Signed-off-by: Tony Lindgren --- Changes since v2: - Rebase after fixing patch 1/2 the const char *name mismerge Changes since v1: - Updated to apply on the const short idx change - Separated out of the serial core related patches, the serial core changes still need some more changes for preferred console usage - Added Reviewed-by from Petr from the serial core thread --- include/linux/console.h | 2 +- kernel/printk/printk.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h --- a/include/linux/console.h +++ b/include/linux/console.h @@ -340,7 +340,7 @@ enum con_flush_mode { CONSOLE_REPLAY_ALL, }; -extern int add_preferred_console(char *name, const short idx, char *options); +extern int add_preferred_console(const char *name, const short idx, char *options); extern void console_force_preferred_locked(struct console *con); extern void register_console(struct console *); extern int unregister_console(struct console *); diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2404,7 +2404,7 @@ static void set_user_specified(struct console_cmdline *c, bool user_specified) console_set_on_cmdline = 1; } -static int __add_preferred_console(char *name, const short idx, char *options, +static int __add_preferred_console(const char *name, const short idx, char *options, char *brl_options, bool user_specified) { struct console_cmdline *c; @@ -2521,7 +2521,7 @@ __setup("console=", console_setup); * commonly to provide a default console (ie from PROM variables) when * the user has not supplied one. */ -int add_preferred_console(char *name, const short idx, char *options) +int add_preferred_console(const char *name, const short idx, char *options) { return __add_preferred_console(name, idx, options, NULL, false); }