From nobody Tue Dec 16 19:56:47 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1879351016; Thu, 20 Jun 2024 12:46:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718887581; cv=none; b=DWiZTNYzrXUljJcUQLXNMoJrCArOJfV0NgwjNhvfGn+9+KP06JXpZL2gc6E7N4DWPeFaL5LXeJ3G1ehLmk9a1iPkQpfmAFTLvztHRUNRNKC4/n0e8YGu3GxuPXUkg0exWirjSixLWs6iEbfiUkJhq/MvOiOLBHvOl+/9z4nUHJE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718887581; c=relaxed/simple; bh=ykmFHjLmQcgg09LU3W6SLx0qpasqzoUvmrp1nqXPat0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o/ppkb8R+OHx0n+q4il0s+WGs9QxJxOotupb9exewfrg8qmxus9JzJKqfkzm4fMIg7T5CDqsN3VbxuZjozX6+Du+bts/AVvPKH8l/3i1w0E9NPVshEqh+p9XpkBp+dV2t3EpN2649mRoqUu2gDqw8N6DioP+RdJm2mVaWRDbYCA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=NznqrL8k; arc=none smtp.client-ip=198.175.65.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="NznqrL8k" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718887577; x=1750423577; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ykmFHjLmQcgg09LU3W6SLx0qpasqzoUvmrp1nqXPat0=; b=NznqrL8kH8tZj+HDuHHgKfBVoaGVs8tTmGR9gxHX9lNMtCm7W13RQ6yw Vd6kbG/QZ8/TOeekW/KKw4buI8a5Rtx3qHLVe+E4jxbMPqjz7C4h5nwsf YLEE22Ea3yZ24yhDu/PtYkomGjBmv7LT8zTOgM33NbQYSYJr0btaNrf33 t+qgpJrnOulUne0/KrWYaOsA/UkhlCKf4mveK3hPoQFY55X1NqEILCX2n ZXj9DXeJO8umRC68rzYK5HC14MAma3ndGxdUJc4qYZPTAW4aOdGDmu6FK bXq+0HwqvNYqhXsXuZ57kBITH8IHqRQ5b5mVOlZJcRq0rudV+w7wd7Wty Q==; X-CSE-ConnectionGUID: SbTsIBpmQ9eIA/B2w82wWg== X-CSE-MsgGUID: gcw6S6dOSteuxJZmuEI+FA== X-IronPort-AV: E=McAfee;i="6700,10204,11108"; a="26985661" X-IronPort-AV: E=Sophos;i="6.08,252,1712646000"; d="scan'208";a="26985661" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jun 2024 05:46:17 -0700 X-CSE-ConnectionGUID: XB+SXQuATLKI9Btx+atutQ== X-CSE-MsgGUID: EG6QYQ/7Td6eRej8XXPXVg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,252,1712646000"; d="scan'208";a="42888579" Received: from ijarvine-desk1.ger.corp.intel.com (HELO tlindgre-MOBL1.intel.com) ([10.245.247.35]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jun 2024 05:46:12 -0700 From: Tony Lindgren To: Greg Kroah-Hartman , Jiri Slaby , Petr Mladek , Steven Rostedt , John Ogness , Sergey Senozhatsky , Tony Lindgren , Andy Shevchenko Cc: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , linux-serial@vger.kernel.org, Tony Lindgren , linux-kernel@vger.kernel.org Subject: [PATCH v4 1/4] printk: Revert add_preferred_console_match() related commits Date: Thu, 20 Jun 2024 15:45:26 +0300 Message-ID: <20240620124541.164931-2-tony.lindgren@linux.intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240620124541.164931-1-tony.lindgren@linux.intel.com> References: <20240620124541.164931-1-tony.lindgren@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Recent changes to allow using DEVNAME:0.0 style console names caused a regression to the kernel command line handling for the console options. The last preferred console added gets used for init. This is documented in the comments for add_preferred_console(). Now the kernel command line options for console=3DttyS0,115200 console=3Dtty0 are wrongly handled and cause the /dev/console to be associated with ttyS0 instead of tty0. This happens because we are calling __add_preferred_console() later on from serial8250_isa_init_ports() after console_setup() and the console gets treated as the last added preferred console. As the DEVNAME:0.0 style console device is not known at console_setup() time, I added a call to __add_preferred_console() later on when the console is ready. To fix the issue, let's revert the printk related commits: f03e8c1060f8 ("printk: Save console options for add_preferred_console_match= ()") b73c9cbe4f1f ("printk: Flag register_console() if console is set on command= line") 8a831c584e6e ("printk: Don't try to parse DEVNAME:0.0 console options") We need to also drop the call for add_preferred_console_match() from serial_base_add_one_prefcon() added by commit 787a1cabac01 ("serial: core: Add support for DEVNAME:0.0 style naming for kernel console"). Petr has suggested a better way to handle the deferred consoles that does not rely on calling __add_preferred_console() again. Reported-by: Petr Mladek Link: https://lore.kernel.org/linux-serial/ZlC6_Um4P4b-_WQE@pathway.suse.cz/ Fixes: f03e8c1060f8 ("printk: Save console options for add_preferred_consol= e_match()") Reviewed-by: Petr Mladek Signed-off-by: Tony Lindgren --- drivers/tty/serial/serial_base_bus.c | 8 +- include/linux/printk.h | 3 - kernel/printk/Makefile | 2 +- kernel/printk/conopt.c | 146 --------------------------- kernel/printk/console_cmdline.h | 6 -- kernel/printk/printk.c | 23 +---- 6 files changed, 6 insertions(+), 182 deletions(-) delete mode 100644 kernel/printk/conopt.c diff --git a/drivers/tty/serial/serial_base_bus.c b/drivers/tty/serial/seri= al_base_bus.c index 73c6ee540c83..5ebacb982f9e 100644 --- a/drivers/tty/serial/serial_base_bus.c +++ b/drivers/tty/serial/serial_base_bus.c @@ -210,13 +210,7 @@ void serial_base_port_device_remove(struct serial_port= _device *port_dev) static int serial_base_add_one_prefcon(const char *match, const char *dev_= name, int port_id) { - int ret; - - ret =3D add_preferred_console_match(match, dev_name, port_id); - if (ret =3D=3D -ENOENT) - return 0; - - return ret; + return 0; } =20 #ifdef __sparc__ diff --git a/include/linux/printk.h b/include/linux/printk.h index 40afab23881a..65c5184470f1 100644 --- a/include/linux/printk.h +++ b/include/linux/printk.h @@ -60,9 +60,6 @@ static inline const char *printk_skip_headers(const char = *buffer) #define CONSOLE_LOGLEVEL_DEFAULT CONFIG_CONSOLE_LOGLEVEL_DEFAULT #define CONSOLE_LOGLEVEL_QUIET CONFIG_CONSOLE_LOGLEVEL_QUIET =20 -int add_preferred_console_match(const char *match, const char *name, - const short idx); - extern int console_printk[]; =20 #define console_loglevel (console_printk[0]) diff --git a/kernel/printk/Makefile b/kernel/printk/Makefile index 040fe7d1eda2..39a2b61c7232 100644 --- a/kernel/printk/Makefile +++ b/kernel/printk/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-y =3D printk.o conopt.o +obj-y =3D printk.o obj-$(CONFIG_PRINTK) +=3D printk_safe.o nbcon.o obj-$(CONFIG_A11Y_BRAILLE_CONSOLE) +=3D braille.o obj-$(CONFIG_PRINTK_INDEX) +=3D index.o diff --git a/kernel/printk/conopt.c b/kernel/printk/conopt.c deleted file mode 100644 index 9d507bac3657..000000000000 --- a/kernel/printk/conopt.c +++ /dev/null @@ -1,146 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Kernel command line console options for hardware based addressing - * - * Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/ - * Author: Tony Lindgren - */ - -#include -#include -#include -#include - -#include - -#include "console_cmdline.h" - -/* - * Allow longer DEVNAME:0.0 style console naming such as abcd0000.serial:0= .0 - * in addition to the legacy ttyS0 style naming. - */ -#define CONSOLE_NAME_MAX 32 - -#define CONSOLE_OPT_MAX 16 -#define CONSOLE_BRL_OPT_MAX 16 - -struct console_option { - char name[CONSOLE_NAME_MAX]; - char opt[CONSOLE_OPT_MAX]; - char brl_opt[CONSOLE_BRL_OPT_MAX]; - u8 has_brl_opt:1; -}; - -/* Updated only at console_setup() time, no locking needed */ -static struct console_option conopt[MAX_CMDLINECONSOLES]; - -/** - * console_opt_save - Saves kernel command line console option for driver = use - * @str: Kernel command line console name and option - * @brl_opt: Braille console options - * - * Saves a kernel command line console option for driver subsystems to use= for - * adding a preferred console during init. Called from console_setup() onl= y. - * - * Return: 0 on success, negative error code on failure. - */ -int __init console_opt_save(const char *str, const char *brl_opt) -{ - struct console_option *con; - size_t namelen, optlen; - const char *opt; - int i; - - namelen =3D strcspn(str, ","); - if (namelen =3D=3D 0 || namelen >=3D CONSOLE_NAME_MAX) - return -EINVAL; - - opt =3D str + namelen; - if (*opt =3D=3D ',') - opt++; - - optlen =3D strlen(opt); - if (optlen >=3D CONSOLE_OPT_MAX) - return -EINVAL; - - for (i =3D 0; i < MAX_CMDLINECONSOLES; i++) { - con =3D &conopt[i]; - - if (con->name[0]) { - if (!strncmp(str, con->name, namelen)) - return 0; - continue; - } - - /* - * The name isn't terminated, only opt is. Empty opt is fine, - * but brl_opt can be either empty or NULL. For more info, see - * _braille_console_setup(). - */ - strscpy(con->name, str, namelen + 1); - strscpy(con->opt, opt, CONSOLE_OPT_MAX); - if (brl_opt) { - strscpy(con->brl_opt, brl_opt, CONSOLE_BRL_OPT_MAX); - con->has_brl_opt =3D 1; - } - - return 0; - } - - return -ENOMEM; -} - -static struct console_option *console_opt_find(const char *name) -{ - struct console_option *con; - int i; - - for (i =3D 0; i < MAX_CMDLINECONSOLES; i++) { - con =3D &conopt[i]; - if (!strcmp(name, con->name)) - return con; - } - - return NULL; -} - -/** - * add_preferred_console_match - Adds a preferred console if a match is fo= und - * @match: Expected console on kernel command line, such as console=3DDEVN= AME:0.0 - * @name: Name of the console character device to add such as ttyS - * @idx: Index for the console - * - * Allows driver subsystems to add a console after translating the command - * line name to the character device name used for the console. Options are - * added automatically based on the kernel command line. Duplicate preferr= ed - * consoles are ignored by __add_preferred_console(). - * - * Return: 0 on success, negative error code on failure. - */ -int add_preferred_console_match(const char *match, const char *name, - const short idx) -{ - struct console_option *con; - char *brl_opt =3D NULL; - - if (!match || !strlen(match) || !name || !strlen(name) || - idx < 0) - return -EINVAL; - - con =3D console_opt_find(match); - if (!con) - return -ENOENT; - - /* - * See __add_preferred_console(). It checks for NULL brl_options to set - * the preferred_console flag. Empty brl_opt instead of NULL leads into - * the preferred_console flag not set, and CON_CONSDEV not being set, - * and the boot console won't get disabled at the end of console_setup(). - */ - if (con->has_brl_opt) - brl_opt =3D con->brl_opt; - - console_opt_add_preferred_console(name, idx, con->opt, brl_opt); - - return 0; -} diff --git a/kernel/printk/console_cmdline.h b/kernel/printk/console_cmdlin= e.h index a125e0235589..3ca74ad391d6 100644 --- a/kernel/printk/console_cmdline.h +++ b/kernel/printk/console_cmdline.h @@ -2,12 +2,6 @@ #ifndef _CONSOLE_CMDLINE_H #define _CONSOLE_CMDLINE_H =20 -#define MAX_CMDLINECONSOLES 8 - -int console_opt_save(const char *str, const char *brl_opt); -int console_opt_add_preferred_console(const char *name, const short idx, - char *options, char *brl_options); - struct console_cmdline { char name[16]; /* Name of the driver */ diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 420fd310129d..dddb15f48d59 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -383,6 +383,9 @@ static int console_locked; /* * Array of consoles built from command line options (console=3D) */ + +#define MAX_CMDLINECONSOLES 8 + static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES]; =20 static int preferred_console =3D -1; @@ -2500,17 +2503,6 @@ static int __init console_setup(char *str) if (_braille_console_setup(&str, &brl_options)) return 1; =20 - /* Save the console for driver subsystem use */ - if (console_opt_save(str, brl_options)) - return 1; - - /* Flag register_console() to not call try_enable_default_console() */ - console_set_on_cmdline =3D 1; - - /* Don't attempt to parse a DEVNAME:0.0 style console */ - if (strchr(str, ':')) - return 1; - /* * Decode str into name, index, options. */ @@ -2541,13 +2533,6 @@ static int __init console_setup(char *str) } __setup("console=3D", console_setup); =20 -/* Only called from add_preferred_console_match() */ -int console_opt_add_preferred_console(const char *name, const short idx, - char *options, char *brl_options) -{ - return __add_preferred_console(name, idx, options, brl_options, true); -} - /** * add_preferred_console - add a device to the list of preferred consoles. * @name: device name @@ -3522,7 +3507,7 @@ void register_console(struct console *newcon) * Note that a console with tty binding will have CON_CONSDEV * flag set and will be first in the list. */ - if (preferred_console < 0 && !console_set_on_cmdline) { + if (preferred_console < 0) { if (hlist_empty(&console_list) || !console_first()->device || console_first()->flags & CON_BOOT) { try_enable_default_console(newcon); --=20 2.45.2 From nobody Tue Dec 16 19:56:47 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D2A0C1ACE73; Thu, 20 Jun 2024 12:46:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718887587; cv=none; b=cr7Wn9UG1C9PtTIa+d9+B4WmZWgBYlDfR9tCtN8YuOaBXKxoJlu1ieK3fi/F5SyeS/+fekiZesdGikTfXWZcR0TDXNUjyARHlp+YPNvWf5Gnrd68ln3+kmzQj4kGWFezAuorGOBz+jwFazT1I2M9w42MblxaL6V7qBiDzIHqBvI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718887587; c=relaxed/simple; bh=Zfo5p2XS+UpBhCaGmUZEdR7V1ETFipCjP8W5TnHmIiw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YWFBtnt8FwYek1eTUoE+QiUhJKizNVDreOn+91ilDHf+osBsu42CYYzPT9AdQ76DxDZmfpv/T86Y281vHA7De5WJ8uPFVQClxcyvWQ7NJ/PDseYt7ht1VX+5r0TAx/Inms/JHc1XE7jFcY+B+ydHfrIbT9qrp7zpsiAmfYIOj4U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=f8jS/MB5; arc=none smtp.client-ip=198.175.65.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="f8jS/MB5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718887586; x=1750423586; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Zfo5p2XS+UpBhCaGmUZEdR7V1ETFipCjP8W5TnHmIiw=; b=f8jS/MB5F+63hs8f+Z6Ln59kLLddnuT/f3Q1PXHmMU57Q+Z4YsPNsjVv az3VLG0y6YGDdlBbOhUQIzDD1oxWKMCU3YdR4HRDeoYAPn/f52f7Ab+xq tH/PoGiFluO9aG/hwq8zYC6+HM7ZGhRsnT+GFwPzvPFWZRWDD14sIpaoH hM57Jp2soFg58LDLDp1w6hm7WejMuiG8Fo90mBfLMJYkMuu32MALTEUmG nBHI9ISLJd1fCEBgXGKApO51YgDBlSPAXNtCkHfHp7CZ+VbO0dtfSbZFD 53EHQ+lVIXrCPqY0Q+bjNexCmC//gXdFkjQowTnxddvQZRpW6iMVKC7H2 A==; X-CSE-ConnectionGUID: HL/7htdlR9+jA+O/X/ou0g== X-CSE-MsgGUID: 1Kyt3dW6QD+qHMtPbS0Ddw== X-IronPort-AV: E=McAfee;i="6700,10204,11108"; a="26985670" X-IronPort-AV: E=Sophos;i="6.08,252,1712646000"; d="scan'208";a="26985670" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jun 2024 05:46:26 -0700 X-CSE-ConnectionGUID: nEKjr2BISbqmVdISbfwbLQ== X-CSE-MsgGUID: FBzR+O2JR9W573rVLTFEEw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,252,1712646000"; d="scan'208";a="42888676" Received: from ijarvine-desk1.ger.corp.intel.com (HELO tlindgre-MOBL1.intel.com) ([10.245.247.35]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jun 2024 05:46:21 -0700 From: Tony Lindgren To: Greg Kroah-Hartman , Jiri Slaby , Petr Mladek , Steven Rostedt , John Ogness , Sergey Senozhatsky , Tony Lindgren , Andy Shevchenko Cc: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , linux-serial@vger.kernel.org, Tony Lindgren , linux-kernel@vger.kernel.org Subject: [PATCH v4 2/4] printk: Add match_devname_and_update_preferred_console() Date: Thu, 20 Jun 2024 15:45:27 +0300 Message-ID: <20240620124541.164931-3-tony.lindgren@linux.intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240620124541.164931-1-tony.lindgren@linux.intel.com> References: <20240620124541.164931-1-tony.lindgren@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Let's add match_devname_and_update_preferred_console() for driver subsystems to call during init when the console is ready, and it's character device name is known. For now, we use it only for the serial layer to allow console=3DDEVNAME:0.0 style hardware based addressing for consoles. The earlier attempt on doing this caused a regression with the kernel command line console order as it added calling __add_preferred_console() again later on during init. A better approach was suggested by Petr where we add the deferred console to the console_cmdline[] and update it later on when the console is ready. Suggested-by: Petr Mladek Co-developed-by: Petr Mladek Reviewed-by: Petr Mladek Tested-by: Petr Mladek Signed-off-by: Tony Lindgren --- drivers/tty/serial/serial_base_bus.c | 8 ++- include/linux/printk.h | 4 ++ kernel/printk/console_cmdline.h | 1 + kernel/printk/printk.c | 103 +++++++++++++++++++++++---- 4 files changed, 100 insertions(+), 16 deletions(-) diff --git a/drivers/tty/serial/serial_base_bus.c b/drivers/tty/serial/seri= al_base_bus.c index 5ebacb982f9e..2cf86f1ff298 100644 --- a/drivers/tty/serial/serial_base_bus.c +++ b/drivers/tty/serial/serial_base_bus.c @@ -210,7 +210,13 @@ void serial_base_port_device_remove(struct serial_port= _device *port_dev) static int serial_base_add_one_prefcon(const char *match, const char *dev_= name, int port_id) { - return 0; + int ret; + + ret =3D match_devname_and_update_preferred_console(match, dev_name, port_= id); + if (ret =3D=3D -ENOENT) + return 0; + + return ret; } =20 #ifdef __sparc__ diff --git a/include/linux/printk.h b/include/linux/printk.h index 65c5184470f1..7239976698e4 100644 --- a/include/linux/printk.h +++ b/include/linux/printk.h @@ -60,6 +60,10 @@ static inline const char *printk_skip_headers(const char= *buffer) #define CONSOLE_LOGLEVEL_DEFAULT CONFIG_CONSOLE_LOGLEVEL_DEFAULT #define CONSOLE_LOGLEVEL_QUIET CONFIG_CONSOLE_LOGLEVEL_QUIET =20 +int match_devname_and_update_preferred_console(const char *match, + const char *name, + const short idx); + extern int console_printk[]; =20 #define console_loglevel (console_printk[0]) diff --git a/kernel/printk/console_cmdline.h b/kernel/printk/console_cmdlin= e.h index 3ca74ad391d6..0ab573b6d4dc 100644 --- a/kernel/printk/console_cmdline.h +++ b/kernel/printk/console_cmdline.h @@ -6,6 +6,7 @@ struct console_cmdline { char name[16]; /* Name of the driver */ int index; /* Minor dev. to use */ + char devname[32]; /* DEVNAME:0.0 style device name */ bool user_specified; /* Specified by command line vs. platform */ char *options; /* Options for the driver */ #ifdef CONFIG_A11Y_BRAILLE_CONSOLE diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index dddb15f48d59..7d91593f0ecf 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2429,18 +2429,23 @@ static void set_user_specified(struct console_cmdli= ne *c, bool user_specified) console_set_on_cmdline =3D 1; } =20 -static int __add_preferred_console(const char *name, const short idx, char= *options, +static int __add_preferred_console(const char *name, const short idx, + const char *devname, char *options, char *brl_options, bool user_specified) { struct console_cmdline *c; int i; =20 + if (!name && !devname) + return -EINVAL; + /* * 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. + * value is not valid when the console name and index are defined on + * the command line. */ - if (idx < 0) + if (name && idx < 0) return -EINVAL; =20 /* @@ -2448,9 +2453,10 @@ static int __add_preferred_console(const char *name,= const short idx, char *opti * if we have a slot free. */ for (i =3D 0, c =3D console_cmdline; - i < MAX_CMDLINECONSOLES && c->name[0]; + i < MAX_CMDLINECONSOLES && (c->name[0] || c->devname[0]); i++, c++) { - if (strcmp(c->name, name) =3D=3D 0 && c->index =3D=3D idx) { + if ((name && strcmp(c->name, name) =3D=3D 0 && c->index =3D=3D idx) || + (devname && strcmp(c->devname, devname) =3D=3D 0)) { if (!brl_options) preferred_console =3D i; set_user_specified(c, user_specified); @@ -2461,7 +2467,10 @@ static int __add_preferred_console(const char *name,= const short idx, char *opti return -E2BIG; if (!brl_options) preferred_console =3D i; - strscpy(c->name, name, sizeof(c->name)); + if (name) + strscpy(c->name, name); + if (devname) + strscpy(c->devname, devname); c->options =3D options; set_user_specified(c, user_specified); braille_set_options(c, brl_options); @@ -2486,8 +2495,13 @@ __setup("console_msg_format=3D", console_msg_format_= setup); */ static int __init console_setup(char *str) { - char buf[sizeof(console_cmdline[0].name) + 4]; /* 4 for "ttyS" */ - char *s, *options, *brl_options =3D NULL; + static_assert(sizeof(console_cmdline[0].devname) >=3D sizeof(console_cmdl= ine[0].name) + 4); + char buf[sizeof(console_cmdline[0].devname)]; + char *brl_options =3D NULL; + char *ttyname =3D NULL; + char *devname =3D NULL; + char *options; + char *s; int idx; =20 /* @@ -2496,17 +2510,23 @@ static int __init console_setup(char *str) * for exactly this purpose. */ if (str[0] =3D=3D 0 || strcmp(str, "null") =3D=3D 0) { - __add_preferred_console("ttynull", 0, NULL, NULL, true); + __add_preferred_console("ttynull", 0, NULL, NULL, NULL, true); return 1; } =20 if (_braille_console_setup(&str, &brl_options)) return 1; =20 + /* For a DEVNAME:0.0 style console the character device is unknown early = */ + if (strchr(str, ':')) + devname =3D buf; + else + ttyname =3D buf; + /* * Decode str into name, index, options. */ - if (isdigit(str[0])) + if (ttyname && isdigit(str[0])) scnprintf(buf, sizeof(buf), "ttyS%s", str); else strscpy(buf, str); @@ -2523,12 +2543,18 @@ static int __init console_setup(char *str) #endif =20 for (s =3D buf; *s; s++) - if (isdigit(*s) || *s =3D=3D ',') + if ((ttyname && isdigit(*s)) || *s =3D=3D ',') break; - idx =3D simple_strtoul(s, NULL, 10); + + /* @idx will get defined when devname matches. */ + if (devname) + idx =3D -1; + else + idx =3D simple_strtoul(s, NULL, 10); + *s =3D 0; =20 - __add_preferred_console(buf, idx, options, brl_options, true); + __add_preferred_console(ttyname, idx, devname, options, brl_options, true= ); return 1; } __setup("console=3D", console_setup); @@ -2548,7 +2574,51 @@ __setup("console=3D", console_setup); */ int add_preferred_console(const char *name, const short idx, char *options) { - return __add_preferred_console(name, idx, options, NULL, false); + return __add_preferred_console(name, idx, NULL, options, NULL, false); +} + +/** + * match_devname_and_update_preferred_console - Update a preferred console + * when matching devname is found. + * @devname: DEVNAME:0.0 style device name + * @name: Name of the corresponding console driver, e.g. "ttyS" + * @idx: Console index, e.g. port number. + * + * The function checks whether a device with the given @devname is + * preferred via the console=3DDEVNAME:0.0 command line option. + * It fills the missing console driver name and console index + * so that a later register_console() call could find (match) + * and enable this device. + * + * It might be used when a driver subsystem initializes particular + * devices with already known DEVNAME:0.0 style names. And it + * could predict which console driver name and index this device + * would later get associated with. + * + * Return: 0 on success, negative error code on failure. + */ +int match_devname_and_update_preferred_console(const char *devname, + const char *name, + const short idx) +{ + struct console_cmdline *c =3D console_cmdline; + int i; + + if (!devname || !strlen(devname) || !name || !strlen(name) || idx < 0) + return -EINVAL; + + for (i =3D 0; i < MAX_CMDLINECONSOLES && (c->name[0] || c->devname[0]); + i++, c++) { + if (!strcmp(devname, c->devname)) { + pr_info("associate the preferred console \"%s\" with \"%s%d\"\n", + devname, name, idx); + strscpy(c->name, name); + c->index =3D idx; + return 0; + } + } + + return -ENOENT; } =20 bool console_suspend_enabled =3D true; @@ -3318,8 +3388,11 @@ static int try_enable_preferred_console(struct conso= le *newcon, int i, err; =20 for (i =3D 0, c =3D console_cmdline; - i < MAX_CMDLINECONSOLES && c->name[0]; + i < MAX_CMDLINECONSOLES && (c->name[0] || c->devname[0]); i++, c++) { + /* Console not yet initialized? */ + if (!c->name[0]) + continue; if (c->user_specified !=3D user_specified) continue; if (!newcon->match || --=20 2.45.2 From nobody Tue Dec 16 19:56:47 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E10721ACE73; Thu, 20 Jun 2024 12:46:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718887597; cv=none; b=stH8jvRiCRQesl4y+cqkv3nR7pGhNGQ0rRDHvkOIadZylnfAPl5J1nPotWPLJpCK8WW2nxTkHoraHicv7vHthPrUbaLy4vyYGPF3UC/gFtBG6+LyIGHTlIZ+085cp+aCkD6luXmsm+OV4pR3ns0BZx2J5qhEq8r2c5bQWRo8iOg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718887597; c=relaxed/simple; bh=wryTky+f8DBKHxvuyF6uPMNEDIH64K2MCv4fOtZirPQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FBeNgOoeqQNuCiJtdfP0RC8kdTbbiTXra67jVmnyhCMD4H6W/h7KjWmQfem5667k46NEw6SRAaz7bi+GBzkQ68xrMoi0seIz84w2G+aojhnFGx5R4LG1CaMkIx4iPwNOzyguGTUuklrHK/Sf4EOdez8Wi8Keu+sXe2b6q2XVjOg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Z1VtS8QX; arc=none smtp.client-ip=198.175.65.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Z1VtS8QX" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718887596; x=1750423596; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wryTky+f8DBKHxvuyF6uPMNEDIH64K2MCv4fOtZirPQ=; b=Z1VtS8QXYWaZLzz453LZBsD23xAELVmXoDkSy8sXgNc2LDzbYTIiHud1 PgqpT8c7DLj4RzFHNAWibOgBA8yyUwZ7q3FamqsnNpZj0kV+Y/EC3dsZk FpF/gELnHkQGb7pHMY2PjzBA93YlrrnEbht7SCm4HW0YhMI8iuMBfyoY+ G3sWNbUQ2kMMo2d0Uoo1w0nqD/cnM0tWpyZqVc/ZCoGET31m6Pi/8FmO9 UsC/8rhpcQg/ZT96UFaIdS72gKjzLdh4Uiq7GwkWUiRzfefuP5X/grh8e w3Aq+bqUw/pGnKBkWvtaA+i5mTMoFd97RZqeAJguNE4re+gPPLqCcA8Rr Q==; X-CSE-ConnectionGUID: ojvtZ+1ASv6X09UrLVYy6A== X-CSE-MsgGUID: DD9wwq2eQwiQWGMeTWI8+g== X-IronPort-AV: E=McAfee;i="6700,10204,11108"; a="26985677" X-IronPort-AV: E=Sophos;i="6.08,252,1712646000"; d="scan'208";a="26985677" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jun 2024 05:46:36 -0700 X-CSE-ConnectionGUID: Dd1Dq2EbSJmy/Vc4WOIOCg== X-CSE-MsgGUID: e50AX1CfQQWmnlEOUEaxvg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,252,1712646000"; d="scan'208";a="42888747" Received: from ijarvine-desk1.ger.corp.intel.com (HELO tlindgre-MOBL1.intel.com) ([10.245.247.35]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jun 2024 05:46:31 -0700 From: Tony Lindgren To: Greg Kroah-Hartman , Jiri Slaby , Petr Mladek , Steven Rostedt , John Ogness , Sergey Senozhatsky , Tony Lindgren , Andy Shevchenko Cc: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , linux-serial@vger.kernel.org, Tony Lindgren , linux-kernel@vger.kernel.org Subject: [PATCH v4 3/4] serial: core: Revert unusable console quirk handling Date: Thu, 20 Jun 2024 15:45:28 +0300 Message-ID: <20240620124541.164931-4-tony.lindgren@linux.intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240620124541.164931-1-tony.lindgren@linux.intel.com> References: <20240620124541.164931-1-tony.lindgren@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There is no point of trying to handle the console quirks in the serial core instead of console_setup() currently. With the console_setup() related changes, we are now deferring the DEVNAME:0.0 style consoles based on the ":" naming only. So the serial core console quirk handling would not do anything for the "ttyS" named consoles as they are not deferred. Also the earlier approach would have depended on further changes to be able to drop the serial port quirk handling from console_setup(). Let's revert the following console quirk handling related serial core commits: b20172ca6bf4 ("serial: core: Fix ifdef for serial base console functions") 4547cd76f08a ("serial: 8250: Fix add preferred console for serial8250_isa_i= nit_ports()") a8b04cfe7dad ("serial: 8250: Add preferred console in serial8250_isa_init_p= orts()") a0f32e2dd998 ("serial: core: Handle serial console options") 787a1cabac01 ("serial: core: Add support for DEVNAME:0.0 style naming for k= ernel console") Once the console quirk handling is gone, we add back the DEVNAME:0.0 functionality with a minimal patch. Suggested-by: Petr Mladek Link: https://lore.kernel.org/linux-serial/ZnGQ8JAu2OQf0GX8@pathway.suse.cz/ Signed-off-by: Tony Lindgren Reviewed-by: Petr Mladek --- drivers/tty/serial/8250/8250_core.c | 5 -- drivers/tty/serial/serial_base.h | 30 ------- drivers/tty/serial/serial_base_bus.c | 129 --------------------------- drivers/tty/serial/serial_core.c | 4 - 4 files changed, 168 deletions(-) diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/= 8250_core.c index ff15022369e4..b0adafc44747 100644 --- a/drivers/tty/serial/8250/8250_core.c +++ b/drivers/tty/serial/8250/8250_core.c @@ -15,7 +15,6 @@ */ =20 #include -#include #include #include #include @@ -42,8 +41,6 @@ =20 #include =20 -#include "../serial_base.h" /* For serial_base_add_isa_preferred_console()= */ - #include "8250.h" =20 /* @@ -563,8 +560,6 @@ static void __init serial8250_isa_init_ports(void) port->irqflags |=3D irqflag; if (serial8250_isa_config !=3D NULL) serial8250_isa_config(i, &up->port, &up->capabilities); - - serial_base_add_isa_preferred_console(serial8250_reg.dev_name, i); } } =20 diff --git a/drivers/tty/serial/serial_base.h b/drivers/tty/serial/serial_b= ase.h index 743a72ac34f3..b6c38d2edfd4 100644 --- a/drivers/tty/serial/serial_base.h +++ b/drivers/tty/serial/serial_base.h @@ -49,33 +49,3 @@ void serial_ctrl_unregister_port(struct uart_driver *drv= , struct uart_port *port =20 int serial_core_register_port(struct uart_driver *drv, struct uart_port *p= ort); void serial_core_unregister_port(struct uart_driver *drv, struct uart_port= *port); - -#ifdef CONFIG_SERIAL_CORE_CONSOLE - -int serial_base_add_preferred_console(struct uart_driver *drv, - struct uart_port *port); - -#else - -static inline -int serial_base_add_preferred_console(struct uart_driver *drv, - struct uart_port *port) -{ - return 0; -} - -#endif - -#ifdef CONFIG_SERIAL_8250_CONSOLE - -int serial_base_add_isa_preferred_console(const char *name, int idx); - -#else - -static inline -int serial_base_add_isa_preferred_console(const char *name, int idx) -{ - return 0; -} - -#endif diff --git a/drivers/tty/serial/serial_base_bus.c b/drivers/tty/serial/seri= al_base_bus.c index 2cf86f1ff298..4df2a4b10445 100644 --- a/drivers/tty/serial/serial_base_bus.c +++ b/drivers/tty/serial/serial_base_bus.c @@ -8,7 +8,6 @@ * The serial core bus manages the serial core controller instances. */ =20 -#include #include #include #include @@ -205,134 +204,6 @@ void serial_base_port_device_remove(struct serial_por= t_device *port_dev) put_device(&port_dev->dev); } =20 -#ifdef CONFIG_SERIAL_CORE_CONSOLE - -static int serial_base_add_one_prefcon(const char *match, const char *dev_= name, - int port_id) -{ - int ret; - - ret =3D match_devname_and_update_preferred_console(match, dev_name, port_= id); - if (ret =3D=3D -ENOENT) - return 0; - - return ret; -} - -#ifdef __sparc__ - -/* Handle Sparc ttya and ttyb options as done in console_setup() */ -static int serial_base_add_sparc_console(const char *dev_name, int idx) -{ - const char *name; - - switch (idx) { - case 0: - name =3D "ttya"; - break; - case 1: - name =3D "ttyb"; - break; - default: - return 0; - } - - return serial_base_add_one_prefcon(name, dev_name, idx); -} - -#else - -static inline int serial_base_add_sparc_console(const char *dev_name, int = idx) -{ - return 0; -} - -#endif - -static int serial_base_add_prefcon(const char *name, int idx) -{ - const char *char_match __free(kfree) =3D NULL; - const char *nmbr_match __free(kfree) =3D NULL; - int ret; - - /* Handle ttyS specific options */ - if (strstarts(name, "ttyS")) { - /* No name, just a number */ - nmbr_match =3D kasprintf(GFP_KERNEL, "%i", idx); - if (!nmbr_match) - return -ENODEV; - - ret =3D serial_base_add_one_prefcon(nmbr_match, name, idx); - if (ret) - return ret; - - /* Sparc ttya and ttyb */ - ret =3D serial_base_add_sparc_console(name, idx); - if (ret) - return ret; - } - - /* Handle the traditional character device name style console=3DttyS0 */ - char_match =3D kasprintf(GFP_KERNEL, "%s%i", name, idx); - if (!char_match) - return -ENOMEM; - - return serial_base_add_one_prefcon(char_match, name, idx); -} - -/** - * serial_base_add_preferred_console - Adds a preferred console - * @drv: Serial port device driver - * @port: Serial port instance - * - * Tries to add a preferred console for a serial port if specified in the - * kernel command line. Supports both the traditional character device such - * as console=3DttyS0, and a hardware addressing based console=3DDEVNAME:0= .0 - * style name. - * - * Translates the kernel command line option using a hardware based addres= sing - * console=3DDEVNAME:0.0 to the serial port character device such as ttyS0. - * Cannot be called early for ISA ports, depends on struct device. - * - * Note that duplicates are ignored by add_preferred_console(). - * - * Return: 0 on success, negative error code on failure. - */ -int serial_base_add_preferred_console(struct uart_driver *drv, - struct uart_port *port) -{ - const char *port_match __free(kfree) =3D NULL; - int ret; - - ret =3D serial_base_add_prefcon(drv->dev_name, port->line); - if (ret) - return ret; - - port_match =3D kasprintf(GFP_KERNEL, "%s:%i.%i", dev_name(port->dev), - port->ctrl_id, port->port_id); - if (!port_match) - return -ENOMEM; - - /* Translate a hardware addressing style console=3DDEVNAME:0.0 */ - return serial_base_add_one_prefcon(port_match, drv->dev_name, port->line); -} - -#endif - -#ifdef CONFIG_SERIAL_8250_CONSOLE - -/* - * Early ISA ports initialize the console before there is no struct device. - * This should be only called from serial8250_isa_init_preferred_console(), - * other callers are likely wrong and should rely on earlycon instead. - */ -int serial_base_add_isa_preferred_console(const char *name, int idx) -{ - return serial_base_add_prefcon(name, idx); -} - -#endif - static int serial_base_init(void) { int ret; diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_c= ore.c index 0c4d60976663..2a8006e3d687 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -3422,10 +3422,6 @@ int serial_core_register_port(struct uart_driver *dr= v, struct uart_port *port) if (ret) goto err_unregister_ctrl_dev; =20 - ret =3D serial_base_add_preferred_console(drv, port); - if (ret) - goto err_unregister_port_dev; - ret =3D serial_core_add_one_port(drv, port); if (ret) goto err_unregister_port_dev; --=20 2.45.2 From nobody Tue Dec 16 19:56:47 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C38C11AC799; Thu, 20 Jun 2024 12:46:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718887605; cv=none; b=VALYywVcHwfTU2nFPo0e4763Gex1mA+RWNUdZqzYmnSJypUAYCdRFRuCWgLx1+Ltih329z64mse6ChQfRwQnW8rZOVoz8htk7IUgYK+tAUiH76cLrRUqy1x8IG1e4XI7+N2SpfP+YCO52lzlfb2zm2HmmKd7UXQASw5DbuuLjwQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718887605; c=relaxed/simple; bh=eaqYx0tP7xE/NKkuA/s0zoqf+t488PDvb5zZwZQtox0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O2KlRqb4XPCFZKlQf/GqsCFSuKu8clk2RMbFYAde60rUyBDsV1tkDVXQkOw3vaL4t3EueAzD2dAfgy/8OYN2iqPpchPbZJ4rDCp3IUJ1w65/zNP+If5+8VGtL1EQceax2VbgsfWlmEf2xKcicGWpk0/Tb+BLAjoQC0Cr7EY9D6M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=PnB1hhJd; arc=none smtp.client-ip=198.175.65.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="PnB1hhJd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718887604; x=1750423604; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eaqYx0tP7xE/NKkuA/s0zoqf+t488PDvb5zZwZQtox0=; b=PnB1hhJdV7w2U1PpH3FAa+0a8UT6s8Ae1zOrtJ9Y76PKcfLbBniVtZzu ammVgYieepp8VTY7NRI8Nw5mUfD0ERzmMaRXNLMWV0uj7yZC/BvEtC6fH 5OMGMpzHoSiBatxrDIa1V7GjIbF1EnLjk3bqmGSok2/7mFokVTTlROqIq /biSapXIB/kpeqGr+H33hQHpOHTGaEC0KD+FTPHV+sKaDHsOmsqU4xWTv RLJjRgQzkFJ7IGPA1KQOowRJ7+G3tW35nzE8huSV+ebuEREAPUZBUarmB /5T/lnxP03T40K0tysxVSJxxgNIo6FUPaZFkbj1fFx2I8GUsd0VR95pgn Q==; X-CSE-ConnectionGUID: egMwXlQkSZOHDvJ5u4Aswg== X-CSE-MsgGUID: GJDKnLGbR9GwaGXnqnLlDQ== X-IronPort-AV: E=McAfee;i="6700,10204,11108"; a="26985698" X-IronPort-AV: E=Sophos;i="6.08,252,1712646000"; d="scan'208";a="26985698" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jun 2024 05:46:43 -0700 X-CSE-ConnectionGUID: bKrI8d5JQ1CaEc9iGsMd9Q== X-CSE-MsgGUID: K0oDnHn1T1msDYgNtXmxCg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,252,1712646000"; d="scan'208";a="42888798" Received: from ijarvine-desk1.ger.corp.intel.com (HELO tlindgre-MOBL1.intel.com) ([10.245.247.35]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jun 2024 05:46:39 -0700 From: Tony Lindgren To: Greg Kroah-Hartman , Jiri Slaby , Petr Mladek , Steven Rostedt , John Ogness , Sergey Senozhatsky , Andy Shevchenko , Tony Lindgren Cc: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , linux-serial@vger.kernel.org, Tony Lindgren , linux-kernel@vger.kernel.org Subject: [PATCH v4 4/4] serial: core: Add serial_base_match_and_update_preferred_console() Date: Thu, 20 Jun 2024 15:45:29 +0300 Message-ID: <20240620124541.164931-5-tony.lindgren@linux.intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240620124541.164931-1-tony.lindgren@linux.intel.com> References: <20240620124541.164931-1-tony.lindgren@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Let's add serial_base_match_and_update_preferred_console() for consoles using DEVNAME:0.0 style naming. The earlier approach to add it caused issues in the kernel command line ordering as we were calling __add_preferred_console() again for the deferred consoles. Signed-off-by: Tony Lindgren Reviewed-by: Petr Mladek Tested-by: Petr Mladek --- drivers/tty/serial/serial_base.h | 16 ++++++++++++ drivers/tty/serial/serial_base_bus.c | 37 ++++++++++++++++++++++++++++ drivers/tty/serial/serial_core.c | 4 +++ 3 files changed, 57 insertions(+) diff --git a/drivers/tty/serial/serial_base.h b/drivers/tty/serial/serial_b= ase.h index b6c38d2edfd4..0d50db5b660b 100644 --- a/drivers/tty/serial/serial_base.h +++ b/drivers/tty/serial/serial_base.h @@ -49,3 +49,19 @@ void serial_ctrl_unregister_port(struct uart_driver *drv= , struct uart_port *port =20 int serial_core_register_port(struct uart_driver *drv, struct uart_port *p= ort); void serial_core_unregister_port(struct uart_driver *drv, struct uart_port= *port); + +#ifdef CONFIG_SERIAL_CORE_CONSOLE + +int serial_base_match_and_update_preferred_console(struct uart_driver *drv, + struct uart_port *port); + +#else + +static inline +int serial_base_match_and_update_preferred_console(struct uart_driver *drv, + struct uart_port *port) +{ + return 0; +} + +#endif diff --git a/drivers/tty/serial/serial_base_bus.c b/drivers/tty/serial/seri= al_base_bus.c index 4df2a4b10445..d822499ba9d6 100644 --- a/drivers/tty/serial/serial_base_bus.c +++ b/drivers/tty/serial/serial_base_bus.c @@ -8,6 +8,7 @@ * The serial core bus manages the serial core controller instances. */ =20 +#include #include #include #include @@ -204,6 +205,42 @@ void serial_base_port_device_remove(struct serial_port= _device *port_dev) put_device(&port_dev->dev); } =20 +#ifdef CONFIG_SERIAL_CORE_CONSOLE + +/** + * serial_base_match_and_update_preferred_console - Match and update a pre= ferred console + * @drv: Serial port device driver + * @port: Serial port instance + * + * Tries to match and update the preferred console for a serial port for + * the kernel command line option console=3DDEVNAME:0.0. + * + * Cannot be called early for ISA ports, depends on struct device. + * + * Return: 0 on success, negative error code on failure. + */ +int serial_base_match_and_update_preferred_console(struct uart_driver *drv, + struct uart_port *port) +{ + const char *port_match __free(kfree) =3D NULL; + int ret; + + port_match =3D kasprintf(GFP_KERNEL, "%s:%d.%d", dev_name(port->dev), + port->ctrl_id, port->port_id); + if (!port_match) + return -ENOMEM; + + ret =3D match_devname_and_update_preferred_console(port_match, + drv->dev_name, + port->line); + if (ret =3D=3D -ENOENT) + return 0; + + return ret; +} + +#endif + static int serial_base_init(void) { int ret; diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_c= ore.c index 2a8006e3d687..9a18d0b95a41 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -3422,6 +3422,10 @@ int serial_core_register_port(struct uart_driver *dr= v, struct uart_port *port) if (ret) goto err_unregister_ctrl_dev; =20 + ret =3D serial_base_match_and_update_preferred_console(drv, port); + if (ret) + goto err_unregister_port_dev; + ret =3D serial_core_add_one_port(drv, port); if (ret) goto err_unregister_port_dev; --=20 2.45.2