From nobody Wed Jun 17 06:03:55 2026 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51EC23B8BB2 for ; Thu, 23 Apr 2026 13:00:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776949249; cv=none; b=kFGjGQkeLEQt7X0GWHhZDzU4kpDoWG7r1dkqKHmDeY+Uop3s+ORHbfTB5j4a9Qt+Gv8klqyHE338duKYQn2lCMBoEvVs0WJL/7qjDlfMjVQ/mthV4HVn5YAQntkwmGEiZ/hz9KKEAHSF+niGyKJ6Q/9+mKvYR4pLZ0lJsYL+CoU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776949249; c=relaxed/simple; bh=KBBbp9RPzT5DhI7x83BIuaJnuih3ABx2BO6mdc6Z9GI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l3x/8D/sV4j07j9FXRNjQ0gxwtWuCViLvRnMsvM6It7n+ZfAos+cyjxgU/SzTjat5YqFIdaA1fjPDqH7dhI/8gazB5izSkYpVK+wlmK9i0NyGy1tJ0qu9dhxDQCR+XSwTkdJSKXiffJRvhS+gpC9HF/pbu2682quQlCV2K28FBE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=RvCmdEn+; arc=none smtp.client-ip=209.85.221.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="RvCmdEn+" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-43d70b3e159so3382803f8f.0 for ; Thu, 23 Apr 2026 06:00:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1776949246; x=1777554046; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YXU/CVd+HuekChrSCq98S5OtHKxgdKLmUmDoJCNdaUk=; b=RvCmdEn+ccFJXb5irWzgwY/Sy2hVJlUraZdWWsCwxo8gzH+PCGS1VzMiLzryQNA6zW U8JSZOIozECGEuo+dsGHVfqr02tUeL6SclR4M8zo95NbIA6m+uv7GBYDA45y5Y+OG5QH BUi27S+juglwPngi4gx6LuYwcreByBf4TqC4tO56yNFpN6/rCH62JcFC2b1GOfatU8+V sKRzPpl/lOHbUzILrk8/rUd73twqXEFEYdZTzMGjvXuAP3mf1sxy5oGBe4jR3PXJjib5 2Jdgt4ziUoxNRfyCE1VfWvj5xxiSqWc8Wz1wr8GREBFy4ZTmwMMJhggrm92pdJuVQZT0 +t9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776949246; x=1777554046; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=YXU/CVd+HuekChrSCq98S5OtHKxgdKLmUmDoJCNdaUk=; b=HM2zy+7OYPSPvlS2dyvP0BmYQczeXOHsQf7T7NCwW735Zx/NNWSQn6BC7Gchhclm0e kFiDi1K1zamAupO3uhDr7vNMncEAOKr1+hJ65sxXeBzHMcDtRbLmXGjQiaw/QeulmbVU vJUwZ2J5fpBL3Obt3XU2KyfDix8i9wNryX/QEKUy7ySLv1qpCwnH9V7TiwkwFgNcgbwE aO2jv8tbwgp8+1hkSB3II6IqSf6PlvkWbaQIu1eYjelLRZeqUttDvDG0jF8v8pAlq9JU BjvtSHa9f4jxTIbzQNxO5vSm6se9uOBYFSvNBdy0JEEUleayvgjR48GI82SVt8Zt2zlU Xd/A== X-Forwarded-Encrypted: i=1; AFNElJ8G1qMaRMWPWwRFb0olkOKAClBYqBVQrZAxQVrVp/2a5/h6um7XWhAYkPROBjzzUwI4zrBbtmqjqJ3DnoE=@vger.kernel.org X-Gm-Message-State: AOJu0YwN3cCtxRVuaAwK5wW0w98ZahCsfNzJuytPnNMNTU60tRrJ/03b AfprT23d/7sw7NcIr+ZK+YFYbpGu0BNu9nuzZ946iY28eZJRLTF78mfoAhJwCWQu6R4= X-Gm-Gg: AeBDiesysFQmIxaBPoZe54dmfeZ09oAG9G0MHftQOxltml45zXrx7k+mgnwX1LhqLlR 2LGmHES08sHSaBZkneMUIa2Q8ABnM6o+wVukWoRSIM8iNAsOWPhAgvPigUBjIizhBujPizPIUP6 a2/VMczZRnpehg+960RmiT0zxWna3VqwBrJZp5dqJ+/kvF2UGmFwJT9vI8QIeVZbxlvXDQa5n7s zrVrmWwSYOfYwBpVSfy6QwQK6e/+KifUA8uOxp5DEFWnkmndeaKBo45wrJWLOO2SVEUBOQv7vXt +RRw6OEEJZVEUHZpTEcaU8r2sreI3ocGqrB3urkBtRLjZxNeaPQJPFpKWXtJ+7Gwh0ffJTEnFI/ wSfpCcSnL0GjwjQfZtmVEL6PL46uHP3JNewiD7uGD3bm0EdHsr0cYU9+jSicB3uFMmc/f1jPi/V hKTQY/kCoaYyZ0bcBhc7CE82tYiW1d9gKdtSlv X-Received: by 2002:a05:6000:4381:b0:43f:e791:a333 with SMTP id ffacd0b85a97d-43fe791a3a6mr40497902f8f.29.1776949245361; Thu, 23 Apr 2026 06:00:45 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43fe4e3a166sm51866511f8f.19.2026.04.23.06.00.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2026 06:00:45 -0700 (PDT) From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Steven Rostedt , Marcos Paulo de Souza , Chris Down , linux-kernel@vger.kernel.org, Petr Mladek Subject: [PATCH v2 1/9] printk: Rename struct console_cmdline to preferred_console Date: Thu, 23 Apr 2026 15:00:06 +0200 Message-ID: <20260423130015.85175-2-pmladek@suse.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260423130015.85175-1-pmladek@suse.com> References: <20260423130015.85175-1-pmladek@suse.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" The structure 'console_cmdline' was originally intended to store details about consoles defined on the kernel command line. However, its usage has since expanded; it now stores information for consoles preferred via SPCR, device tree, or by particular platforms, e.g. XEN. The current naming is misleading as it implies the configuration only originates from the command line. Rename the structure and associated artifacts to better reflect their current purpose, for example: - struct console_cmdline c -> struct preferred_console pc - console_cmdline[] -> preferred_consoles[] - console_cmdline.h -> console_register.h - c -> pc Additionally, renaming the header file to console_register.h would eventually allow to decouple console registration logic from the monolithic printk.c. Finally, renaming the local variable from "c" to "pc" helps to distinguish it from struct console variables. Note that "c" is used for struct console in some code, for example see vt_console_device() function definition. The patch should not change the existing behaivor. Signed-off-by: Petr Mladek Acked-by: Chris Down Acked-by: Marcos Paulo de Souza Reviewed-by: John Ogness --- kernel/printk/braille.c | 10 +-- kernel/printk/braille.h | 10 +-- .../{console_cmdline.h =3D> console_register.h} | 6 +- kernel/printk/printk.c | 86 ++++++++++--------- 4 files changed, 57 insertions(+), 55 deletions(-) rename kernel/printk/{console_cmdline.h =3D> console_register.h} (83%) diff --git a/kernel/printk/braille.c b/kernel/printk/braille.c index 17a9591e54ff..9d21a2bb1d38 100644 --- a/kernel/printk/braille.c +++ b/kernel/printk/braille.c @@ -6,7 +6,7 @@ #include #include =20 -#include "console_cmdline.h" +#include "console_register.h" #include "braille.h" =20 int _braille_console_setup(char **str, char **brl_options) @@ -35,14 +35,14 @@ int _braille_console_setup(char **str, char **brl_optio= ns) } =20 int -_braille_register_console(struct console *console, struct console_cmdline = *c) +_braille_register_console(struct console *console, struct preferred_consol= e *pc) { int rtn =3D 0; =20 - if (c->brl_options) { + if (pc->brl_options) { console->flags |=3D CON_BRL; - rtn =3D braille_register_console(console, c->index, c->options, - c->brl_options); + rtn =3D braille_register_console(console, pc->index, pc->options, + pc->brl_options); } =20 return rtn; diff --git a/kernel/printk/braille.h b/kernel/printk/braille.h index 123154f86304..55cd3178a17a 100644 --- a/kernel/printk/braille.h +++ b/kernel/printk/braille.h @@ -5,9 +5,9 @@ #ifdef CONFIG_A11Y_BRAILLE_CONSOLE =20 static inline void -braille_set_options(struct console_cmdline *c, char *brl_options) +braille_set_options(struct preferred_console *pc, char *brl_options) { - c->brl_options =3D brl_options; + pc->brl_options =3D brl_options; } =20 /* @@ -21,7 +21,7 @@ int _braille_console_setup(char **str, char **brl_options); =20 int -_braille_register_console(struct console *console, struct console_cmdline = *c); +_braille_register_console(struct console *console, struct preferred_consol= e *pc); =20 int _braille_unregister_console(struct console *console); @@ -29,7 +29,7 @@ _braille_unregister_console(struct console *console); #else =20 static inline void -braille_set_options(struct console_cmdline *c, char *brl_options) +braille_set_options(struct preferred_console *pc, char *brl_options) { } =20 @@ -40,7 +40,7 @@ _braille_console_setup(char **str, char **brl_options) } =20 static inline int -_braille_register_console(struct console *console, struct console_cmdline = *c) +_braille_register_console(struct console *console, struct preferred_consol= e *pc) { return 0; } diff --git a/kernel/printk/console_cmdline.h b/kernel/printk/console_regist= er.h similarity index 83% rename from kernel/printk/console_cmdline.h rename to kernel/printk/console_register.h index 0ab573b6d4dc..9ab3e1cc749b 100644 --- a/kernel/printk/console_cmdline.h +++ b/kernel/printk/console_register.h @@ -1,8 +1,8 @@ /* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _CONSOLE_CMDLINE_H -#define _CONSOLE_CMDLINE_H +#ifndef _CONSOLE_REGISTER_H +#define _CONSOLE_REGISTER_H =20 -struct console_cmdline +struct preferred_console { char name[16]; /* Name of the driver */ int index; /* Minor dev. to use */ diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 0323149548f6..ca523acbf58d 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -58,7 +58,7 @@ #include =20 #include "printk_ringbuffer.h" -#include "console_cmdline.h" +#include "console_register.h" #include "braille.h" #include "internal.h" =20 @@ -362,9 +362,9 @@ static int console_locked; * Array of consoles built from command line options (console=3D) */ =20 -#define MAX_CMDLINECONSOLES 8 +#define MAX_PREFERRED_CONSOLES 8 =20 -static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES]; +static struct preferred_console preferred_consoles[MAX_PREFERRED_CONSOLES]; =20 static int preferred_console =3D -1; int console_set_on_cmdline; @@ -2544,16 +2544,16 @@ asmlinkage __visible void early_printk(const char *= fmt, ...) } #endif =20 -static void set_user_specified(struct console_cmdline *c, bool user_specif= ied) +static void set_user_specified(struct preferred_console *pc, bool user_spe= cified) { if (!user_specified) return; =20 /* - * @c console was defined by the user on the command line. + * @pc console was defined by the user on the command line. * Do not clear when added twice also by SPCR or the device tree. */ - c->user_specified =3D true; + pc->user_specified =3D true; /* At least one console defined by the user on the command line. */ console_set_on_cmdline =3D 1; } @@ -2562,7 +2562,7 @@ 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; + struct preferred_console *pc; int i; =20 if (!name && !devname) @@ -2581,30 +2581,30 @@ static int __add_preferred_console(const char *name= , const short idx, * See if this tty is not yet registered, and * if we have a slot free. */ - for (i =3D 0, c =3D console_cmdline; - i < MAX_CMDLINECONSOLES && (c->name[0] || c->devname[0]); - i++, c++) { - if ((name && strcmp(c->name, name) =3D=3D 0 && c->index =3D=3D idx) || - (devname && strcmp(c->devname, devname) =3D=3D 0)) { + for (i =3D 0, pc =3D preferred_consoles; + i < MAX_PREFERRED_CONSOLES && (pc->name[0] || pc->devname[0]); + i++, pc++) { + if ((name && strcmp(pc->name, name) =3D=3D 0 && pc->index =3D=3D idx) || + (devname && strcmp(pc->devname, devname) =3D=3D 0)) { if (!brl_options) preferred_console =3D i; - set_user_specified(c, user_specified); + set_user_specified(pc, user_specified); return 0; } } - if (i =3D=3D MAX_CMDLINECONSOLES) + if (i =3D=3D MAX_PREFERRED_CONSOLES) return -E2BIG; if (!brl_options) preferred_console =3D i; if (name) - strscpy(c->name, name); + strscpy(pc->name, name); if (devname) - strscpy(c->devname, devname); - c->options =3D options; - set_user_specified(c, user_specified); - braille_set_options(c, brl_options); + strscpy(pc->devname, devname); + pc->options =3D options; + set_user_specified(pc, user_specified); + braille_set_options(pc, brl_options); =20 - c->index =3D idx; + pc->index =3D idx; return 0; } =20 @@ -2624,8 +2624,10 @@ __setup("console_msg_format=3D", console_msg_format_= setup); */ static int __init console_setup(char *str) { - static_assert(sizeof(console_cmdline[0].devname) >=3D sizeof(console_cmdl= ine[0].name) + 4); - char buf[sizeof(console_cmdline[0].devname)]; + static_assert(sizeof(preferred_consoles[0].devname) >=3D + sizeof(preferred_consoles[0].name) + 4); + + char buf[sizeof(preferred_consoles[0].devname)]; char *brl_options =3D NULL; char *ttyname =3D NULL; char *devname =3D NULL; @@ -2730,19 +2732,19 @@ int match_devname_and_update_preferred_console(cons= t char *devname, const char *name, const short idx) { - struct console_cmdline *c =3D console_cmdline; + struct preferred_console *pc =3D preferred_consoles; int i; =20 if (!devname || !strlen(devname) || !name || !strlen(name) || idx < 0) return -EINVAL; =20 - for (i =3D 0; i < MAX_CMDLINECONSOLES && (c->name[0] || c->devname[0]); - i++, c++) { - if (!strcmp(devname, c->devname)) { + for (i =3D 0; i < MAX_PREFERRED_CONSOLES && (pc->name[0] || pc->devname[0= ]); + i++, pc++) { + if (!strcmp(devname, pc->devname)) { pr_info("associate the preferred console \"%s\" with \"%s%d\"\n", devname, name, idx); - strscpy(c->name, name); - c->index =3D idx; + strscpy(pc->name, name); + pc->index =3D idx; return 0; } } @@ -3897,33 +3899,33 @@ static int console_call_setup(struct console *newco= n, char *options) static int try_enable_preferred_console(struct console *newcon, bool user_specified) { - struct console_cmdline *c; + struct preferred_console *pc; int i, err; =20 - for (i =3D 0, c =3D console_cmdline; - i < MAX_CMDLINECONSOLES && (c->name[0] || c->devname[0]); - i++, c++) { + for (i =3D 0, pc =3D preferred_consoles; + i < MAX_PREFERRED_CONSOLES && (pc->name[0] || pc->devname[0]); + i++, pc++) { /* Console not yet initialized? */ - if (!c->name[0]) + if (!pc->name[0]) continue; - if (c->user_specified !=3D user_specified) + if (pc->user_specified !=3D user_specified) continue; if (!newcon->match || - newcon->match(newcon, c->name, c->index, c->options) !=3D 0) { + newcon->match(newcon, pc->name, pc->index, pc->options) !=3D 0) { /* default matching */ - BUILD_BUG_ON(sizeof(c->name) !=3D sizeof(newcon->name)); - if (strcmp(c->name, newcon->name) !=3D 0) + BUILD_BUG_ON(sizeof(pc->name) !=3D sizeof(newcon->name)); + if (strcmp(pc->name, newcon->name) !=3D 0) continue; if (newcon->index >=3D 0 && - newcon->index !=3D c->index) + newcon->index !=3D pc->index) continue; if (newcon->index < 0) - newcon->index =3D c->index; + newcon->index =3D pc->index; =20 - if (_braille_register_console(newcon, c)) + if (_braille_register_console(newcon, pc)) return 0; =20 - err =3D console_call_setup(newcon, c->options); + err =3D console_call_setup(newcon, pc->options); if (err) return err; } @@ -3938,7 +3940,7 @@ static int try_enable_preferred_console(struct consol= e *newcon, * without matching. Accept the pre-enabled consoles only when match() * and setup() had a chance to be called. */ - if (newcon->flags & CON_ENABLED && c->user_specified =3D=3D user_specifie= d) + if (newcon->flags & CON_ENABLED && pc->user_specified =3D=3D user_specifi= ed) return 0; =20 return -ENOENT; --=20 2.53.0 From nobody Wed Jun 17 06:03:55 2026 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F06036EAAE for ; Thu, 23 Apr 2026 13:00:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776949261; cv=none; b=vFaB1cvns0KxS5IHaHJ3DDiycXyD3VwyL8RIRMSDS+y4Uk+kZH5TVuCp5nmpFC7/agSkmOWquL7C5gYrmAAvN/h8wyoxl/sUqzfBlsQYFBpo1EUGOWDOp8zDoqf5Rbym/W3KSmR5z1syQWumT0TGSSESGyW/YrVG5O5MnEPjXuc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776949261; c=relaxed/simple; bh=y56i9AnUSfG6NW1b3U3RDokjvzgiIPF0zsS76OYJKnA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DlCLiZtlgwNmT1gRgHb2cb+8MFkYYQ/Xu8FIGWWO4TvsQStsonKmXv9ogDKII5ah2Ig9QZHJtFkUyYyDBjHfrNA5idPaBDdm+biMyKZDe/twQHiQvX+K4fz1ARdrBYJoEFypDOabVmyFz46QOtpou1WCbhMzqORHtdKNLk8MZR0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=a7iXCGHa; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="a7iXCGHa" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-4891f625344so51189915e9.0 for ; Thu, 23 Apr 2026 06:00:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1776949258; x=1777554058; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=L7bjJ3c/8Y5FLJEd1+CplJ/Vg8Exx1lvA72Z7SAmuRY=; b=a7iXCGHarqT1aXOZRhyjaEsnb0O7JurOBpvLuPw4uJFMDxd4FaEKnA93m6h2LIH3Zc amMqFWzanpHKdnscpHlSZrQrRWQiBxycU+5Vhoa8/F0ZL0I6uNxuYV+sjNePqnskkxgM GbG/KaVKJpGg7O7qzU5BNaAyBrdw3xvJxfL9hUPoiCBj6KrNmwwAAuMpYMcug7MeNCtn r9cAX6u6NmOT5JNR850ypDc/RDxZj+dNcyiTkwgNPItOQW6XC6tJf7464m+SZ9ISrqeC HxVBrJVRu1WhivB7D5Z0ikIMfSiMCs6MeXjJw1gWnnqW2yg5Z+is60NSwpIeG/DhTL+r 2IyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776949258; x=1777554058; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=L7bjJ3c/8Y5FLJEd1+CplJ/Vg8Exx1lvA72Z7SAmuRY=; b=gQuFpkzRuG6y7ofaLEPeADZnH7xZy6vHLBIjGUxe0jFSR99ZAZ5M3PKPPhaJZ7yZrI nYQntqdmVTIix4migeNVkKyoXxrpwIO8v6Bvcmi9zf1Co9Gkc1lxu7/jzECglUZ/yCdY 7t16P/VUsye45ZwfV26TdjbqG1UtWwvnblSEaG0+a+qbaZzvlv5OUizIQGDgGv9MVnqk tKF42Y+hFP9alQJx4PlnslNA7ne3tgCRrhwrGc6PQnXjWZmQ2HAPfBkY5XOdhgcN7RaA 9JNX1euVcWIk6HloEiNFYUeLs6hOXK3xHJ3ZJ3VyWyy6Q45KOGyk2Wjf4EwU82RTUhJV EWVg== X-Forwarded-Encrypted: i=1; AFNElJ/L/+930zhTp0Jc3FjaItBF+5fHcTpYkGDKTV6Ilrodf+ikqD7nra0To8G9Xab3AKSUT6cutS8DqMoW/9c=@vger.kernel.org X-Gm-Message-State: AOJu0YwmCI/TQt/97QARQSZA8KMu7k2vqBZtsY9okzRfOmE4oxgqr+zX t2q8pE3oxBVO7Cu37AGLQbtUF9LTokc14SxuHp+EkUh/ukPgpTONmtBIn74RT8nswgY= X-Gm-Gg: AeBDievJclC6LQYQ0XHENBqto772ozaNMX0+GGRqVt8LM/k3lYK1V+zcT8PDJh0N4l6 x5wgULxLUQVdhpg2xq4PeeUuVdUY632Z5j1olW+N7iyEnDyd2UW4f1JlnKuqpYf1ZIyzAOpmPV6 b5DzAaQwKqgRzZc3eBQT/yjYRRBRuUPr/iy9L3pD7AZUtHiBqwBt3hvaOB0BKCGfd8UyDso1gnS aYqYolcZZ1rdXWCPpZecpm7MDKXPKPind3GH6+w4wVPuijh3PZgVtn4aBK8/p7cz9gJsrYxB3uQ T68+5ATVPOHdhrDh2PGHtCBPDFdGftwo+zGH9P4k6yHKRdnbRNe4cRfQKIeeLHZqQ5Eo6XrV6Ej vqsbA+K/IV5t+jZMq9irNGKR7mFq4WWSWYjfVd1VilEds1AMFmU4Ca9OAcOaqSXD7xI9pX2r1/f 9P+Ck/T4yCoXrAD73le5moaKO4IE1VlTzSE3ia X-Received: by 2002:a05:600c:4e0c:b0:489:1d7a:4537 with SMTP id 5b1f17b1804b1-4891d7a463emr234222355e9.3.1776949256937; Thu, 23 Apr 2026 06:00:56 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-488fb78d1bcsm228962965e9.5.2026.04.23.06.00.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2026 06:00:56 -0700 (PDT) From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Steven Rostedt , Marcos Paulo de Souza , Chris Down , linux-kernel@vger.kernel.org, Petr Mladek Subject: [PATCH v2 2/9] printk: Rename preferred_console to preferred_dev_console Date: Thu, 23 Apr 2026 15:00:07 +0200 Message-ID: <20260423130015.85175-3-pmladek@suse.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260423130015.85175-1-pmladek@suse.com> References: <20260423130015.85175-1-pmladek@suse.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" The preferred_consoles[] array stores information about consoles requested via the command line, SPCR, Device Tree, or platform-specific code. Within this array, the 'preferred_console' variable tracks the specific index that should be associated with /dev/console (typically the last non-braille console defined). The current name "preferred_console" is ambiguous and leads to confusion. It does not clearly communicate why one console is "more preferred" than others in the array. Furthermore, entries for Braille consoles can exist within the preferred_consoles[] array, yet they are never associated with /dev/console and do not receive standard printk() output. Consequently, the 'preferred_console' index must skip these entries, which is not immediately obvious from the name. Rename the variable to 'preferred_dev_console' to explicitly clarify its role in identifying which entry is linked to /dev/console. The patch should not change the existing behavior. Signed-off-by: Petr Mladek Acked-by: Chris Down Acked-by: Marcos Paulo de Souza Reviewed-by: John Ogness --- kernel/printk/printk.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index ca523acbf58d..13c98285892b 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -366,7 +366,7 @@ static int console_locked; =20 static struct preferred_console preferred_consoles[MAX_PREFERRED_CONSOLES]; =20 -static int preferred_console =3D -1; +static int preferred_dev_console =3D -1; int console_set_on_cmdline; EXPORT_SYMBOL(console_set_on_cmdline); =20 @@ -2587,7 +2587,7 @@ static int __add_preferred_console(const char *name, = const short idx, if ((name && strcmp(pc->name, name) =3D=3D 0 && pc->index =3D=3D idx) || (devname && strcmp(pc->devname, devname) =3D=3D 0)) { if (!brl_options) - preferred_console =3D i; + preferred_dev_console =3D i; set_user_specified(pc, user_specified); return 0; } @@ -2595,7 +2595,7 @@ static int __add_preferred_console(const char *name, = const short idx, if (i =3D=3D MAX_PREFERRED_CONSOLES) return -E2BIG; if (!brl_options) - preferred_console =3D i; + preferred_dev_console =3D i; if (name) strscpy(pc->name, name); if (devname) @@ -3930,7 +3930,7 @@ static int try_enable_preferred_console(struct consol= e *newcon, return err; } newcon->flags |=3D CON_ENABLED; - if (i =3D=3D preferred_console) + if (i =3D=3D preferred_dev_console) newcon->flags |=3D CON_CONSDEV; return 0; } @@ -4111,7 +4111,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) { + if (preferred_dev_console < 0) { if (hlist_empty(&console_list) || !console_first()->device || console_first()->flags & CON_BOOT) { try_enable_default_console(newcon); --=20 2.53.0 From nobody Wed Jun 17 06:03:55 2026 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 567003A4F30 for ; Thu, 23 Apr 2026 13:01:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776949272; cv=none; b=VZFGQviRtNhxaIfudCL1uOZ/vLLPMdt+6hREArYgNPXNTnscPU33HcwGjwnXXlnrW6btH9e7QxwLSC9KBKsyBTobjgOxitMjzXA++8eeRcUJ/wekK6YayvkieY17pzPKQXoc7rCWtsvdEtEsfH9gg7m8U8hX8fYmer4J969/32A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776949272; c=relaxed/simple; bh=g95LC9VMza4PBvjpnZ4SS4ap5tSNtU6yyCGT7+TbMPA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J4VSs1pVmNQjk8dyYWLA2CYSEbb28fmq3aU9D2K8JjmZWcs6HJ5Lsn+ZW+G3FfZZxMK54EKc+znPtsJU8oLiPgzyNWzAF0+1htCEwe4tWw/wdjs9dCJENh8aHiFEV6kGDoUaKKh7+OwcFmNW+6cAFGFkYq7pom6TrSW8agqx1LE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=S9bnNKIJ; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="S9bnNKIJ" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4891d7164ddso28434555e9.3 for ; Thu, 23 Apr 2026 06:01:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1776949269; x=1777554069; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=V7eltpM4g30RwxCpVsv7pO4pBcBmlOR808n2PdluT1A=; b=S9bnNKIJkjFgyuigbQQPT8Xo6q1PhnTxuozCS/VAjZQ4OJFJj/gJbko62+TSWXbvxe oNuf7FL03Cr+8csDJ2CQd+TNyv1v/PreENVHBYk+w4z8mIGGOvIal2g2OyDRJY7A/4i+ LRBrq/Gui5kjdws3k40oazIMvGhmU9kzaJPtfj/B9oB7WRoe281BvfFsam4ITKyaD9IP W6PSueAnjnSHuYDHFmnv1ipXktx5pk5rIoL83AS/eeHf/c9shdUWUQBVRsyY8tSRjKA7 ULoG8D8wPfmc3JEQNH79PtWXmPxc0xnZ7zhG0fjpvS6ojwTU+tBqLZgAwccYccwcJpKV Rgxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776949269; x=1777554069; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=V7eltpM4g30RwxCpVsv7pO4pBcBmlOR808n2PdluT1A=; b=YrbZrZUgDxXVehvFsKUqCrQFW8Yrsy2Hbz4TT1iTiV+IjeOBx8NtaDQGjL7IBJwaNY xaSemhKhBf5mS9PSPXyEsCQCyOJ0C2S3JXcg/0xqPNhyKyGOkL/V0B0C/sGKsiCL0YVl 5pz6GnYc2q3L6Riq7Z/AcWuXKxov+PL726j8rWNlkRqTr6+nsY1f6Vn/W6IB9ygpv/gy qmoyB919KZs2F95MxffL6bWQhsTBIUMSIdOLVMeyolLBM3fE6AkkuTaiNTaY88O78lzM KA0PsdeuYU5aqUwnVsVFAgRrpPBoXtPQwTEcWb+1lHGESOX+fVtws63cIr4tG8kocsQj PjJw== X-Forwarded-Encrypted: i=1; AFNElJ9DKJjPL6ZODW/Z48MDUpVa1NVODYUzqLvBg5u9bw5cZ5dfwgKEe4/iEEMOksysgAvSKw5Z4uP+SzMfo7c=@vger.kernel.org X-Gm-Message-State: AOJu0YwJl/BJMpKp1yJAXKzU8EGf0QXfzDfXWnsnvKCIA3dEwlMZ0Tzv UFBAzhYhNm7a/oo7LzFYOmJpE/5Mi3g91U5fz08U8rwqADJbzv5LolFgm8BZnxflXzi4f8tpM7O XGrzqr74= X-Gm-Gg: AeBDieu40PhUm3HJbzLOnSP2R4THOFu+ibKY5uFhnEmCHth/+pLFXDE9gUXIN8jGyly umh2PFfC39XXi7aioEaQdq8muA3whlR6I9ZZVxdowB2VeemzdVFYOscoeE4HamcKX9uDa307+Gp ozR262NxeNnkg7kYs/avRkmaRIXYr7nq2x1U8TBreyLxxRE0wy3kZzOL4XC/qui/cYrmpREj3kE KbJem+bDg10wnZHrqvIP65gB5yW8DgXSsnLdiuHqwm6XVYpJqvWILSCE9MKz3Hbp8qAMDAPA3q+ EeylnwurwOQD7zQEzvgSO+RHQ1fnrDYfXuNjFLK8YD4YHxByMDJ2DNEDOF0ASdJ1BFwyYqnnin0 14EJrKiJiErHbgDI/djLytKa4DBrFbbQ3yJgbJRw70IRusbKLNoayT2Bor2OdTj1a2QkairiwG9 kaqoC7ggWHS7jOxrbZz8aawa49h/E6mToyUXat X-Received: by 2002:a05:600c:4e4f:b0:488:ab37:b442 with SMTP id 5b1f17b1804b1-488fb793c6bmr396900095e9.28.1776949268469; Thu, 23 Apr 2026 06:01:08 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-488fc14a61asm482717835e9.15.2026.04.23.06.01.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2026 06:01:07 -0700 (PDT) From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Steven Rostedt , Marcos Paulo de Souza , Chris Down , linux-kernel@vger.kernel.org, Petr Mladek Subject: [PATCH v2 3/9] printk: Separate code for adding/updating preferred console metadata Date: Thu, 23 Apr 2026 15:00:08 +0200 Message-ID: <20260423130015.85175-4-pmladek@suse.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260423130015.85175-1-pmladek@suse.com> References: <20260423130015.85175-1-pmladek@suse.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" The logic for adding or updating a preferred console is currently duplicated within __add_preferred_console(), making the code difficult to follow and prone to consistency issues. Introduce update_preferred_console() to centralize the initialization and updating of struct preferred_console entries. This refactoring explicitly defines and enforces the following rules: 1. Console names and/or indexes are not set when a console is preferred via devname; these are resolved later during device matching. 2. Console names are only added alongside a valid index. 3. Only matching entries are updated. 4. Console and Braille options are never cleared. They are updated only via the command line. 5. The global 'preferred_dev_console' index and 'console_set_on_cmdline' flag are updated consistently. Additionally, rename braille_set_options() to braille_update_options() to better reflect its conditional behavior. Behavior change: The original code never updated the preferred console options when it was preferred more times, e.g. via the command line and/or some platform specific code, e.g. SPCR or device tree. The new code explicitly allows to update the console options when they are preferred over the command line. It mostly worked even before but only because the command line was processed early enough before handling SPCR, device tree, or other platform specific init code. The main behavior change is when the same console is preferred more times on the command line. Newly, the later or Braille variant wins. It is a more common and expected behavior. Signed-off-by: Petr Mladek Acked-by: Marcos Paulo de Souza Reviewed-by: John Ogness --- kernel/printk/braille.h | 7 +- kernel/printk/printk.c | 149 ++++++++++++++++++++++++++++++---------- 2 files changed, 118 insertions(+), 38 deletions(-) diff --git a/kernel/printk/braille.h b/kernel/printk/braille.h index 55cd3178a17a..0bdac303f8b1 100644 --- a/kernel/printk/braille.h +++ b/kernel/printk/braille.h @@ -5,9 +5,10 @@ #ifdef CONFIG_A11Y_BRAILLE_CONSOLE =20 static inline void -braille_set_options(struct preferred_console *pc, char *brl_options) +braille_update_options(struct preferred_console *pc, char *brl_options) { - pc->brl_options =3D brl_options; + if (brl_options) + pc->brl_options =3D brl_options; } =20 /* @@ -29,7 +30,7 @@ _braille_unregister_console(struct console *console); #else =20 static inline void -braille_set_options(struct preferred_console *pc, char *brl_options) +braille_update_options(struct preferred_console *pc, char *brl_options) { } =20 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 13c98285892b..d251bf8e104f 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2544,18 +2544,119 @@ asmlinkage __visible void early_printk(const char = *fmt, ...) } #endif =20 -static void set_user_specified(struct preferred_console *pc, bool user_spe= cified) +/** update_preferred_console - Update a given entry in the preferred_conso= les[] + * table. + * @i: index of the entry in @preferred_consoles table which should get up= dated. + * @name: The name of the preferred console driver. + * @idx: Preferred console index, e.g. port number. + * @devname: The name of the preferred physical device. + * @options: Options used when setting up the console driver. + * @brl_options: Options used when setting up the console driver + * as a braille console. + * @user_specified: True if preferred via the kernel command line. + * + * The function ensures that the given values are consistent. Also + * it updates some global variables which are used to make the right + * decisions in register_console(). + * + * Rules: + * + * 1. Either @name and valid @idx OR @devname and @idx=3D-1 are allowed. + * Note that a valid @name and @idx will get assigned later when + * @devname matches during the device initialization. + * 2. Specify @brl_options if the console should be enabled as + * a Braille console [*] + * 3. Only matching entries can be updated. + * 4. @options passed via the command line are used when the same + * console is preferred also by some platform-specific code. + * + * [*] Braille console is using the mechanism for registering consoles + * but it is very special. It is primarily used for user interaction + * with the system. It neither gets printk() messages nor is associated + * with /dev/console. + */ +static int update_preferred_console(unsigned int i, + const char *name, const short idx, + const char *devname, char *options, + char *brl_options, bool user_specified) { - if (!user_specified) - return; + struct preferred_console *pc; + + if (i >=3D MAX_PREFERRED_CONSOLES) + return -E2BIG; + + pc =3D &preferred_consoles[i]; + + if (!name && !devname) + return -EINVAL; + + if (devname) { + /* + * A valid console name and index will get assigned when + * a matching device gets registered. + */ + if (name) { + pr_err("Adding a preferred console devname with a hard-coded console na= me: %s, %s\n", + devname, name); + return -EINVAL; + } + if (pc->name[0]) { + pr_err("Updating a preferred console entry with an already assigned con= sole name via devname: %s, %s\n", + devname, pc->name); + return -EINVAL; + } + if (idx !=3D -1) { + pr_err("Adding a preferred console devname with a hard-coded index: %s,= %d\n", + devname, idx); + return -EINVAL; + } + + if (!pc->devname[0]) { + strscpy(pc->devname, devname); + pc->index =3D idx; + } else if (strcmp(pc->devname, devname) !=3D 0) { + pr_err("Updating a preferred console with an invalid devname: %s vs. %s= \n", + pc->devname, devname); + return -EINVAL; + } + } + + if (name) { + /* A console name must be defined with a valid index. */ + if (idx < 0) { + pr_err("Adding a preferred console with an invalid index: %s, %d\n", + name, idx); + return -EINVAL; + } + + if (!pc->name[0]) { + strscpy(pc->name, name); + pc->index =3D idx; + } else if (strcmp(pc->name, name) !=3D 0 || pc->index !=3D idx) { + pr_err("Updating a preferred console with an invalid name or index: %s%= d vs. %s%d\n", + pc->name, pc->index, name, idx); + return -EINVAL; + } + } + + if (!pc->options || (user_specified && options)) + pc->options =3D options; + + braille_update_options(pc, brl_options); + + if (!brl_options) + preferred_dev_console =3D i; =20 /* * @pc console was defined by the user on the command line. * Do not clear when added twice also by SPCR or the device tree. */ - pc->user_specified =3D true; - /* At least one console defined by the user on the command line. */ - console_set_on_cmdline =3D 1; + if (user_specified) { + pc->user_specified =3D true; + console_set_on_cmdline =3D 1; + } + + return 0; } =20 static int __add_preferred_console(const char *name, const short idx, @@ -2563,19 +2664,11 @@ static int __add_preferred_console(const char *name= , const short idx, char *brl_options, bool user_specified) { struct preferred_console *pc; - int i; + unsigned int i; =20 if (!name && !devname) return -EINVAL; =20 - /* - * 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 when the console name and index are defined on - * the command line. - */ - if (name && idx < 0) - return -EINVAL; =20 /* * See if this tty is not yet registered, and @@ -2584,28 +2677,14 @@ static int __add_preferred_console(const char *name= , const short idx, for (i =3D 0, pc =3D preferred_consoles; i < MAX_PREFERRED_CONSOLES && (pc->name[0] || pc->devname[0]); i++, pc++) { - if ((name && strcmp(pc->name, name) =3D=3D 0 && pc->index =3D=3D idx) || - (devname && strcmp(pc->devname, devname) =3D=3D 0)) { - if (!brl_options) - preferred_dev_console =3D i; - set_user_specified(pc, user_specified); - return 0; - } + if (name && strcmp(pc->name, name) =3D=3D 0 && pc->index =3D=3D idx) + break; + if (devname && strcmp(pc->devname, devname) =3D=3D 0) + break; } - if (i =3D=3D MAX_PREFERRED_CONSOLES) - return -E2BIG; - if (!brl_options) - preferred_dev_console =3D i; - if (name) - strscpy(pc->name, name); - if (devname) - strscpy(pc->devname, devname); - pc->options =3D options; - set_user_specified(pc, user_specified); - braille_set_options(pc, brl_options); =20 - pc->index =3D idx; - return 0; + return update_preferred_console(i, name, idx, devname, options, + brl_options, user_specified); } =20 static int __init console_msg_format_setup(char *str) --=20 2.53.0 From nobody Wed Jun 17 06:03:55 2026 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F13B23B8BB2 for ; Thu, 23 Apr 2026 13:01:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776949283; cv=none; b=E7etuPSH0eXf9GsZNGopT9ZQ/MgVZqRf/kRTiW/Sek1sbLl8lGP9+ZC0+tyajANbQz3IAfHlVrbgDIMrZ2/RimEafjgvBINaokgdCaGGTOmbIcz/WaK+43I3yHQr29rATBjJ7/USDwYPpMJp02dmScIW4oLXSiU25AujdPcsIdU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776949283; c=relaxed/simple; bh=+VBeH9oyGFsdhOP+o6agKwpvUyUUhqnwzA69eIXCSjY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f/YuQEStzWI3oMm9gff0cO5YvrePdwq3mujztlmg76unx9hYeR9tOGbr99T8PB5Hn06Y+X6v5YjuvrdGqt1/+Asrd4tTqJjOdMEBvtFgaxIU4Ya9Lgfh0xLJ63Uct1uRECHAV5f36wYLLMgoPAVAwuFrBUCwOA2M0ba/Cawdxio= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=dUYEDTTr; arc=none smtp.client-ip=209.85.221.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="dUYEDTTr" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-43d572f7437so4415303f8f.1 for ; Thu, 23 Apr 2026 06:01:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1776949280; x=1777554080; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YRsSHYNbUIrGTNk1cMXgUnL20Y0xVCc5kgWXyD53d7w=; b=dUYEDTTrnHOGLn5/hfENU9nYiUbZXyNXuFJhIemFfGhiB8Y0xwZbWgyXoopqlxM2U2 VFbc9ifmyVEYjHhNbZEcrfuPRFi4vC+NM17v6/NfPgz/LroeoPePRM+Nrz5H9veAY2z8 03dW4f5wYoM+om/u8MEuvxu4YTmNdq0qc+B2DzHhD334F+8PXxL5OKkQ/aoMVuUSSq+y rkcWOOrXw31swujbaabmjADAEM+K5bIDWoo3NdjDVw3Z1Ge9AI/05tBVb4PguAR8knL1 NWi65KxNaKDk0aZr3CuMAWBcZBnWxmxrr0cVZ9NGnSMy+eOGGRw2L6W/8l4x37KV4vzd OSTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776949280; x=1777554080; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=YRsSHYNbUIrGTNk1cMXgUnL20Y0xVCc5kgWXyD53d7w=; b=L0hTrTTQfYLbGiZr4hI68N1S63Tf8brS2eD8RvdrmvcWQVQKgTkSPZC72TV5X28Wvb B1r157oOubHWgmWVwSysWBZPQp4QAG5y9rqVnFUaFfg0jXMxOj69gWqGmyl0U0HdmXng G3OJh+upXX1ezSn6ZtQerjLIgJiiLiq7KTkWeWLl15sJajHlPakXXgOf7dv7Rad5L/bK XxsFg+3ACYgtsL5MLXzDw4J/+DaF2TDsT+i6rOmEg5QfLRbnGkiZKThhLjJTjQSeNQbT 7GUbIIt+Rpfdjxg0a7JIN3KjG/ZSgImccLWoOp+KB6qcAt5kW7OdZ1EEhkmMByJbRpdv amsw== X-Forwarded-Encrypted: i=1; AFNElJ9EGS6D3CWp3Vki3vKSg3z1XgN4m8BmCMUax8aSWoPV+LNS9zINNc6ekcl9ERcSiQdH9nsFNBZf9v+vC4U=@vger.kernel.org X-Gm-Message-State: AOJu0Yx7CBakcVjwXITXWuNT+Pge2u9IJiKSe0RfBiZYVvUwIi5UsYTE zusXYnmTq2KQD2hp/BzQXju+gnAb1/f0OU3Yr0LeEX2xSMl1ZCT0CIQD/xOMX1Swe8g= X-Gm-Gg: AeBDiesG5bqWXCcNVkUumlw5eE98CY3WdkyIPGCTN2khPk197s+uo6GB7pUBIwIRTds Fia/Ar3SlDd5HwgpcS00XejGmgsfiu/gyHyNQLDPgPV9b/zAhT1eQjNZUZ2sHxRuRCJfjOAJw4s Cq82g8rGaXZG73WyOstDBGxvhCg1WxeAzwqyNU95ybWYUvrYxlzuWcco0oIfTyxigCzil9WXAfk v66gM7NW2yZ4WLPglrlacdHC5W7PXGdYem4iQErXdRGxi4b2bUZ5SvgN8recVjhFxJ84ERUjn/M xm/28fwSITIVGWpCynxyxtSGca0c+bCgjtCTUcMqiVVFOqUrP6ufhsVEPpzrUkmvumx7BbRjFYN WAcFuyvNVATdEmsTDJgAl96Ge7ymoPqS25Tyk4tr70ACUPjTt5bZgVKMk6c8Cq8FMtVLb2u9q2S gPHm1LXH5uDQdpxG/zhxBVf7CQACkdQgp4FLTu X-Received: by 2002:a05:6000:1a8d:b0:439:ca9b:1f61 with SMTP id ffacd0b85a97d-43fe3dcbf0emr42427213f8f.17.1776949279978; Thu, 23 Apr 2026 06:01:19 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43fe4e4d112sm57663442f8f.29.2026.04.23.06.01.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2026 06:01:19 -0700 (PDT) From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Steven Rostedt , Marcos Paulo de Souza , Chris Down , linux-kernel@vger.kernel.org, Petr Mladek Subject: [PATCH v2 4/9] printk: Cleanup _braille_(un)register_console() wrappers Date: Thu, 23 Apr 2026 15:00:09 +0200 Message-ID: <20260423130015.85175-5-pmladek@suse.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260423130015.85175-1-pmladek@suse.com> References: <20260423130015.85175-1-pmladek@suse.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" The _braille_(un)register_console() wrappers currently attempt to hide implementation details like the CON_BRL flag and pc->brl_options. This forces callers to handle an unconventional tri-state return value (0 for NOP, >0 for success, <0 for error), which makes the control flow harder to follow and non-standard. Refactor the wrappers to use standard kernel return codes (0 for success, -ERRCODE on failure). Move the responsibility of checking brl_options to the caller to make the logic more explicit. Additionally, move the assignment of the CON_BRL flag from the internal wrapper to braille_register_console(). This aligns it with how CON_ENABLED is handled. To maintain symmetry and fix a potential bug where flags might persist after removal, explicitly clear both CON_ENABLED and CON_BRL in braille_unregister_console(). The patch should not change the existing behavior. Signed-off-by: Petr Mladek Acked-by: Chris Down Reviewed-by: Marcos Paulo de Souza Reviewed-by: John Ogness --- drivers/accessibility/braille/braille_console.c | 7 ++++--- kernel/printk/braille.c | 16 +++------------- kernel/printk/braille.h | 12 ++++++++++++ kernel/printk/printk.c | 13 +++++-------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/drivers/accessibility/braille/braille_console.c b/drivers/acce= ssibility/braille/braille_console.c index 06b43b678d6e..7b324329882f 100644 --- a/drivers/accessibility/braille/braille_console.c +++ b/drivers/accessibility/braille/braille_console.c @@ -360,12 +360,12 @@ int braille_register_console(struct console *console,= int index, if (ret !=3D 0) return ret; } - console->flags |=3D CON_ENABLED; + console->flags |=3D CON_ENABLED | CON_BRL; console->index =3D index; braille_co =3D console; register_keyboard_notifier(&keyboard_notifier_block); register_vt_notifier(&vt_notifier_block); - return 1; + return 0; } =20 int braille_unregister_console(struct console *console) @@ -375,5 +375,6 @@ int braille_unregister_console(struct console *console) unregister_keyboard_notifier(&keyboard_notifier_block); unregister_vt_notifier(&vt_notifier_block); braille_co =3D NULL; - return 1; + console->flags &=3D ~(CON_ENABLED | CON_BRL); + return 0; } diff --git a/kernel/printk/braille.c b/kernel/printk/braille.c index 9d21a2bb1d38..593f83eb0487 100644 --- a/kernel/printk/braille.c +++ b/kernel/printk/braille.c @@ -37,22 +37,12 @@ int _braille_console_setup(char **str, char **brl_optio= ns) int _braille_register_console(struct console *console, struct preferred_consol= e *pc) { - int rtn =3D 0; - - if (pc->brl_options) { - console->flags |=3D CON_BRL; - rtn =3D braille_register_console(console, pc->index, pc->options, - pc->brl_options); - } - - return rtn; + return braille_register_console(console, pc->index, pc->options, + pc->brl_options); } =20 int _braille_unregister_console(struct console *console) { - if (console->flags & CON_BRL) - return braille_unregister_console(console); - - return 0; + return braille_unregister_console(console); } diff --git a/kernel/printk/braille.h b/kernel/printk/braille.h index 0bdac303f8b1..ec5feac1f508 100644 --- a/kernel/printk/braille.h +++ b/kernel/printk/braille.h @@ -11,6 +11,12 @@ braille_update_options(struct preferred_console *pc, cha= r *brl_options) pc->brl_options =3D brl_options; } =20 +static inline bool +is_braille_console_preferred(struct preferred_console *pc) +{ + return (!!pc->brl_options); +} + /* * Setup console according to braille options. * Return -EINVAL on syntax error, 0 on success (or no braille option was @@ -34,6 +40,12 @@ braille_update_options(struct preferred_console *pc, cha= r *brl_options) { } =20 +static inline bool +is_braille_console_preferred(struct preferred_console *pc) +{ + return false; +} + static inline int _braille_console_setup(char **str, char **brl_options) { diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index d251bf8e104f..7a3bbb0cb794 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -4001,8 +4001,8 @@ static int try_enable_preferred_console(struct consol= e *newcon, if (newcon->index < 0) newcon->index =3D pc->index; =20 - if (_braille_register_console(newcon, pc)) - return 0; + if (is_braille_console_preferred(pc)) + return _braille_register_console(newcon, pc); =20 err =3D console_call_setup(newcon, pc->options); if (err) @@ -4314,17 +4314,14 @@ static int unregister_console_locked(struct console= *console) bool found_boot_con =3D false; unsigned long flags; struct console *c; - int res; + int res =3D 0; =20 lockdep_assert_console_list_lock_held(); =20 con_printk(KERN_INFO, console, "disabled\n"); =20 - res =3D _braille_unregister_console(console); - if (res < 0) - return res; - if (res > 0) - return 0; + if (console->flags & CON_BRL) + return _braille_unregister_console(console); =20 if (!console_is_registered_locked(console)) res =3D -ENODEV; --=20 2.53.0 From nobody Wed Jun 17 06:03:55 2026 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F8D23E6DD0 for ; Thu, 23 Apr 2026 13:01:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776949309; cv=none; b=gYRTklk2BsaVmtwVhDSGHvQvbxw3TvKud5Dp/l0lbJs76SL5Yw6QW29U54nclQQ/y55XnJ0ULe6vsBtoH7DLgu66P0OQ/Ay4rgRAC3BuY+2v5m/36Twt2t8fSWPLmTFmasEZnE/ahC8XHbRDq0cH5AVxDr5h3TwcLPCDXo/UPAo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776949309; c=relaxed/simple; bh=sWEHt4jXjnVtx1hKAGTyEqrt/XaYDLvuDRAPACMvvyA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P/nU7ChRfOm59dg9KrpzaYyF6axeKAZMVNiXkYo/ST7/DHyxzDYLQgg3xzNrZ3HJ+9G7k8azx36q3FzlLIjlKMFpYchesAisWyvHTw5iGXpv8GfDYF9GeNiY7AvZJvqWTxXBH9p0/6AFiFOIveChLA8AsSb1pJ4Nh4Q5ylzmaOY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=MjNy/Af4; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="MjNy/Af4" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-488d2079582so77666095e9.2 for ; Thu, 23 Apr 2026 06:01:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1776949307; x=1777554107; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RcYfeJ46/SlgH0YRv/BkhmlZvOuSIujY9Aw9ElcLZus=; b=MjNy/Af4Ky2YzNbFf/QyaJxZIWN1W11x7WHIA3YRGyTx0xoVbq01cgbLhyD1DjCTAM gW3UeazerRpfZdEeOcchR3Vc7322tneMPkehDozoskMpTl9RnkeoYGC/6+vGTJyJgHFu ND8YI2QCuR6sBx/PLBqYXltNsWzLfYdse0tct3wsZkyVyX/92l4aTMmbdfTeOzmCY08d 6zHnyzmtO4gR5FH25pAaGHFOvkCP+SKeg/QskCOSe7PbjisG/89tjoiIaQhsE2DO0LS7 GZGSAe4926fkS0M5dK7iJQ4plgXBXEkWObMXy5Sm+C29dcSHEzjgVnaDtD8m7Nd3umvL XJ5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776949307; x=1777554107; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=RcYfeJ46/SlgH0YRv/BkhmlZvOuSIujY9Aw9ElcLZus=; b=sZaUimYgMms8cfb4DwimH/QqNue55AxO4jFvaR16DkiPP54OYQZhY8OOxbVJ28WetR 03aeiQwVhIs+CA2Avc5bJE5+V+Uy+jmsrN8bMRUEbkXn6Yo3gggky8/5ZwI7y7oNJAVZ OKRmO2J+o49t97CTcCpcglSOZeDU4JkrZU/0llAO7/7xW/y8MKUWSWN9ht6/UsjO6fYM KqVMU2+ZIOd74gk2h2unJFAAKISc7y6En7X7v9nkLno5e4q/pIuNpxcHCTeYoUGn9Jcr huhjhAgTQn2bfR2R5JTMOjRBQ71Ip6+hC10r0IUsO3LxXSZHIJrPgOplEYEdaiq81zzF BDUg== X-Forwarded-Encrypted: i=1; AFNElJ9pqCJnS9NYoLUarm1wWsJzQBnQdqyL/kBl0p5a7iEz2DSwFyne4wMgWPKhEGPFdVYHCN+D16pYil6y2ks=@vger.kernel.org X-Gm-Message-State: AOJu0YyUDFWte1jlfAuAcqc9bxNxaEgugODUNwuYrGsgcEJhkP5F5WUq Ku2oRyTFOeJyHFLA1x5wEnWhlsqwqPClkOmBjaLbQl3fGqY114FI8XoELYzHXf2xOvk= X-Gm-Gg: AeBDieuywpJKubxaxWjVHW7+DeQkQyiZL/HlPdrGtqfv8xZmItRrQ7Ug5o1Aoc1UQNs S3q58UfWRIZEA6w5di2Wu1X6IsgUbZM4eNdLxftaEPkAYrUctbHWjVdhtf3sUP473FXORDzmJXh hP1vRn1PP569UWoEpiNbPIWEmiSgvqN3IspvSOjezU1xtfgCIC1jpjJ+ZyniXCE2T8j3fBxf1KM tWBNMFGhN4Dkeh5WaU+XA9v/OsbiOWZOAGiwz7KgcxYkRIqmim9kdb2o7cyJrHQesUu7hc4Mtc4 tRd4o+wGvPhTDcgQS+RFS3y9QE2rseacjHvUKQILRI7UssILIhmD6fXMQeZ2tlgRyAckQ4J25tK 5cSAqEPtBMLdOMaGMzxxxMHglk3ykjnIvuQaoGuiVWm2CNgAVfeObjln7JcChHgGuR8bQZ14I9o +wGVKkEB6LSFHrelELziAcOIu6WigsTj+5xx+f/B797D8+aeY= X-Received: by 2002:a05:600c:a117:b0:48a:58ae:992f with SMTP id 5b1f17b1804b1-48a58ae9ec5mr97858215e9.16.1776949306523; Thu, 23 Apr 2026 06:01:46 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-488fb74c789sm154931695e9.5.2026.04.23.06.01.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2026 06:01:43 -0700 (PDT) From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Steven Rostedt , Marcos Paulo de Souza , Chris Down , linux-kernel@vger.kernel.org, Petr Mladek Subject: [PATCH v2 5/9] printk: Separate code for enabling console Date: Thu, 23 Apr 2026 15:00:10 +0200 Message-ID: <20260423130015.85175-6-pmladek@suse.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260423130015.85175-1-pmladek@suse.com> References: <20260423130015.85175-1-pmladek@suse.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 are several code paths which try to enable a newly registered console. Move the logic into a separate try_enable_console() function. It simplifies a bit the long register_console() function definition. Also followup patches are going to add even more code paths. And it will be easier to use "return" when it does not make sense to try other variants. The patch does not change the existing behavior. Signed-off-by: Petr Mladek Acked-by: Marcos Paulo de Souza Reviewed-by: John Ogness --- kernel/printk/printk.c | 64 ++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 7a3bbb0cb794..2543c810efcb 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -4040,6 +4040,41 @@ static void try_enable_default_console(struct consol= e *newcon) newcon->flags |=3D CON_CONSDEV; } =20 +#define console_first() \ + hlist_entry(console_list.first, struct console, node) + +static int try_enable_console(struct console *newcon) +{ + int err; + + /* + * See if we want to enable this console driver by default. + * + * Nope when a console is preferred by the command line, device + * tree, or SPCR. + * + * The first real console with tty binding (driver) wins. More + * consoles might get enabled before the right one is found. + * + * Note that a console with tty binding will have CON_CONSDEV + * flag set and will be first in the list. + */ + if (preferred_dev_console < 0) { + if (hlist_empty(&console_list) || !console_first()->device || + console_first()->flags & CON_BOOT) { + try_enable_default_console(newcon); + } + } + + /* See if this console matches one we selected on the command line */ + err =3D try_enable_preferred_console(newcon, true); + if (err !=3D -ENOENT) + return err; + + /* If not, try to match against the platform default(s) */ + return try_enable_preferred_console(newcon, false); +} + /* Return the starting sequence number for a newly registered console. */ static u64 get_init_console_seq(struct console *newcon, bool bootcon_regis= tered) { @@ -4114,9 +4149,6 @@ static u64 get_init_console_seq(struct console *newco= n, bool bootcon_registered) return init_seq; } =20 -#define console_first() \ - hlist_entry(console_list.first, struct console, node) - static int unregister_console_locked(struct console *console); =20 /* @@ -4178,31 +4210,7 @@ void register_console(struct console *newcon) goto unlock; } =20 - /* - * See if we want to enable this console driver by default. - * - * Nope when a console is preferred by the command line, device - * tree, or SPCR. - * - * The first real console with tty binding (driver) wins. More - * consoles might get enabled before the right one is found. - * - * Note that a console with tty binding will have CON_CONSDEV - * flag set and will be first in the list. - */ - if (preferred_dev_console < 0) { - if (hlist_empty(&console_list) || !console_first()->device || - console_first()->flags & CON_BOOT) { - try_enable_default_console(newcon); - } - } - - /* See if this console matches one we selected on the command line */ - err =3D try_enable_preferred_console(newcon, true); - - /* If not, try to match against the platform default(s) */ - if (err =3D=3D -ENOENT) - err =3D try_enable_preferred_console(newcon, false); + err =3D try_enable_console(newcon); =20 /* printk() messages are not printed to the Braille console. */ if (err || newcon->flags & CON_BRL) { --=20 2.53.0 From nobody Wed Jun 17 06:03:55 2026 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F7A6188596 for ; Thu, 23 Apr 2026 13:02:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776949323; cv=none; b=oX3rRHuqLiYjqwD5Fk+pcBFhRRatsRMmpxrHfP7wCv3NdkMlMB6y6PUhY1ATYhgTPfq7OZnvFczXTVtGN9ieooYztaFj/8umIsCTgm6WfG35C2hwkYXdg/jxyK3etBN1wFGq4fZt2U2Nhibgw3VUVYKOgJinK7qN5x73sojBuA4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776949323; c=relaxed/simple; bh=HqypRryrIx0l1ROVYu2Nc7w30ewF8sWRBOBcXjHqBC0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=r9SNgggn1v46RbqfzeFAWa6jf8QtY+VdAQ31saRrqVQWEH/bPog0cM0TEvPQdfWa1R+9joAO6ixW1SW1Gxoy51doBns2NEUtWbT+i5zd1DVIxEz0p22rmU8ZTNFp/dSv7ljZrrH6BuoT5hdI//7SDaSgYVo8gaDY7JqlmU65f7k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=Q89LQ+hn; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="Q89LQ+hn" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-48374014a77so86685365e9.3 for ; Thu, 23 Apr 2026 06:02:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1776949320; x=1777554120; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/Ebd2u/ZqiKgN+HwpCewwG6tt0VL6ZGdK3iSPAdPLro=; b=Q89LQ+hnSAd0T9JM+PHvdKoMdZa6FMlUuMe2/faGuGTgMr++MeMIp/QKFFFeDj0xrP MxRtkm/Ig+hYk81py2txnyIaZ/RLxctGT+Bk0kJ6NQnyP9TBEsdBSTe7ADTfpIozh/e0 GJ+rF6SdsvCDhmLNFzhXN4v8lPnixqqYwN33rFtCJavTmBBG4rQxQsK44B1c/QU39ZDu uDTjLigRGazAAbmduyjQMTj2WetKliXW4DiE5n3hLSnZY/WQS1U/x2GvDrsCmn27FeTz GF/LduEJOPFee8Zhjy/mMT1ZbQKKGiWFssEXly9S9aZHpQy391oM9fXUSGRCdvXCMacY J1jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776949320; x=1777554120; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=/Ebd2u/ZqiKgN+HwpCewwG6tt0VL6ZGdK3iSPAdPLro=; b=aAHeN3JNiKAWka3Y0TNIdp3BzjgWtcLLA3jPhp3sx3mhdlVtXguCJ194XWL4wNkH4F BhG4/qZydkXNHGva79Xs09bz6Me9sL92MBaAh9MLLFh0hzdh4Rin9He3aqeZiqSuWxm3 uh2bdDSeM4ydtkp1LXa/XE2nJmCE2Mz89O/whba+1lM1r//hmu5JST63zjT2a5+dWC9j sdNsSTTrPQtmK5+EyA4c7EgIWY6swgWfwwd8ImIKwqk6/It/VT3Jhp0MaLYqUKFabmQf ITyG0s9eemYSbiOBmpjuCoDZ+uGP6BFNA2Fc7xAp6H29jUKJZ0iQnhOT1DJfK3tHvJ0H AsZA== X-Forwarded-Encrypted: i=1; AFNElJ+4l2vaaTXn7crryBPbPFeKq8Io1GWkXD0jeMyBCzVgIbf2g+uEUIrC41IloWa7F8R7O25o5g7oE/JyCXk=@vger.kernel.org X-Gm-Message-State: AOJu0YxhGH5jOnO2A3q1XKYH/SNhjewTYTk5lobEnPFqxPyH+DNj/E/o swNWNCW0ox0MQPX/bCOLn4mOvjo0GxRK2L83onnGIU7g7iIVP0wzSyZVe269hyLA2b0= X-Gm-Gg: AeBDiesIYcDjPh3CRivDehDSgmquEZkrZxZb1h5wiZyIrxubWd+QXEzobLRGu25I1rS QrZSG0MsnmuM+UIshtmIgK89r7GQYZJV8u0MbLktjL74IE3SvwSmFq722HHPAmGP6Ok1D6ijs9p ZJTu6y/fYZuiiodlOeLsDu0m3HewMkeIqOep1BrGM9KAPuqqC1kniQ2fn0BExfd7uJ6FNQWs34G ZAkbmpwJNCAStwrxZ6j8vNDyw0Q9QVvkeshRQPsDlCS2pVWfxveOmyzn4GG1R1S11j53x+3SYgE aYubOtOOIrSuCBb+z8p9s7+LeP305gofS0Y8qpqy+ga8xtRIum+JBFQcndtxoCqjrzyIwrDXL+1 Eqsm8xfeChWG/DIcv2+oc9l8KIqfuGJGeNr6oaYt2lAwotRW94ECXsHc1vE3IbZZg11L84wFCBA mR9Yq+lQlpXM0mnunxzC3JL9KKiYDzEqnjsw2X X-Received: by 2002:a05:600c:a108:b0:488:a82f:bbb4 with SMTP id 5b1f17b1804b1-488fb78a0famr331074955e9.26.1776949320307; Thu, 23 Apr 2026 06:02:00 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a575ad67asm163356365e9.2.2026.04.23.06.01.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2026 06:01:58 -0700 (PDT) From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Steven Rostedt , Marcos Paulo de Souza , Chris Down , linux-kernel@vger.kernel.org, Petr Mladek Subject: [PATCH v2 6/9] printk: Try to register each console as Braille first Date: Thu, 23 Apr 2026 15:00:11 +0200 Message-ID: <20260423130015.85175-7-pmladek@suse.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260423130015.85175-1-pmladek@suse.com> References: <20260423130015.85175-1-pmladek@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Braille consoles are unique: they can only be enabled via the command line and use the preferred console framework for initialization, yet they are never added to the console_list or associated with /dev/console. Because of this, the preferred_console variable remains unset when only a Braille console is requested. Currently, try_enable_preferred_console() must be called even when "preferred_dev_console" variable is not set, just to catch these "hidden" Braille requests. Refactor the logic by adding a parameter to try_enable_preferred_console() to explicitly handle Braille vs. non-Braille cases. It will eventually allow to skip try_enable_preferred_console() when there are no preferred consoles. This improves code robustness by ensuring the console setup is explicit and only performed once. Note that _braille_register_console() is skipped when the given console driver has a match() callback and it succeeded. It means that it took over an early console and can't be used as a Braille console. As a result try_enable_braille_console() might return success even when it did not enabled the console in the Braille mode. It is the reason why register_console() has to explicitly check whether CON_BRL flag was really set and could skip the further steps. The refactoring even fixes two subtle bugs: 1. When only the Braille console is defined on the command line, the original code might attempt to enable the same console twice=E2=80= =94once as a default and once as a Braille console. This results in calling the setup() callback twice and incorrectly setting the CON_CONSDEV flag. 2. When the same console is defined on the command line using devname and then as Braille console, for example: console=3D00:00:0.0,115200 console=3Dbrl,ttyS0,115200 It would have two separate entries in preferred_consoles[] array. The 2nd (Braille) entry would be used when univ8250_console_init() tries to register the generic "ttyS" console driver. Note that the 1st entry still does not have defined the "name" entry at this stage. The 1st non-Braille entry would be used later when serial8250_init() registers all found devices, assigns "tty0" for the given "00:00:0.0" devname and tries to register the same struct console once again. The original code would call newcon->setup() twice in this scenario. It won't add the console into console_list only because the later check in register_console() would detect CON_BRL flag set from the 1st registration and return early. Signed-off-by: Petr Mladek --- kernel/printk/printk.c | 56 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 2543c810efcb..e34955189d16 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -367,6 +367,7 @@ static int console_locked; static struct preferred_console preferred_consoles[MAX_PREFERRED_CONSOLES]; =20 static int preferred_dev_console =3D -1; +static bool want_braille_console; int console_set_on_cmdline; EXPORT_SYMBOL(console_set_on_cmdline); =20 @@ -2644,7 +2645,9 @@ static int update_preferred_console(unsigned int i, =20 braille_update_options(pc, brl_options); =20 - if (!brl_options) + if (brl_options) + want_braille_console =3D true; + else preferred_dev_console =3D i; =20 /* @@ -3975,8 +3978,9 @@ static int console_call_setup(struct console *newcon,= char *options) * Care need to be taken with consoles that are statically * enabled such as netconsole */ -static int try_enable_preferred_console(struct console *newcon, - bool user_specified) +static int __try_enable_preferred_console(struct console *newcon, + bool user_specified, + bool try_only_braille) { struct preferred_console *pc; int i, err; @@ -3987,8 +3991,19 @@ static int try_enable_preferred_console(struct conso= le *newcon, /* Console not yet initialized? */ if (!pc->name[0]) continue; - if (pc->user_specified !=3D user_specified) - continue; + + /* + * @try_only_braille and @user_specifified define which + * preferred console entries are handled in this round. + */ + if (try_only_braille) { + if (!is_braille_console_preferred(pc)) + continue; + } else { + if (pc->user_specified !=3D user_specified) + continue; + } + if (!newcon->match || newcon->match(newcon, pc->name, pc->index, pc->options) !=3D 0) { /* default matching */ @@ -4001,7 +4016,7 @@ static int try_enable_preferred_console(struct consol= e *newcon, if (newcon->index < 0) newcon->index =3D pc->index; =20 - if (is_braille_console_preferred(pc)) + if (try_only_braille) return _braille_register_console(newcon, pc); =20 err =3D console_call_setup(newcon, pc->options); @@ -4025,6 +4040,17 @@ static int try_enable_preferred_console(struct conso= le *newcon, return -ENOENT; } =20 +static int try_enable_preferred_console(struct console *newcon, + bool user_specified) +{ + return __try_enable_preferred_console(newcon, user_specified, false); +} + +static int try_enable_braille_console(struct console *newcon) +{ + return __try_enable_preferred_console(newcon, true, true); +} + /* Try to enable the console unconditionally */ static void try_enable_default_console(struct console *newcon) { @@ -4047,6 +4073,24 @@ static int try_enable_console(struct console *newcon) { int err; =20 + /* + * First, try to enable the console driver as a Braille console. + * It would have metadata in the preferred_consoles[] array. + * But it won't be counted as @preferred_console because + * it does not get printk() messages and is not associated + * with /dev/console. + * + * Note that it might succeed also when the driver has a match() + * callback and it took over a boot console. In this case, + * the driver will continue working as a classic non-Braille + * console. + */ + if (want_braille_console) { + err =3D try_enable_braille_console(newcon); + if (err !=3D -ENOENT) + return err; + } + /* * See if we want to enable this console driver by default. * --=20 2.53.0 From nobody Wed Jun 17 06:03:55 2026 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE4D33A4F30 for ; Thu, 23 Apr 2026 13:02:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776949335; cv=none; b=rNL72g4N3cZahgfOiq1Ee2tIh6oF8Njgb9mbFxQRU1xnWpQCvqGrdM1FxjtQ8h0TOARTmxYSyIJb9NjAyFCMtUWTYWK4XuYJBpEqQuBsPLrhUH8BWTib/KwOdTGlAOMttyP5Ijl/iRaph0HWwOcD9QlUSnUgVzJLRErPCmSDZU4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776949335; c=relaxed/simple; bh=4JAIKsk9xGP9KZ9G9E+SjuE6qjenkCq14DqXaDRnaWs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sMQaRzo3VqDKQSQA7COLgI9svx04SsHf0NqTJ8nXeXnWwT9nokb+XcSTHyz8T4GJXnUVLlDyMaCygPczAKRflva1aKQrJGp2Adjn9Y9oy4Xi/I9j79qy/ZuAqPGR3MJtS9Krldoz7gw2q3UCD/kjdvqqghkuY8spfhrgp9xw9/U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=LTixN5No; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="LTixN5No" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-4891c0620bcso39797105e9.1 for ; Thu, 23 Apr 2026 06:02:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1776949332; x=1777554132; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=f3BDMJ2WjTPc/08h07dFD1R9fzTpSvsDNWyfoYmhEYk=; b=LTixN5NodzvMwdAa9GIHLO7O6i/XVIw9Sjqkw7BuHxOZW7jORjF0hXiqcfAgCHHmk6 tKhIJCaODKZ8/TkS5Gr145T6EDd8qidwIJkoozt8uQ+8VF1H1g765wwAu3exp4rOEhEa hGVA4ce60MEbTCAXnHmQW1rxwaln+GMvVR9fRKrP3Etl4458BZclvgWzdF2kA5inu9gK +GLcwLyEkYOxemfqKpScTEMcJkgIx6Q93S4MbpvbizIULF8eL9i3kBFmVXbGOnb/BUJt g5eRCH7LySyAfIXErmyjrCpq3mk24GyGNmL1FV6e85BfKq6pltXDWeuUUZMKxzrKjdDY IdyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776949332; x=1777554132; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=f3BDMJ2WjTPc/08h07dFD1R9fzTpSvsDNWyfoYmhEYk=; b=N2vBc8/EBcp7WVl1chOlXSx8gZz5qcDeH5BLJnrDDaycYaL6cGmnCUygQl//ArLzWH cmjr7AfHmQo9MYi2Oz+wVEawepz2h36sW20z5Jz11lPqYsuHkEq+ScfbTK2Vq+GWZK+V S8EkPMMynuvqAjJmf73qZjNf5V/k4ukmv2Dht9QXSvdQ2fQ1GrDwbKUGEhMcaaUYMqv7 A7vQdLxw++Cnw6FVePQUQBTbfd3w/fckyq671C9MvZVPwokkiJD9fF6mpfZfZ9x2L6AD qsItLRmPc/QuULRvcOV6eG2yIqPkPdtot5bWtJURn5aBT+LyNUADpjEpLWpPlqVzPXyL xbog== X-Forwarded-Encrypted: i=1; AFNElJ+tE4V1Cri+NlB4OLQhGXvsDHb5OhBwIcWJ0VD61SvadYfQAMusOB6L8ws3HRMBNI+STKYIQujsCMNj6qY=@vger.kernel.org X-Gm-Message-State: AOJu0Yxpur1Jl3Vs9oatyv1oFYnCww7pNYHM7ojvAweSv05P6k+uNhZI kM12qcLwiB664P+FTy7FuKtYd8prIzu90ULLcFXP5a3ESEi/spGgsSReuP99vQTQE2c= X-Gm-Gg: AeBDiesghA4xuPWIUuGTWByXzQutTwKytNPWVltEs7GeCpW8TwRQVXbipX5hNKwRtuV dQ+pzhmtTyN0txmUcMusjYkfFzwRLm8cpVLO55myggS+YKbmDrnUvmohLxzw/9k6hDOAj9UdS0c Gvr+8EF6VVw20VQGsLUO5sugWIJxzdVg4W22naiWHQiyq1ty58gTtPb2rP/Hu4QUFDCV3Mk4gi/ dC8CFkhnDwLAfCq3+6IjW3+E2qpVnoDa7CuCvRmP7mrbTRIQKGlHIf4+bYe7UE1vqulZQgvqgnV YRTcJv/7F7b9iXYp8UfPZeDrE220Wxw3LkqOc/JAyb0yadLEZkWvX543azsRXZa3ZcVkySHP62t 21Do/lKLjkG3/3r1tYhxptWWvkh+QArJyom+owKnLKCfXi3re8qlmHLVx7XCzHWdIIcL91hecnm tNxqgmlub1ipnqmbg9R1m6rpoVRHfbjI0SPRdd X-Received: by 2002:a05:600c:468f:b0:489:1cd2:610a with SMTP id 5b1f17b1804b1-4891cd2624fmr224994035e9.9.1776949331958; Thu, 23 Apr 2026 06:02:11 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4891cc7b2efsm177988095e9.0.2026.04.23.06.02.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2026 06:02:11 -0700 (PDT) From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Steven Rostedt , Marcos Paulo de Souza , Chris Down , linux-kernel@vger.kernel.org, Petr Mladek Subject: [PATCH v2 7/9] printk: Do not set Braille console as preferred_console Date: Thu, 23 Apr 2026 15:00:12 +0200 Message-ID: <20260423130015.85175-8-pmladek@suse.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260423130015.85175-1-pmladek@suse.com> References: <20260423130015.85175-1-pmladek@suse.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" The Braille console reuses the framework for handling consoles preferred via the command line. However, it is a special-purpose interface that neither receives standard printk messages nor associates with /dev/console. Currently, the "preferred_dev_console" variable can point to a Braille console entry in the "preferred_consoles[]" array. This occurs if an entry was first created for a non-Braille console, but a later 'console=3D' parameter redefined it as a Braille console. Since a Braille console will only ever be enabled as such, it should not be tracked as the primary system console. Adjust the logic to ensure "preferred_dev_console" continues to point to the previously designated normal console instead. Signed-off-by: Petr Mladek --- kernel/printk/printk.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index e34955189d16..9143a050c289 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -367,6 +367,7 @@ static int console_locked; static struct preferred_console preferred_consoles[MAX_PREFERRED_CONSOLES]; =20 static int preferred_dev_console =3D -1; +static int preferred_dev_console_prev =3D -1; static bool want_braille_console; int console_set_on_cmdline; EXPORT_SYMBOL(console_set_on_cmdline); @@ -2566,10 +2567,11 @@ asmlinkage __visible void early_printk(const char *= fmt, ...) * Note that a valid @name and @idx will get assigned later when * @devname matches during the device initialization. * 2. Specify @brl_options if the console should be enabled as - * a Braille console [*] + * a Braille console. * 3. Only matching entries can be updated. * 4. @options passed via the command line are used when the same * console is preferred also by some platform-specific code. + * 5. Braille console is never associated with /dev/console.[*] * * [*] Braille console is using the mechanism for registering consoles * but it is very special. It is primarily used for user interaction @@ -2645,10 +2647,22 @@ static int update_preferred_console(unsigned int i, =20 braille_update_options(pc, brl_options); =20 - if (brl_options) + /* + * The last preferred console should get associated with /dev/console. + * Except for the Braille console which can't get associated with + * /dev/console. One level history should be enough because only one, + * the VisioBraille device, is supported at the moment. + */ + if (brl_options) { want_braille_console =3D true; - else + if (preferred_dev_console =3D=3D i) { + preferred_dev_console =3D preferred_dev_console_prev; + preferred_dev_console_prev =3D -1; + } + } else if (!is_braille_console_preferred(pc)) { + preferred_dev_console_prev =3D preferred_dev_console; preferred_dev_console =3D i; + } =20 /* * @pc console was defined by the user on the command line. --=20 2.53.0 From nobody Wed Jun 17 06:03:55 2026 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B862231D371 for ; Thu, 23 Apr 2026 13:02:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776949351; cv=none; b=U4EjAOgEWib9wG7TMnyKMndALnwV579P/Sdn/L76hF/HdMZB0vgnfu4q4lwtTxPWOgII9jj8gSUSgPQLBe5QjQkwSEIv+rOGiadmSN+PuKRmpxhPqPOZriBn3K4DlSRZOuNy0+Hd9CpYV93EAvodzWaLSyRjn8dZl+loTKqY2hM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776949351; c=relaxed/simple; bh=Z1emXjID8GZwhNL1lS/g+f7c8Z3yF1l3LJ/LE/EP2qY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XeLtPl7TQA8JzcgSIo4hEWDbyr0Nta59snj/VV3mzbrttCpivYpWN8QM1y31ysimQHOmThUhI9P5WhLMGPRa5TJitJaprWWOaUgZK8wWo2pRxeqRElKc5qHMBRmdqeWKNW9m76XJUyuDf0puKtqtDe/GDwq9wj1jXTJDvd+qzuw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=e6eL27yM; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="e6eL27yM" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4891c00e7aeso42610795e9.2 for ; Thu, 23 Apr 2026 06:02:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1776949348; x=1777554148; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=l87ZLddebUWdjXvuZeXUUisBg2RinkONT9hW90ee0fM=; b=e6eL27yMaBvl4eBEcGkHcHr/eGdC17ubmzGPn8LlHTzJyeAcf5gq7eTF5sM8mxAgqI gTmuZXiFpI9pWysARvfqrj91gbMKl3wMTP2VjtUotKVXaP4ca/VTKgB6jLoSBrhXZna5 zD31UvaUqI1TNIekpqCeV3sQS4bgFzHE9Lu8LEQdrgOUQ8IoBBwsGJ4LxvhQpv2YmzJX 5wqhQfDE2clgSg+Gk9gydmmANkeS4+MQfv38eoRnM/Qwz1oAQwlDQfMaeYA1VsFeM6GF ydnGobWIdMRNC02UmPcO/dMf6o1DU0w63PrrP0f/V30LQfB63jjp42CUpWopX5pktDG6 JNFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776949348; x=1777554148; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=l87ZLddebUWdjXvuZeXUUisBg2RinkONT9hW90ee0fM=; b=Kwz5iG5PVTm4l9yydIwL9QvA2VVbuPiPTwDWIZHuG16Q6EXAIM/QQKgtPkt0/ONrrs GBmj6W0yFJjjuN23SkIFfQULOYoEsridCSviruUaOoQUJnJgw4Nsz/sW9VGixjXcfokF MqDlNnAgLzrw9lowGNFkYJU5mSpad4K+r7kYCAPR9DhOKfV7WsvNmxp2paZFegfTZzjp 65sELKw7EipTjL6qmNvWZ+Zm4/O/MXNqG0PWsBKhgGN5dJ/Qtt03A1PlAK+YOvVUUjpS m0CcYjblLqLULk7OMoAvc0C6IAO3AEqI/YRB40VBM+ksUNZo9w40MCxaaPliOh+yOLq6 sqYQ== X-Forwarded-Encrypted: i=1; AFNElJ9n5fpbrf8WsoMGWZwbtNICgQaTYljqtdYcdgn9wiaynawjMGkS2nC0+0n8vIRn2UPL6Z0pX+Et0T1EAoI=@vger.kernel.org X-Gm-Message-State: AOJu0Yzs6RypFREzffPm2nanBK+MGI7v2jPxIRXUC4SJ/mk3wGZeQzHP 8ndnVxE5EG4EdiLm+ZAFUMQtt8PtGELkbIcK1HqkMNv2zGAYQ6v7WJhRQ00WNVFpvJs= X-Gm-Gg: AeBDieuT7W78LVAb9GihDbT8Rv5cBwqsl7/2D+gtxrzicfoHMpDobPTfz4QnHferZvG ZcDH9trAfkciEEgsuzz1gD9iw3uFTKgwmlESdXwF2Lc3ftrO26N2EayhpNMwYmNdXWZsARBdiY2 24BiTwCGVzok3HI4XzWxPgjbsxwMwo8BkUGmYnH3TgXXbZT0k/Co9FKs5OoFfYQ0mLkzrDKw6v6 s67VWTLF6bH4gNL70jstz0Mi3JhvU/6+Oz7SsumoUHoJSy56jf4ELoX1vvi/VhzeEt0yha/GRqE 6CeukqjQWN/174kJit5l1YHJK5xcPAzHzBD6H7VqTLi+9Msvk2SZunGjzRJwFIBVYFRzBfpKXVc xNYt8nDCVJXb4QlppmHJ7vf3natxEeTFbfmiJElv36UFXM+NlbhSXtUiINJ9RNgYpZZOni9C+27 GuGn9TMF4Ht6vwNYiikFuGU/YpkMLxn6b9jHBR X-Received: by 2002:a05:600c:5285:b0:48a:5333:811e with SMTP id 5b1f17b1804b1-48a53338269mr225529235e9.15.1776949343463; Thu, 23 Apr 2026 06:02:23 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4412150a071sm18249756f8f.21.2026.04.23.06.02.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2026 06:02:23 -0700 (PDT) From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Steven Rostedt , Marcos Paulo de Souza , Chris Down , linux-kernel@vger.kernel.org, Petr Mladek Subject: [PATCH v2 8/9] printk: Handle pre-enabled consoles in the top-level try_enable_console() Date: Thu, 23 Apr 2026 15:00:13 +0200 Message-ID: <20260423130015.85175-9-pmladek@suse.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260423130015.85175-1-pmladek@suse.com> References: <20260423130015.85175-1-pmladek@suse.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" The function try_enable_preferred_console() currently has the non-obvious side effect of returning success for consoles that are already pre-enabled. This obscures the logic flow during console registration. Move the check for pre-enabled consoles directly into the top-level try_enable_console(). This change makes the handling of pre-enabled consoles explicit and easier to follow. Furthermore, this separation lays the groundwork for future cleanups where try_enable_preferred_console() can be restricted to cases where an entry actually exists in the preferred_consoles[] array. Possible behavior change: try_enable_preferred_console() will newly be called also with @user_specified parameter set to "false" when it failed with the "true" variant. But it looks like the right way to do. It will allow to call newcon->setup() when the console was preferred by some platform specific code. Signed-off-by: Petr Mladek --- kernel/printk/printk.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 9143a050c289..91c3be6843bc 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3988,9 +3988,6 @@ static int console_call_setup(struct console *newcon,= char *options) * the newly registered console with any of the ones selected * by either the command line or add_preferred_console() and * setup/enable it. - * - * Care need to be taken with consoles that are statically - * enabled such as netconsole */ static int __try_enable_preferred_console(struct console *newcon, bool user_specified, @@ -4043,14 +4040,6 @@ static int __try_enable_preferred_console(struct con= sole *newcon, return 0; } =20 - /* - * Some consoles, such as pstore and netconsole, can be enabled even - * without matching. Accept the pre-enabled consoles only when match() - * and setup() had a chance to be called. - */ - if (newcon->flags & CON_ENABLED && pc->user_specified =3D=3D user_specifi= ed) - return 0; - return -ENOENT; } =20 @@ -4130,7 +4119,19 @@ static int try_enable_console(struct console *newcon) return err; =20 /* If not, try to match against the platform default(s) */ - return try_enable_preferred_console(newcon, false); + err =3D try_enable_preferred_console(newcon, false); + if (err !=3D -ENOENT) + return err; + + /* + * Some consoles, such as pstore and netconsole, can be enabled even + * without matching. Accept them at this stage when they had a chance + * to match() and call setup(). + */ + if (newcon->flags & CON_ENABLED) + err =3D 0; + + return err; } =20 /* Return the starting sequence number for a newly registered console. */ --=20 2.53.0 From nobody Wed Jun 17 06:03:55 2026 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2959C31D371 for ; Thu, 23 Apr 2026 13:02:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776949358; cv=none; b=UN6jfJHCMwOULXVkxLcQPKcv0apXDceDJCHcLFYg5BgVwSaOhb2lyrvw23fm5H89bL46QZVqSvUPR2yezE4OiEn1T+WgeT93CIbtMzVwNz6EXaXaK56WIjw+kciXh8Q+2yb3K6fkivj7xqHpVXCvG8zFKk/yMiLdLi4tfBo8sb8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776949358; c=relaxed/simple; bh=/drvUAizRl/Dl9+3bX9DGCBpeNYp5eNhrImtniHgd1s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=m4thOgu/p2ERnycqVarZYInHX9wzBLsixaD9QTlAbpTEDX8A5cguWMTMptxCgJ2V8VHi0cP4w7RVcrVKKCCGccamMEQ4eGS+ProETtseRy94njWunVKIFwkAL1yP7C4M2QmMYedpZlrl6PCZfAsDlD6NX1XV8P4SXcjEXC9HZpE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=DLcEUNbx; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="DLcEUNbx" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-488b3f8fa2bso67476925e9.1 for ; Thu, 23 Apr 2026 06:02:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1776949355; x=1777554155; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0sEt6Z5ht7ZI5bmj5Y6lMPZxl22n/lWDugMJLpnDkd8=; b=DLcEUNbxONADEdAt81zFMQpiaqKCD5cPVAiEJOmymhcefcGj0y9q5tKKzdpHfQR/H1 l8K0knQ++2FlC2d3TqhXeTrnuu34cPVs76c0c8kTKOkmRmOpGsyTi9DRRQOOnx6/cAk+ Q/4zf8qSaYL466FjRKMkh4mNca2RnjgL7Q1am0VZP2XX5He6khgfoX86VFwo+2j+H59l ryxtc+HmPKiYeoP9BN90sGhTaTUDubEaamqZOLe3uFLIPD3LO56cAkNc93AdkN0zzwD+ BXDCXqPNRUh8GpWRpIUqev0GCJKwIA1T4ES+eVn+dSaEzql3c5/nH+sZRmy7pkOvwE10 Od4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776949355; x=1777554155; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=0sEt6Z5ht7ZI5bmj5Y6lMPZxl22n/lWDugMJLpnDkd8=; b=OLrljR3VyXKa5MLhrKXNlLBW4vkTTq5yVKp8zYB9+Wy+8VkUMC9vUBE66aGG4BOAro OcYo8a/GpCN/OjMFzk05+Lsr5qM+l8SNsDXGmD5m5fzZ5g/EI/fponMBe4+mtgNlG648 XLG+cYKjwxJUz/8iUde2WCDDcC3TKUMBuf+CF+Xe34RQC4A3pngyssJHdP+g5BpWxxaq /CmwJZnLv0DQrD6kSY0J3P4g+j0JLEuSZzLF8kR48kjqtY20oG3HxrT7gYmoHA/zHyAL ymIJMZBwXU6qWifw4yK1xpmZUQud/VTNHUvB2uys4u7T1d7N5O6Ko9IgeySBfD5qf6pK IwxQ== X-Forwarded-Encrypted: i=1; AFNElJ9flKHt6Ban7yaSHAVYrHgHtEVXMEtiAKT2qhh82P23sf2nuA7mOUMEG0kfcPx387PXG/O9MZosEqC2eKk=@vger.kernel.org X-Gm-Message-State: AOJu0Yy5UmYASWfFCaLe3d5ZI9TfwA8myWLpDNU5PVewSR08ReVNEpEW kfrSgcZegKCEGzaXLoE1eeDlI09CjrAuB6LdjmXjEPZnZkha3pvFypjPqE5NXetY/FE= X-Gm-Gg: AeBDieuL2yVLmsLrzVlk8qVIMHKFHTkxtB09fbvEaxzVnuYisy8nZpiiJ0pKBQGAqcs lUQBy/v3KfFvFvhXadu4S0LUd6dJc0EaUYGTwjH4l95Xoo2CHJWYSUar1nczSMsrm8TCzHbxLWe cweXYfN6lJX9dYANJ3AvHecnqahA3ZTi4nL/WyetluzEJE+Kd1hohq1VsSSXlM3oL8IgwrjxdC6 8HreqU6WClIz+OibrguDmvf0XuuBUcpM2zrnhkG1jOoHu7g+7EW6FUffjlE5f/vUoR6wi6SsSD2 hCqeuGGdBi8eqX9JeFOZ6AytqF1wbl9SKSkQp1inxQRBO+HMH4m3v7SSQBjMS8sYXJ2exwvm6Uv cDWa6uPoeR8FP4BsLK75mk3PKfENTv6Lyn7dsuzzX/QwZSJA6QsE/A3KYZ1tPk+VsBqolM+I7EJ QcA/7T4KVfF4s8pwLk/7A5kOVE1DTeEIJmY6Z7qwDZt4lnrCo= X-Received: by 2002:a05:600c:b96:b0:48a:5339:a46 with SMTP id 5b1f17b1804b1-48a53390f6cmr184055395e9.9.1776949355253; Thu, 23 Apr 2026 06:02:35 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-488fb75ab25sm161120155e9.11.2026.04.23.06.02.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2026 06:02:34 -0700 (PDT) From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Steven Rostedt , Marcos Paulo de Souza , Chris Down , linux-kernel@vger.kernel.org, Petr Mladek Subject: [PATCH v2 9/9] printk: Try enable preferred consoles only when there are any Date: Thu, 23 Apr 2026 15:00:14 +0200 Message-ID: <20260423130015.85175-10-pmladek@suse.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260423130015.85175-1-pmladek@suse.com> References: <20260423130015.85175-1-pmladek@suse.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" try_enable_preferred_console() used to be always called because it had several hidden effects, namely: - enabled Braille consoles which were ignored by "preferred_dev_console" because they were not associated with /dev/console. - returned success when a console was pre-enabled using CON_ENABLED flag. - returned success when a console was enabled by default because try_enable_default_console() did not return success. The first two hidden effects were removed in previous patches. Remove the last one so that try_enable_preferred_console() can be called only when any non-Braille console is preferred. Signed-off-by: Petr Mladek --- kernel/printk/printk.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 91c3be6843bc..4098ed3b735f 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -4055,18 +4055,23 @@ static int try_enable_braille_console(struct consol= e *newcon) } =20 /* Try to enable the console unconditionally */ -static void try_enable_default_console(struct console *newcon) +static int try_enable_default_console(struct console *newcon) { + int err; + if (newcon->index < 0) newcon->index =3D 0; =20 - if (console_call_setup(newcon, NULL) !=3D 0) - return; + err =3D console_call_setup(newcon, NULL); + if (err) + return err; =20 newcon->flags |=3D CON_ENABLED; =20 if (newcon->device) newcon->flags |=3D CON_CONSDEV; + + return 0; } =20 #define console_first() \ @@ -4109,7 +4114,9 @@ static int try_enable_console(struct console *newcon) if (preferred_dev_console < 0) { if (hlist_empty(&console_list) || !console_first()->device || console_first()->flags & CON_BOOT) { - try_enable_default_console(newcon); + err =3D try_enable_default_console(newcon); + if (err !=3D -ENOENT) + return err; } } =20 --=20 2.53.0