From nobody Mon Jun 8 04:24:55 2026 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (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 ECCB73C7DF0 for ; Tue, 2 Jun 2026 08:53:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780390426; cv=none; b=geOY0Pnt0EMdJZjVc4Uys43IermIzDfhPx9CZI/UPfMxlFDBrNg4bjb6iamuyEey9nbL5I9xDv0x/jVicIsPF9XWmjWHwUFfcYjMIipenvrsAZPChsiRqVGqZWj0StdqVWKCvGmUNCN0czSd8069RqAA9TCod3mnJfSa1/Nug4o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780390426; c=relaxed/simple; bh=AXMHC8b6ZCYIDvbfYhK1DJjBmiAMD4EN27vrE2xW7oU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d9Pzh3uulmRPpGJLbRB8K6faIYb9FFa3r71bAqOeeBhDTSltv2qFyPMLsu1xXFUPn3DfJ3MxYstiDfX5Nowx1mgBSPxFtb2pFzF/LNpUWBgtiWnuA/iP3oCRmlmWTY6BJTWNTNUZ8I2ZwS8vBvnNEYGMZVdMJLQ4JVZz+3rEGuU= 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=aaiagkFI; arc=none smtp.client-ip=209.85.221.42 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="aaiagkFI" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-45ef29c5561so2128230f8f.0 for ; Tue, 02 Jun 2026 01:53:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1780390422; x=1780995222; 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=LfmdLaYSxx3QxxirsGWUqs7dR7teltuU/UMlm9lq9mM=; b=aaiagkFIBjZfUrsCqFSjY76qeS9wlGlD9hbOX+Lm4HsxBUIxGmbiTFONq0mI/LXYC9 KDLfuFjH4hz+F5AjDHkzXS1xNk5rs2X486y9wHPLDbCRGjinBmLkzCA+4Lu3CD0CbHkS AWZJslZ4QmsZj913Xs0HL7FwJD4LGVBYipcMztK85q2c51UOd/8HC43DJSuQTBMtO8kb 4zzGIQLR33Cc7O6WGT+fpl4xTSCM2TyOVGdt9JXDrj7B4+vh5BZbMtOF9wAAYmIULFFQ aFXKZvXdQV/36XbbY/hvkmjwKXM7slZ9zMNnbHHxMnS7hACKnEUsSoObimm3CoSl1fTh eLiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780390422; x=1780995222; 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=LfmdLaYSxx3QxxirsGWUqs7dR7teltuU/UMlm9lq9mM=; b=abDMzVTTCYLJZ2q/Y7/Cxjsbgeyvrimmz96Z2601hp1yNbbgbt+c0ydaQGLEh0Lc/v RwUYgJfwy2SFnA+Tc6a2E2LrMW5HkesksEHxmMinlJKK2O1/kaFdqAQ9Q6LeNliAUlNM 6w9g167cWsLJ3L/qnC5QijL2MrEjOlzQs2pfKBEHMRVuyyGFKPKbgdqakdp79ZigQ48T S34WZ4Ll1E4E0WAEVuCnFPCJID7VXRQX4md7VyVIts5YyiCJov+6y1nrs50FVgoklrB6 LDxPM3Yze6cjErsm3GDEvzXgDAkXETTzV1DU7Ps33oCTViiGngsgjOKXHoc+KUKRfzu6 PNtA== X-Forwarded-Encrypted: i=1; AFNElJ//eXrqUDJR+fRsgzb5dF66/JyZAjaIzCY+f+YtLmf1HGv3NX7CKH8lQtOOKuCyHvMvR870oCiX7B7kA6M=@vger.kernel.org X-Gm-Message-State: AOJu0Yyt0tjiK6tAU65PDyxoC9KKufSAvemoybYotxJ/0cQ43/Si6GNr 6ktP5iw+4XZudt4dYZbTV4G1rnIf0DZDhBc35/5fS+R2DZ7tfExw42BGdC1ktLKzJwk= X-Gm-Gg: Acq92OHp1VzHrikGHbAhjJixw9Ss6WFGlhTpdcIWfxr7T3nI0LTYPm03Xw9+wsu6+DM 7HDnnkb8QJ9TL4qrv5L2YhQZorgBSHbg1WOQKs8voa5cknAMF7dYOdHNOl8a3Ldvr7PZsLLuzaS q1Iaat4AzcilIyqjgrKQUdGbbw0Mzn0yf2JZ5QvdH5s1/b9FIAxlD5fGPrsJPgrdXszpIRVvIjV AdAH4IL/KQx75GagBFtM4iokjw4o7sVKL0aV5kErkS6RLvsbsPnvjDUyqiwbQ/wrnltTLIxwXiw 09+D77Aqd+GuSn8w3XdT5nyFXCl4xh7nm9nplUjN/DkepljgbjhnOOFexGtwqzXkPv2fxXr6gNp /i5rk7pLDQCHX7pWFyccBW2TgWqR7hpoE6nRB4IO7rBrWb/OLfR/lr65s/yWi1PXwtQY6W34KKS qERz0UzIXDLSeZFdvUztdvgMR4bek2YaOQ1X7y X-Received: by 2002:a05:600c:828c:b0:490:ade0:6129 with SMTP id 5b1f17b1804b1-490ade061c8mr102198385e9.33.1780390422257; Tue, 02 Jun 2026 01:53:42 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490b0e3431bsm49258355e9.12.2026.06.02.01.53.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2026 01:53:41 -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 v3 01/11] printk: Rename struct console_cmdline to preferred_console Date: Tue, 2 Jun 2026 10:53:02 +0200 Message-ID: <20260602085312.228251-2-pmladek@suse.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260602085312.228251-1-pmladek@suse.com> References: <20260602085312.228251-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. No functional changes. 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 | 87 ++++++++++--------- 4 files changed, 58 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..f1e2bc74f1c0 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,7 @@ __setup("console_msg_format=3D", console_msg_format_s= etup); */ 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)]; + char buf[sizeof(preferred_consoles[0].devname)]; char *brl_options =3D NULL; char *ttyname =3D NULL; char *devname =3D NULL; @@ -2633,6 +2632,10 @@ static int __init console_setup(char *str) char *s; int idx; =20 + static_assert(sizeof(preferred_consoles[0].devname) >=3D + sizeof(preferred_consoles[0].name) + 4); + + /* * console=3D"" or console=3Dnull have been suggested as a way to * disable console output. Use ttynull that has been created @@ -2730,19 +2733,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 +3900,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 +3941,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.54.0 From nobody Mon Jun 8 04:24:55 2026 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (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 07DDE37474E for ; Tue, 2 Jun 2026 08:53:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780390437; cv=none; b=bLyEyPl+rWXV1Svdez/RlUp4P3Y/cHKXlHBksOURHq0p7kSJGl+KCpcoVVJZQGB7fogB6RGfGu4NUuUAzVUJHX/i5M7+uDe/Si4nuRdjqhXZn5JRhX2taEWyfh5CaYshSzrbsgKGfvxuIlyRyjHlEQs+spytvqvLkmpO1qJE/rQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780390437; c=relaxed/simple; bh=ZlEGZtuIzhaUow43aIg5o8T4ZkO0L2LLu1EVJ6Ijomg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uXvQEtS9BJo4kXVwIv7CyOi3XedEXnja2Wv4R9I5mM/XLXufqP75hY/X8aXc/Xo2zHuorcTI4DJ3Q62K1cedv5HEdbeo3bYIPVrBOFkWtRy2TD1Ub9droTfv+Ot505kFhNyq9Gm8OmNWNTtGIdwPKbKuk7uCeWxSEaKGaDeUmTY= 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=aU8udB0Z; arc=none smtp.client-ip=209.85.221.46 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="aU8udB0Z" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-46013161068so894304f8f.2 for ; Tue, 02 Jun 2026 01:53:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1780390434; x=1780995234; 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=jIIoyPD3WCWKj/iuMX1hEITbdkrDqtAEyKoDLeoz0l0=; b=aU8udB0ZnAg+YTPX0yD37w6eD95WItuVPi76Yx2Unul/jAMQOUgV5w2LAzMh/4zq2o 8hyDsSos6MkGZ9TKMn/Y+aTbZwU+OD03JxLV7j0PLw65w894wFjPevF8SIAbsCm7sLQo qytVjaPZBteUu0XCvy26FDVXIzh4wa3ItKvRhT2IivOrOCV2LyPHWV1BcbTv3ZL7K2as W0etgqHbey6QxlWQrIS3zfZaf1BmsRXRwHjiHy/PfGNz/FZzK5KyM/HJsDEoD35RFWTw jpZnoz5SRqRQRh47u0h2/AVBXFn8HDe0Q5WWl25sL6YPahqPruw7rhXSRIJMZl1Jqa++ md3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780390434; x=1780995234; 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=jIIoyPD3WCWKj/iuMX1hEITbdkrDqtAEyKoDLeoz0l0=; b=sifvVHSo5dM39PLTy2Yn+yVuImwzsyCRZxBYtCtUYsnT7BON2TknSW56ePk238J4NL KEL3YO35WLHbF0qFZZJvaAYyjg4TWKmiCLGXhpeaPVOVTJkOPsIRBn3hnnjuxClNc+h5 clhPq7eyTBE54shTfMkw8rX6ZAdoxeLUzCs6kM9zXP5xBjQ+OAzms/e423TDfSnI4dtV 10sEE7gxD3Cln95Wz+LcaoDN9fe5whlZu9BojUNWWe0J2nrnMmprQ1nRbLbpf6ew4M+6 v0lFTO2lALwN4GHAvrCUxuNOGMo78s1utqlPEMPjJhPAAnka+I2+YhIvjih1/YR6YDiD gAyQ== X-Forwarded-Encrypted: i=1; AFNElJ/FPjkbxe84cT0P3i1Tvrbsfwblv03AiaG7FThftmJe4R3Zu3RJ8JuF+wG0y50xbhaQ08LyYQMqBgwCk+c=@vger.kernel.org X-Gm-Message-State: AOJu0YzYxP5LbU5/5M+13177vfoPEvShk91CajlUXjnimlNA3XT3mz3K DFVTeIyO1dKhhBy/0QQaJ+AAIHK8xkvZFc/iCrUBXBpCfoFEKTUCUahs9pGNYKbctbd+U9KrpmK UpiGR X-Gm-Gg: Acq92OEE8Sz2UV0rsYe+z2K5MyhjiC2fwK3jzrwFt3VEbN0y3t0p3wJAKfjVTkY3ntO Uf+Vj0sSPp89nkDlvlQD90wNIql6qVPY0EaKEcQjUYeWnTjLyolP1nfnaB+6vetfJPgS14KCEbT LP6NPKSKm0x0yy5Z5vUWX4AagE9RsLMc/0xt/qAykWM1n+or1Gla0vsS20i0sWA2i1vEO9AoObc 89B5GhkOyA1gj5lYnVKdbB19TuVUMl2DMqf1G4uw0Jeo5aUmdbAZSA7W00R8kjCAXAj23APrIxf sSYRocNMMMQyVHUTvNxMgrGMAgqE9ijPGCJ0tYe1cOUzX33VzG154E9crWGKH3kK4FzV20IboiP eDEnbgPUXEkDREs75uymWjdKYAPGkeONB7pJBIK8ofNhvB1l9C4Q2zEJSgrsUMiUVAaAOwqYqNp EI9dW1+gKlEF9JGFlkp0mSwBNjkP9Hlvd5L7Do X-Received: by 2002:a5d:5d12:0:b0:460:194d:8df2 with SMTP id ffacd0b85a97d-460194d9727mr4624778f8f.3.1780390434371; Tue, 02 Jun 2026 01:53:54 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45ef354bb62sm30235496f8f.19.2026.06.02.01.53.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2026 01:53:54 -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 v3 02/11] printk: Rename preferred_console to preferred_dev_console Date: Tue, 2 Jun 2026 10:53:03 +0200 Message-ID: <20260602085312.228251-3-pmladek@suse.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260602085312.228251-1-pmladek@suse.com> References: <20260602085312.228251-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. No behavior change. 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 f1e2bc74f1c0..5938e9df7345 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) @@ -3931,7 +3931,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; } @@ -4112,7 +4112,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.54.0 From nobody Mon Jun 8 04:24:55 2026 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (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 241A536EA8E for ; Tue, 2 Jun 2026 08:54:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780390449; cv=none; b=dpekEkOOto6u4P1i0SAOr4s/VwP8e6AGtDBbmT9IuKFKeB7FF1eBzm1vRnZkfN3dsvdgJ+3VUFXuyeA9Q+HX60xJjl3aU3pPh1LZ5EBFQKAOYMan7X1dOVP42VghSF3kbHIWV5L4m7PZCHLnf3MxutgRiiRzvcFCaZkr4dc6mdY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780390449; c=relaxed/simple; bh=tjBPP6vwYVT9PN7pxaSqYfQdRMoDmbHXU+zTX5/4YbI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pq0c3SfnhICUashjZ99kv5QipgfFmFzNeClZTwplIUcxgeo9uGQbrATDPZdfAvFdls699SNsoB8lFBDJEPkscGVZMQRDiWcgEjudrQ7q4thFtBKuhHpNsdmYXEyhWqqLTenvDJ9XMC7EmLyOS+nVIsfkm42hOMMlvjI3k40wOSw= 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=fRVMGyhW; arc=none smtp.client-ip=209.85.128.51 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="fRVMGyhW" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-490388fd0dbso111618975e9.0 for ; Tue, 02 Jun 2026 01:54:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1780390446; x=1780995246; 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=v1suNiINZUqCrLI/VwQHHQcRyvtfBY7Ngnxz2o1UORo=; b=fRVMGyhWvNZ0rLzTYSejtnf9fFpdLDUpD6/mNS0ZE+vHOrd430RT6qmkyX4SlzUGpY pK5C3myEo8idDdgzHjGrpTaW8T1RkvpbE/SuPOV6SOKBCCLEiV6C5re7Ae+EEBxBhwYT zKtFmUeNDCkesWbM44n9AI+D9ZRC1S+lmkyEzTzJvNM+gfIXbQaLvdmes7AHEOJVwjll p/vAsguFr9dO7NzHLfQ3P0LxlwKg7oaTuqwQA46XD8rLnhWD4JlLuo1WeFbNUWqY1hzh Vg6wT0FADReBAGAAcZQbg3lbJ3Js78jMQg21U+tV5KVK0I9IzTrhbge60pMHzHPhBQfd hrUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780390446; x=1780995246; 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=v1suNiINZUqCrLI/VwQHHQcRyvtfBY7Ngnxz2o1UORo=; b=RcTgF1xwSeC+llsGw2nggRl2vlfCzd0vOuGa/hYfFwlmy1IZTTNK05fCxnkl81KzKE DZMbmiMW0htlYDWnlHMCBf/JOS+3XHJQSRT6CuyHTmKZCfG4lOF9WjZnKBZLcINk352Q y0498aa5sz5Xzo4Hqp/Myg/ywmiIt7kTLNhraw+ky4kcViTwDC4EAY8vguzLOss1Fmew 0uPG3oNTOM2ahn4nxHc2WrQ78dTrI3nNAnWJukx7BkRd1jGcXs34Xj38OzlGWZHI+hCp s2S5bV23JBVr45Fr1sbf06/vgBZOTfdYGhExRZWxqRqTWE3E1pKb4/1CX9vhznY/6OUY VSfQ== X-Forwarded-Encrypted: i=1; AFNElJ9zQ4T3C96e7iTKJkQ+pJ5QOILLgSxeAzHh4+lN2f9RiV5MU313/BnQ+gyaIbNYxUxRkHuMxEm5Fd0Idjg=@vger.kernel.org X-Gm-Message-State: AOJu0YwmvoAzaZyzMB0ld7kuaw0epj4z+dpwXXs2F4KPhJpaINr1KL7N danJzmSsxSHy1CDiQTyNunYtfjZtU6wpt9uftZ9YYrIlynFRW/Ar1IUTdq/H6g52ruk= X-Gm-Gg: Acq92OFpcv88Dv5jKRHi/7+U6O0toviOW85A9hcM+OCnzVDoz7zU9U+lqCoRDczVXei u87ufgd3/kjSs01QNVOt6XHBFF3R1+CoeNbkbrzSWI17uvSx/FtqIS47diVcnZ2x3vV13eLpU3J 2KP1K4qO/H+n1CVsLI5mWsY0lMkpQ/ydlc1a4k4CZwK4Cjmp2D+1iLjMZmJiRzfu/TCzJJobC/9 5eX/w9seaIfqVgURoAO7WpojIlWd0zgtrNR/Uy1jErfXlRCobQBLHHLm9pPKEOzFhJfNRukX4Ww HOWI0+BBCMDXe3uAbvSK1etSv3+XdaEVZ0WjoXTj2Kr4iY5gVYWGJtX8iBpgPmAe9qSzwNimyX6 TnspkVC1CTPslBXZF0R2Cpr1ARKipfeG/ZFaflHFxCIHSMM35FEd4rymh5D4qdSBP17ruq7mWoi R53HSp3KoI7leQhrShTOEpz3KMa2SRZfK8KuQa X-Received: by 2002:a05:600c:348f:b0:48f:e230:c3fb with SMTP id 5b1f17b1804b1-490a2988e6dmr292361175e9.33.1780390446371; Tue, 02 Jun 2026 01:54:06 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490b0daefbbsm88488945e9.0.2026.06.02.01.54.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2026 01:54:05 -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 v3 03/11] printk: Separate code for adding/updating preferred console metadata Date: Tue, 2 Jun 2026 10:53:04 +0200 Message-ID: <20260602085312.228251-4-pmladek@suse.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260602085312.228251-1-pmladek@suse.com> References: <20260602085312.228251-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 --- kernel/printk/braille.h | 7 +- kernel/printk/printk.c | 153 +++++++++++++++++++++++++++++++--------- 2 files changed, 122 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 5938e9df7345..4e4aadc51f6b 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2544,18 +2544,123 @@ asmlinkage __visible void early_printk(const char = *fmt, ...) } #endif =20 -static void set_user_specified(struct preferred_console *pc, bool user_spe= cified) +/** add_or_update_preferred_console - Add or update a given entry in + * the preferred_consoles[] 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 add_or_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) { + pr_err_once("Reached maximal number of preferred consoles.\n"); + return -E2BIG; + } + + pc =3D &preferred_consoles[i]; + + if (WARN_ON(!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]) { + /* This is a new entry. */ + 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]) { + /* This is a new entry. */ + 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 +2668,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 +2681,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 add_or_update_preferred_console(i, name, idx, devname, options, + brl_options, user_specified); } =20 static int __init console_msg_format_setup(char *str) --=20 2.54.0 From nobody Mon Jun 8 04:24:55 2026 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.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 0C4C03AD50E for ; Tue, 2 Jun 2026 08:54:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780390465; cv=none; b=ktifALb/14js8MFQD+/MFwAh68yRezEZEdYy1YgqWzgVVB7Vveb17L+pjS6xwisT9lnu/5rV4qAIj8lyPquS9uL/Z2L9bjBs8oOVLbwTB+N1Exk+I+IC7xOh3RH+BpZU8o9IkRtvmVIZOvouItDMI08Q3jGdl5SpCDp5osmT6to= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780390465; c=relaxed/simple; bh=CFoGni/kFfd2DzrCmbPAUyOHnqZ34zCaezXsF0V5Rt0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mYyOk0cLxmQ0oOJTGeZKS/lCKOAhW/2zT5eCZh8G1/RhiYXj5LZM0RZ+h/OKC2PXqcsXJQXTsXe2kLlelNq386fOV0YqWcBQKcWMF2StFHtrg/CUQ9uo2Nv/0BJLE4ZcPQH8oGe0MnQ+F2T6Aftd9hl5teqLXB132IXh7EXh7To= 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=HGeTtnxM; arc=none smtp.client-ip=209.85.221.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="HGeTtnxM" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-45ee6d32402so2719392f8f.1 for ; Tue, 02 Jun 2026 01:54:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1780390458; x=1780995258; 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=yIfYBC9coKnvV2xjTHOUNafFcovucRtDATksoAoVxpY=; b=HGeTtnxMQT+bpcuuHkURejTxqAnMlTXL50fPzKZkfTGilCkPivQleHvnPtDwurnery BP8TTsHyzJgj7GRlrWUfyEUxSVJO19UrMRqmVj+05epWSLw85frwUXdMn7/QZoLDP9uS 2jGuG9/k3+/pOIjJAE/+GfVk/dxVMhD3CDhwXdyOpQYEFyyywtLwlJ0oLKjArZgtvQ8g k42ZHdjQDD+E7Dcv69Qo7VeQ5i9bfdhFzKPRrnXLMaov8hKRqz2/YW4vQPPEcxg4kIiZ 8U8/ijJZjSIRnQ2ZdasJ271Jt32EcqRkjIvV0s3C5oU9oE2/uVvdamrmAKJg4vC0WoD9 biBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780390458; x=1780995258; 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=yIfYBC9coKnvV2xjTHOUNafFcovucRtDATksoAoVxpY=; b=dm1JMpwHPjC97uvnDK3hv0S77SRehPjongFx2inEIeKS4v8uiFWBZOlbanAzkw5eRA LaI6Bsg4ATX9t+LVO9Pv5kxKA8h0+4IfcjDqbiYMbF6WNZYxFd8LrbDVxecPl/lGZ37i Ho5U3bV+fNiEDijZeMeYivtY74OJxD4s/izSnNeYZCqAMQoeG9Pz4qYyCr4nGgi6j75f 42PIZCiUw0WwS8YmbXqSIV++k5cL6u3PvpeiFT6IpgAFeCOl09vxlxC2VojbXNX7fuil 2HVbsSwcRLrPc0PcExvzQtMxu+tlBwj9cI8bBeVyMjMza6D6Hg6UJQX6gZEHqWLXKfy5 mA4A== X-Forwarded-Encrypted: i=1; AFNElJ9YG38Mcswcctoo1zs3DtdLrY/c11PdDLub8rGc58L3l/YrV3XK0G9Qu7vJke+w7ZlodH6UdexVmFKNlpw=@vger.kernel.org X-Gm-Message-State: AOJu0YztA1Ff4sIrGOeeQCbRc2E9S3pxDrMNYnufIThm3my+8S14bRUd okOcO0Yam58PiCC3gcbqTq2GbX5d5JbXxaUn+1Xxh45XpKNWblWxFN496JPKKBSSzLaTVMnMhBF fw+JC X-Gm-Gg: Acq92OGQDBYPrO7lGPEYN5+bY/UdE66aSnRooRhmUIXgtvuEiD6Sl9zHKEckxEMHJf8 iy7ncz7wacDyQ20uxlYfUlNfqc+ASOiqMWLBTOSgPRK8/+VOmF8ApJGOyKKo72E6W71+gxiAJEt K2+Xp9y/15lHNBnTx4n+TIf3LOxet2OqsiSDLQjzvzl1ugy0OA1YyCxGcw1uKYXv37bbqPjtdl3 5tKoPF65fu4YEm7epLZ0vY+S0n42IclvejGK4/L1hhhNRefVXk/DZB9gW+H7C/wu+d1eoOg+Oi8 OX3jiYttR/83PdDppGSDEZGP/JupcESHhvt///tNkPLSfbnjNsWznIJ3jwIYzbrZJObBKSl7rDd WQRPM9xFwZEre2R9/G/EwW2c64Jj2sDus8raDE3ZhpTysDaRGjRE1fYDBW6qUpiof3B6vayPtAH crxeWdYzTSN4zl1KWLrFuJQVfUDeFuLrnmTBwTYOkWskZgg+A= X-Received: by 2002:adf:fe90:0:b0:45e:64b3:af44 with SMTP id ffacd0b85a97d-45ef6b94067mr19058283f8f.36.1780390458257; Tue, 02 Jun 2026 01:54:18 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45ef354b7edsm31498416f8f.22.2026.06.02.01.54.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2026 01:54:17 -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 v3 04/11] printk: Cleanup _braille_(un)register_console() wrappers Date: Tue, 2 Jun 2026 10:53:05 +0200 Message-ID: <20260602085312.228251-5-pmladek@suse.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260602085312.228251-1-pmladek@suse.com> References: <20260602085312.228251-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(). No behavior change. 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 4e4aadc51f6b..ffff77f81e97 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -4006,8 +4006,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) @@ -4319,17 +4319,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.54.0 From nobody Mon Jun 8 04:24:55 2026 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 4D94F3BE620 for ; Tue, 2 Jun 2026 08:54:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780390479; cv=none; b=JIQKDMnCBDttcrLJCScgT1wReF+EiAJYYNcNbs5LYWDMnhs0CPKcUnpqXESblDKwJ4yG4XgzODcZxfx2r/TmkxeacOBL5itw1q0h2+wawzLN53vFahzY3OMFJRxoOWsC5ip6BEtZz3bNsxrESvEjEhc2vVMhOIGnjBzozUeugrY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780390479; c=relaxed/simple; bh=ZaT+/7I10sjNAE33VAam3Fr1U5ow7W6JonB5Vz+sqe0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YgPu9KSqUgdQ4A2j1qbVDZlfESiBJJtvrqceRzsOcLYm7yq0G4VHvrUI3JZDie+7klIJfTLdCfVe+vFZK+lDT185oI/YvIEcc1Qk42Xqq5mw9B9dwnN7dadTl7Pb2A/Qj5vAyOeYDSaXHMna7Pg4evC4v4L6oG+s/vgHslWT4+I= 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=eKgG316/; arc=none smtp.client-ip=209.85.128.44 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="eKgG316/" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-490af320e2aso11280155e9.2 for ; Tue, 02 Jun 2026 01:54:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1780390470; x=1780995270; 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=myNFao4QCXHlYEfG8LUTprsTeobP90lLd7U+QggG78M=; b=eKgG316/KBjytg+fN2GNxNJ1p3YDxyhsc2jNUsCJMYcBoIVJJckjirJ1mBmfar/xFD Tbfw5VjZ0bepbHOY9yGiUhgBuPP+B30TaLuTh3FN9FPBMa6HGaskpiTQNkrcacJ32TOv BuwFTbG/zJP335PoBSalUR6U5Cy5aORr1Ip7tVkpWEKlNYtui05B66aCNJaCBpBQXEv1 Syzpu9/ubjaHNUL/ngmLvDUewTbciHFWXZYm0adEMo6ujUr9DuUSIFmIdPeKzplu78nW v1/VuqkJaRf0u+xagl2Jyos/NJ7lKU6VWw2IF7vbMb5PLvYlqxd4EQt2wDRBFTXMQfRr op7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780390470; x=1780995270; 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=myNFao4QCXHlYEfG8LUTprsTeobP90lLd7U+QggG78M=; b=VDtKCNtNfnrRleS99VUgS+7nED23duBcdjXUGYxCnPWGiA7AangokQHRdR4q9xaGt0 2IbrAs1bdsATFEsJIm2ZupuWgdcdyD7g47SC7v2DhyIOLQRDNXn9e8IfkjILxzn/t+Yx ZIUMMhp07NQ4X6zoBI+GWO4lyTTHn0VFahR2qy9UOMFYbj4DbAJ9glFUAXiFnprcjoEa cSgbulstaaRQ3g63DN+rV3JzkBAGPyL5hAgHz1QFAN5deMveN6D/gY6VYrfC4TiSp8nJ fzjDCkRB9+jgr0wCxZruKkk/1ZWUIU8I4MU5oS2VWySxNWBOauCoRDDd9kw8qFbBZTHz otSw== X-Forwarded-Encrypted: i=1; AFNElJ/NpHUKjKlWShirNTSCJ7PbsdIVymW9RFLEbcL993GKn0yOAJGq66dpguepFT+uhp7CrYji6/fEtrhcCdc=@vger.kernel.org X-Gm-Message-State: AOJu0YyOErIPWxXzMB+ZxTaKIIoMuwmx1Tycdn1sbaSU0lJSCxDUnBN7 Utw1EWG+at/Ng+o/qe3iqSpqSFQ+UKpikZOIU9oDDywixKckuCWCX7R5tbulJel0B4M= X-Gm-Gg: Acq92OFD+lzM8RbESzdzxB0zV86wfwE6oOvo4y3HIAgvSkJ/SwIGkiHyIlhJnW7XzFH YDfIQj0Ob33eiV3GNQRWR6U2wQc7NPfWNn+9ZT4llUAqSOzpKMWoCsZRzdYXOYK6es3Chm/XR8m D/Wib7R1a7ACWhQ0Qncz1WCk3Obd3bqrYHrl+tib+fI46HLh+sRwxXnu84GEuLfPO/TDolB875c ecjDC6mpDL1SwJBcRae7tK4C/gPA8PSUnaKqWcdGG6ahE/Tr5YdGi6fq8fTmeKNrdBeygl40DaN 7uravgc1m+SJ6QW1JOAognDnrAjn/9n3/VJ3TT+Sc0UOC7QCdrTg8Zkfk/KRCtfCCPyKi/jsFXF /x5t59RKHFEFTLtL8GjG2JIWBYhtzbpG9k8cRikD3e1uRogZLdoC6EwnLn97YdMrZZi9ZMDpo3A xwcV+dvjDfTJq+U5u2aOvJHKwxgiiX5E5KJO6i X-Received: by 2002:a05:600c:190b:b0:48f:f64c:c2fe with SMTP id 5b1f17b1804b1-490a298f29bmr64680585e9.22.1780390470661; Tue, 02 Jun 2026 01:54:30 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4909c1035ebsm148114195e9.5.2026.06.02.01.54.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2026 01:54:30 -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 , Sashiko Subject: [PATCH v3 05/11] console/braille: Lock console->setup() call during the registration Date: Tue, 2 Jun 2026 10:53:06 +0200 Message-ID: <20260602085312.228251-6-pmladek@suse.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260602085312.228251-1-pmladek@suse.com> References: <20260602085312.228251-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" In braille_register_console(), the console->setup() callback must be called while holding the console_lock. This prevents a race condition with a possible active boot console that might be using the same hardware registers. This applies the same protection to the braille console registration that was introduced for regular console registration in commit 801410b26a0e ("serial: Lock console when calling into driver before registration"). Reported-by: Sashiko Closes: https://sashiko.dev/#/patchset/20260423130015.85175-1-pmladek%40sus= e.com Assisted-by: Gemini:gemini-3 Signed-off-by: Petr Mladek --- drivers/accessibility/braille/braille_console.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/accessibility/braille/braille_console.c b/drivers/acce= ssibility/braille/braille_console.c index 7b324329882f..9ed3abffb687 100644 --- a/drivers/accessibility/braille/braille_console.c +++ b/drivers/accessibility/braille/braille_console.c @@ -356,7 +356,9 @@ int braille_register_console(struct console *console, i= nt index, if (braille_co) return -ENODEV; if (console->setup) { + console_lock(); ret =3D console->setup(console, console_options); + console_unlock(); if (ret !=3D 0) return ret; } --=20 2.54.0 From nobody Mon Jun 8 04:24:55 2026 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.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 98DB61D63F0 for ; Tue, 2 Jun 2026 08:54:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780390489; cv=none; b=WFWM0Ht7uPjA3OfirCmqlANgsnO7j3Vrd/S4JSEa+4hHgcOUvZ7HzTTmmdhmRU71/6zgjcEsQRb+EgnZbCDtgNdZ+XbmWuZWgU5LPgO69GeJnmyb8e4jsXmUl5udCGm91zloRKh7CDbDjMkZ5o+ZKal/ye4ewA9m3Ihvey9Uuv8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780390489; c=relaxed/simple; bh=HxvPC1NjQzsCeGTWTnfvF69v1VKVbvc7cmgfUlew6t8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=am4kaqX66KRyxpM8ijnqaz+O12CXwRDDWMbbUeqTCBYQ8nwd5JAGVE4rorABNH2m2m/nb8LYY5UENSJzhWeAT+Hgso1dh25xaOxhaODP47YVMepChPGm3fDMC5+YWWRiUx6xaVqPqvi+JtSpRB0JdHId2Fb6+5VtyJx1VDT4JRE= 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=P3NUV8KR; arc=none smtp.client-ip=209.85.221.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="P3NUV8KR" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-46019b190b6so476200f8f.3 for ; Tue, 02 Jun 2026 01:54:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1780390483; x=1780995283; 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=G2N8t5kxghSp3RHQTPMfvphKu+Jc1yGaAHo8QXY6/R8=; b=P3NUV8KRi4g/QIqOUAPnA7zDQuonIa7695/3vUfJBdxZbzQai50mW5FcTXv6Ny6SCA BEAK7P7ys73N+z2zZNJSR1hm52rOKB+BoGv3hhlmW46ckijhCTC/hSomn5nrc2R10Xss M2g6eMNWHHI7fJQLYgz77zv6L8DIqs6Anbtqj0rrlrDQ+fZ79w53gEjN048zxApgKRzg 10b6Lm/K41ZDqqoHZqpsYwT+eVNOkgvWj70mRjZKokZzGT+2M9Je4uSmeUGkDigPTWNw xSTxv6smMzBLwsbKZn26cW/RS91XFDJri5PvMSYWq4KZi/LBHRw4fu7N+1ldfify1vb5 1ACw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780390483; x=1780995283; 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=G2N8t5kxghSp3RHQTPMfvphKu+Jc1yGaAHo8QXY6/R8=; b=iwYXQs/osEGcNZCtz1QEx9wuZHCOj37bqxXKV+ga0heO8bFXEkSxdnFitcbzbLXPl7 3CC6xuCGfn/vtkN4GZ3CZLM4A6BWJ74LMACCjudZoacp1Kt02t1AavZn2rOrn6ZGmozh 0aSosnPgMxMxVYbgV+wZiF6pnfHTWFZ66FFlVnGU3Ru7n3cr3kENY/hWd4qmqSwQtC2s o9S0jrkVjxQsRuG8Pf2N0W87XR/VQvUeWn7QnEKhzPy+f6TX7EA6/a+UCr5KRxSn7UuV d3w/8YmA4pukIpxfxDhj/y44lu/Svb8VUfabyaDAlvNAaVq4uUa+s+oYhQN980crFr13 OaVg== X-Forwarded-Encrypted: i=1; AFNElJ9jB8gzPMW1rRaKQC89olm5cNH6bDy06FEHnERAjo3GUtmOfNBAMGYrZV+cuoOcj4w+BSkzDOZNj/V79lA=@vger.kernel.org X-Gm-Message-State: AOJu0YzDqhz+k57DKBwHp81fWV5LyeysfDoe/o9DJ4KRKebG/ZRChe/q SZZSDJYvfURZbOmhRETml7yeK7Rqatx1xW5OFc4EY02uaJkkFx6MjuyDYIVOlehzj50= X-Gm-Gg: Acq92OHFEq+QpRUIfk8z1P8MaFFy5jUuucwTSO3XIZXd4ajXpHSzdJ7Xa8S/YEn2QHQ dUQLIAv7breACz0CCPiXY0+E65zQ/ul16VMjOU1X1XHkAom7mgIkH1TFzm9FmsmkuOxUZaoup4W SlYaLoAOoeoaeyerKlnkX4M2JbRCcN3JNQQGbsFmCSWM6HMlgmFxeiSDS+KggTfLGlKpMfJQM3r 2XHZ50RqsvBR9O2TE9L5KCcGjKFL58iMRO7VqYyAR+6B/m88NWJ4ZGaMD+xpcvEow7TPnMSSova Bah4/C2zP1Kzl/TATroUfKbkc84hPfvOWcfCqjIcrzyaOOKhHIMzEyPdna697S6a3NELDwC11aa ye3CWOxv/c3RSt7buHRW+vTYDLi6C2hWE+XFDmrA+0HJPSk6MuXfUHN1+N4uyMkPOOcJkP8bLg3 B7teVveLDDsIhyMAK897zbrxqaTl9PfeR1rEL7oABeojHxN0g= X-Received: by 2002:a5d:58d0:0:b0:43f:e934:50ac with SMTP id ffacd0b85a97d-45ef6aecc76mr20011409f8f.7.1780390482728; Tue, 02 Jun 2026 01:54:42 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45ef3595ef4sm30043231f8f.37.2026.06.02.01.54.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2026 01:54:42 -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 v3 06/11] printk: Separate code for enabling console Date: Tue, 2 Jun 2026 10:53:07 +0200 Message-ID: <20260602085312.228251-7-pmladek@suse.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260602085312.228251-1-pmladek@suse.com> References: <20260602085312.228251-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. No behavior change. 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 ffff77f81e97..6b23a3b677b7 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -4045,6 +4045,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) { @@ -4119,9 +4154,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 /* @@ -4183,31 +4215,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.54.0 From nobody Mon Jun 8 04:24:55 2026 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (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 A83743C9888 for ; Tue, 2 Jun 2026 08:54:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780390500; cv=none; b=JULd7uONSFeuOtLyIhbfdOlZPvNILwVK7LeTc+XPvAHJ9R5aJY7YtMVICUPcuQdFE/Lc1eNAYc5QrGYnnAAh38vZj9Ha5j0E5KjMaAArSu4Vw06OaVuSgvsXqkrgkhAEPHpDZ5IVTzT6YZrzQeRY6Ue7fQTdDweeYx6jgm02yg8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780390500; c=relaxed/simple; bh=r4gjHMrPvYagKtkxVn/aOP7Aw6tIo/dCWyNDGzAEXVE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cThc/ayoyo3+qF77v6snpWFj0o9w0leMWbUTpD+YnqV6ndgXEG2dA8ld2IK4xLrA5duSV1ivrkuLE2/fpGP87Wz6fbt5dHu2iJOSdOA9UqJpRiv6krd/HzsnsWvtdKpK14atHbny3/0rdsN8eQ6XOcnAExZDkzkPweHya+TTKMc= 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=RRQ5LO9a; arc=none smtp.client-ip=209.85.208.49 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="RRQ5LO9a" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-68d234218bcso4435259a12.2 for ; Tue, 02 Jun 2026 01:54:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1780390497; x=1780995297; 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=gqrj4xVPWGLmCrkZBPqs0EHz2T5zlLU+/FlWHn0jxHM=; b=RRQ5LO9a4H8vIAK7L4ZMIHrypj9tt4iFw1xbtvwvKQbUB1hiFB7N5plgKC59VV38HH i7PN1nRkDDGYbwx9dxcUC4Wa7N4Kjrnc2iB5OyNxgXgvu8MGdyYQ2eAJtyn53EG/nVQc DFk7dSValVJDJMTZ5HFvsOm8oEtM7zCRdfIAOL3TvH4Qa5NVqhIXp0hH+Q+9z0YavkJY xjhP/kbhqEPd3E2PRFjCLCoIHrrdY7CsPfbID0t8Q6joybrTAUTM8K0UoYJV2bb25E1o gVUWkD2sCfGWh4CJLux4CPtlVgb2p343+Xx+NJsvieUt2KttGSVvEUU0A+dj50FX0jOH WOHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780390497; x=1780995297; 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=gqrj4xVPWGLmCrkZBPqs0EHz2T5zlLU+/FlWHn0jxHM=; b=jTI8ZkTSaEa2o/hnAhhZtsXjXz7gm0qylELX0T6f0qF2V9CPuD5xVhgcXUq3JwHCRY X/2549WZN7/dQKg9oqfuNP5OUEGW6I6B2hHFyJz0knFfVEiNQlIv1QKG9JTpc14fNDPX Vrfs/4kGML8tynmExJ7vrpkfn9hTdGOKGoZ3tUHRzzhxvSkUmCGfKn83wkNIXdupN5Ey TSGAS+7qZLThutxurwp+etXGzsLbwEiEEcUrvfM8gEGrHfIgDl4t3BaBXXq30oq58R17 SE+DXAKH0ukRchZlT0cGYpSDPok/45XJGB6uWO2Vy+5wqu2yDz5R4GH+/Qoiv+aK+ySz wTKw== X-Forwarded-Encrypted: i=1; AFNElJ8GCXkLw1nojnG/GQCsrqJx04jIY+aKRUl3kWGrN7nn6BLCtVyDSX6fRnOJ27a4zMPqEyQ4ABFiQVSPDZ4=@vger.kernel.org X-Gm-Message-State: AOJu0YysoSS4nFoJuOZybg5Lo6i9mPRXr6HGdQBtuAww9spWMhXFtTjk StOsc99PwQpXDm+JSV9uJ7ELIJM1Xcfp9DzxWkp6Cyh9i4VZ+i9fzJM1CYWDItcqS7UesU8LX+r izL4C X-Gm-Gg: Acq92OGn7o8qeDrjFz56ZqzNOacp3vWmG2AazIn8+abuvPk94sJ2NpWQzLuwKK+0CPG vE5mddKfdfPMGvb1W1Br6B2FEUBXMcEuCqVy09KKze2IRVpZKYOs8e1nNlQOLiDDlLnZlxN2wqX ntsk3FmaMIlqPXn0+bzmO0pDZR6tIAYN3ydFtzGmBm4R6NMN2w51XMTb63bw6s4P0ipeqydo3Or 36T3yOcu69OJhjIVxPSMH6XHI0NjPdXE9e24xKTr7j0ClniFR8Hii2g9VU5O3dUlEtDMMqtt7B3 WK4PJJD+iV9997V/tj5zciSbkbfc48dHPdIfBxA8/9RhLTU32YJ66DyVWjClEY2Cj1m/dnOUF0A Qe8N0j/VSXOcg9iXKFkGHaYHDAoDBVe9LMXVUK4Il4fd+TmTQjBFXEwDL0a6OMv/cXx8RqKc8GH E1bkdDVv016gxbbg8+3HYGdKutLHb05bFi/qmSIgGjSPcldLA= X-Received: by 2002:a17:906:fd8b:b0:bdc:ac75:73b9 with SMTP id a640c23a62f3a-beab66dcc4fmr844954866b.43.1780390495270; Tue, 02 Jun 2026 01:54:55 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45ef34b834esm31605817f8f.11.2026.06.02.01.54.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2026 01:54:54 -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 v3 07/11] printk: Try to register each console as Braille first Date: Tue, 2 Jun 2026 10:53:08 +0200 Message-ID: <20260602085312.228251-8-pmladek@suse.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260602085312.228251-1-pmladek@suse.com> References: <20260602085312.228251-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 6b23a3b677b7..4a7ecef97b04 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 @@ -2648,7 +2649,9 @@ static int add_or_update_preferred_console(unsigned i= nt 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 /* @@ -3980,8 +3983,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; @@ -3992,8 +3996,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 */ @@ -4006,7 +4021,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); @@ -4030,6 +4045,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) { @@ -4052,6 +4078,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.54.0 From nobody Mon Jun 8 04:24:55 2026 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 552933C81A9 for ; Tue, 2 Jun 2026 08:55:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780390510; cv=none; b=eFCf0QZ/xjWOYc2eehd+SF35K2U0hNv5j1O9B6qTvM4EGfYVBXuc9jOHm/bRgGaoes07Ko1dZEZhe9pOOKArzLJPuJ1PARFT1Up0iOGe20O47LhQoloQd/G0n54tX+PWjwsmOOIKS4yXLMfWUnPBeksJRA1FbbXbyjzGGU3pjnE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780390510; c=relaxed/simple; bh=NriifX9l+AOOXiU9CiR5iqOsLjleHLgKz8nc6t86zj8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pB9RFZMqQ7TUY4OYzZpTQPUqoFZTWH1RIbrhWCB6diOr7obYieBR9n5BBxUqNWGetsqbR2eyKja50hKg9Rwk3BU0pyBTB9JOcr0SlsJGyoBCGLFtIW3nz6EVOstrBi4eciDhzn88r3W16U4elprZLfDRjQEkcqNSNVasGtDl24s= 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=Y84cHh0f; arc=none smtp.client-ip=209.85.128.49 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="Y84cHh0f" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-490388fd0dbso111627915e9.0 for ; Tue, 02 Jun 2026 01:55:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1780390508; x=1780995308; 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=n46R3qXfkU7oRMH+JFixKSzY2h+YoJR1acg080JNZZ8=; b=Y84cHh0fya7ziYhD9N/F9ISietl6+0ZtT9eOWt8HEhohh18jQB3C6zK2dHare/hMET rRWOAcS5x+VtZAqiKMqS4kxAhwndTkgRwD6lRSSb+IkiT6OSvaHAvIFJij7leazyDTWc 3Q6paqVLaF5W2Ri09cagSg1VAQKl/SB+TWVPXWtd+ZSlQZSI0C8sa2/LwzrigmtR1k7q VmxoSmR+Zp1+7PPTTCOIzQ90TAD9am4oMiVp0pV9x+CQoGX0eEonR3t45xS1+UFdshSA tgSC1cF4ODvpe6gcsIaPmd53L51jdhvvbBRevr6qTitszuXrCfmgfwX3nxWV9nyiyAAA 2JbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780390508; x=1780995308; 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=n46R3qXfkU7oRMH+JFixKSzY2h+YoJR1acg080JNZZ8=; b=WVaMXGj1q2BgjQge4zSpIyWPkbjLDaHDpkqsUtomCcH1Kx3L7qGzsF7WzwpAO/IGiq C0sln9+Kyu1G13ur153JcPD8lVZrUsszrwyr7Iji15McypTj49K9EKND5CcP3iahp60w 9BN/u+LYYx5hpO/r8ZPgC72MV3y0tJXQdNfV/Z833Q8aWGB8giyiGgNj7raSJukjaWyC +/mUt/r7YUXAMzeaKXypdXm1P0CLpTVSPs4O6XJXeY2mpCHyRa5ZU57nDwYMqdkWvIDp B4KigfXuQ9mKbvqCzizHCCQHa79kr88RaxzEw+kfsX0jzyCJzSVhUxWcEFjsNCyfj6+X aWfQ== X-Forwarded-Encrypted: i=1; AFNElJ+mwe4a21cFRWiDX2JQNiK3Gq2bwZrt0gM2LHsqt/iPVdlP6rT2jbTjjUATgIPJfymVzYfkLwzqJUXvrCc=@vger.kernel.org X-Gm-Message-State: AOJu0Yz/3nrCxRV6hu8CgI5XVqoG0gbXVbWN1w41Db4sn72IjhJ9wIEF pMYgZEyicMDLpElEdw81PAyieST1YNcqLxzqDHf3tO0/yjToMB6KlFjnjQnh5SPRbto= X-Gm-Gg: Acq92OGassq0qmpfUqExaVA5hDXhSGhoZ41naq2HS/HZdnPdCwak4qmSPpd1omA0gvH CUSpg8qTtiRTwvuWBSl4C0FXNycEJxyA1KWWKEdtCECAvUf1LybYowgArEJbDBr2/J+hT9/ryWL rLODxW+zXjSKsqD3FcYp6uLrIPFExpufGriy2/U2CjF1b0O1/dHCH1HYts499rb+NrsEXNSZkcR yrnpop94vVd5MHPdspoAWnzFr1mRL3gw9tRpVgTm2D+EzTtoxh42k74MC2V3S/9beIFbKO8puJT MhVJ1gEjjMBofkRhDlng355Kr8kasql5aQhUHbY+CtpaKsg6sGwZ122zZtKTwNEMCG8Cu/XDoY2 Ivric2Jn/a/+StJcbWOWdKcx8qN082fYUL7wKzAfVS75VnyFyuMIFletCtV67qJd2Uufl1ny5+S gD8nWdJ3xOo8HwA6WH/egtDFwCaBgftH+DL1U+yXSPCU+Nfwg= X-Received: by 2002:a05:600c:4f8a:b0:490:afc5:f95d with SMTP id 5b1f17b1804b1-490afc5fb2amr72778495e9.29.1780390507705; Tue, 02 Jun 2026 01:55:07 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490b0e20bacsm50457625e9.6.2026.06.02.01.55.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2026 01:55: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 v3 08/11] printk: Do not set Braille console as preferred_console Date: Tue, 2 Jun 2026 10:53:09 +0200 Message-ID: <20260602085312.228251-9-pmladek@suse.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260602085312.228251-1-pmladek@suse.com> References: <20260602085312.228251-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 4a7ecef97b04..97327c27436a 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 @@ -2649,10 +2651,22 @@ static int add_or_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.54.0 From nobody Mon Jun 8 04:24:55 2026 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.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 EE1DC22D7B5 for ; Tue, 2 Jun 2026 08:55:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780390522; cv=none; b=qH2dPUSlB84cPf/lJ8DYDyBp8TQeM+e/ruOOMTcB1faxdEgXzmipjWEhqqh9O+WsmSZP1r2F2t4979vDCsBvAf2Vw1E/hYbr3fPEkOUE9JD9wupwEEHoV1sPLJ2YabR1GaiKoBTCbaJubZcZyQvjDq5N+Bj3U2Z/ACwcy62kxOg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780390522; c=relaxed/simple; bh=jGkvL8etaBzyJWE1YCKdlI5DAJzYmJX1S4keeQJe5pE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Mpyqlt85vb7l7DIa02fu89ryGZ2umuEOlXpCAb5M2lQ2nzQ3hg90KDLxm4qiaAde1j5m8eY5fPdDsgcFbrKkWy2mwUSNsaoLs9PrIaI8m1b7aM63S6LeG956UWJs8K1zXDfDKGn537OMRW2+RMUQXU3igg7oB9WVNLpkwW1NdZw= 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=QEa11p3G; arc=none smtp.client-ip=209.85.128.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="QEa11p3G" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-490a7678b2dso19851775e9.2 for ; Tue, 02 Jun 2026 01:55:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1780390519; x=1780995319; 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=oVL4jOZ//PvW9R/mRISI1v0jCG0a8V/9Y3FuFcbG2Uo=; b=QEa11p3G8upVkwHYQ5efdNg9goPaP7VasoBz3ipVhzFnzVH2zajG2SrEaR5k8BHVLx 9MeKQJTcxHlko9JDux76h+KquAo+6S9uQYYAuGzapBsdZ54tPs9oNfg3JiJ+Hrw/Wydy zdCe5pwmJ4V1XPgainriRweE8kWdNtxr83MudeJGqy7p28ymvcYcfnFTsCslfGnKYr4p KaLVtPZn/TpvN6Lc623HYLrxu57POn07iy1OVOqknu72xmGyKlBqiexni8OTRMBIAd/9 uPdzomtq5Kz9uM1tZDk0re9BjVaTTIrNfEAV1jQlm8g+EPSiRM3v0KuBeiCkkt7Us3Ww FmyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780390519; x=1780995319; 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=oVL4jOZ//PvW9R/mRISI1v0jCG0a8V/9Y3FuFcbG2Uo=; b=DD1P7lfU/ORtwBntVFU98/WgcoVC8Ib2QS+lWDKInu6Hi7bKsz10FI1Sx5c9Ho8LhY DS0h6TH5EgTXHX2vpzS0DVZUn2amrtpDSFYWmrI3QWC6EM7XE9bkiTMbFnbkwjhtZGZP KSwy1qzJGsRlEnJRRk438w6A0TbNQgBrMM2jQel/C9r6GH2IElCbml4Wn07F7hrid0sN AyBXcY7gE1rbGrU0y1h1AfQoLolaslm/YHMS078AXZPUGznwpHLQOBm8UiD9m3c7mPQO seQtoSmT1T8+6hBSKSJCzO0bpClIoNQkuvsl5K3z0Ku1qCDsob4+d7iYKcYIXskZ2E6O BZHw== X-Forwarded-Encrypted: i=1; AFNElJ9VlOL+qoBmyJG8CfFajmlK874WBRROplgM3Uz0BV7CCkjioZdOjl3rj0fs1XNZKPHn09xXtXCgfKlJEII=@vger.kernel.org X-Gm-Message-State: AOJu0YxVd8TZGyopvTe/L0NjzpYEZXkebw4GNKPvYyeUwvZTu6dEuYsN xnmz3Y2973cvzfZt287Iwx9xi9wTcrKyrE1pJLHSuEZWSLImWmvvmV5mqqa6p3qsS9Y= X-Gm-Gg: Acq92OHKoxgRnDE/gwuQISnq3WwcTfkpnbxoVVmh7DCCng+z0wf2FX907ShAaz0pA2l t7PEZ992XpyHLNsKnvsQ3RDiNMNC8Hb9ULc/P/CCa4bi3dhqcV6e2geNNG2h7t8OpSdlYiXEce8 /OGqXqFJWS1gvtPHdVXCnZMFU8Kk+QaWHVZ0mxytwUP7BWd3X1feWJ58GBNRQvIcMAkUY6Y0kgg mIIC5wnemyPvwbi3uoPLO1YlxEB4klZio0Fn1yiXTqvMxN5W9Or+3lzQYndzfXMOSrsizUdkVDx Rq7PxhhTGwqHlSnGXIHpdshRe/P5R7PAONRXJzMwmEw93gX9sVG0N20+ENNU8JJNt+gqA79Yt62 2uoEpH9x+nmLLCNqWSosKiPQozznxWMrdrsKDvJs6ePUxvll2+SARj3kdEZy99zY6Cej9R5vlcu 2nx0q4Dt/cpG5dOI4XxZRr+9hNnrAOAceWMRmj X-Received: by 2002:a05:600c:a012:b0:490:9d5b:d721 with SMTP id 5b1f17b1804b1-490a292f9dbmr262836485e9.16.1780390519481; Tue, 02 Jun 2026 01:55:19 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4909c10376asm95064055e9.23.2026.06.02.01.55.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2026 01:55:18 -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 v3 09/11] printk: Handle pre-enabled consoles in the top-level try_enable_console() Date: Tue, 2 Jun 2026 10:53:10 +0200 Message-ID: <20260602085312.228251-10-pmladek@suse.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260602085312.228251-1-pmladek@suse.com> References: <20260602085312.228251-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 97327c27436a..a4eaf157cece 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3993,9 +3993,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, @@ -4048,14 +4045,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 @@ -4135,7 +4124,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.54.0 From nobody Mon Jun 8 04:24:55 2026 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 01CA431B80E for ; Tue, 2 Jun 2026 08:55:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780390535; cv=none; b=trikOppLiut+8yDzCsgvpbpkKq6x/wUYMWgNzeJ+cxyuxDfTLcr3pC7wfDS9M8pEFm/AXatSo1DXCBopThZurm/lq0icKol7gsnrEl5N7MOoOeAcItuC8z1A3bhvwnAfPZk2LojUuQh5LzNpsMuHJ9TQux5FBm+B8g2lNzm6tkA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780390535; c=relaxed/simple; bh=e0AoXs/6FD9FCUQRAd9/tP/d4AOU1jbUQld9ovhylz4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MjxamaSdozyYUNOoyxjIKR34xumGgFx7v4NEuiwi9ZJHhVCN7foY7SQalbjUGy0jxosNkF3dH7q4cqjQeYwMsLer8gTzJ/2vGSXCwRJmJAWdNecsIW56X9v+xeryk21JlwvkaEpNME5jnriIGcbXRVDp/cV4QZaDcqWKY0ny58o= 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=CoPgLVsO; arc=none smtp.client-ip=209.85.128.44 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="CoPgLVsO" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-490b1bbcf3aso4057105e9.1 for ; Tue, 02 Jun 2026 01:55:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1780390532; x=1780995332; 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=jP023VEDqnXhAI7yeQ0FG7GdS1GrrxF3UPmb8MSuyUk=; b=CoPgLVsO5Qp0XBb0SYDqcgPwRZLWG+YMT0oKnr+TIHoXK2tcBBicESQ1fmnzR9WOZN QXAfugtFj3PW10ofk6avcOi5lstJSeo95iCbiysPa6Qs7PAeuACO3inDC58tb/P6hJLN IyM9NVfP6pRipmeJ+akK6qFbocndYbBIDjaAU7flg07TkhteDjPjJg06c6/Pc/E3b6xc OQdAvgTmvGiXJK1xdM2FzZjFJlKu1/AhNf7HumDPnitcwuj1RYp5CFghTaKvYj1xmdIx Kv0TdKJEn1EfEjQJw9h+J05jcIx4YRd+EKici+m/XwUH9sOUceZCd/aDOv09lrsNx5L5 2F5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780390532; x=1780995332; 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=jP023VEDqnXhAI7yeQ0FG7GdS1GrrxF3UPmb8MSuyUk=; b=cj/6BYL3ySyVq9x+LsqKlM0gi/h405UQH4Ggq5Wk00g0Py2k6F+DTOab5ftq5Faic9 YRV6WNcNpOhVc+k4pJfcgPs2digU2dh1dC2iFMGO2OW+uOr932VVUQxINcMB0EgyzsjA jNnlaTxppjnzvnBbeBVzDm7k63cdOROGhtttPl23BMVPMAMOJKJIOm5nBVMVxB3tR4s6 ucyPx3oY2N+ILY317VJehWXK7QxmBwPNamWLgqutM1EoZhInp9ICPxxU2Hrgc+Fj6/Le ZBcdG/c8Xlkse4qnPlCN6/+aTyO4z8DtrP62GQz6Q0dcrGHkwnMAhvJ0XSujvq/J5y+9 AeQw== X-Forwarded-Encrypted: i=1; AFNElJ/psK7MQBN/e0UAW6DiDNhnm4xeeYYL64OrmuK23VDCZzOFiWygtXEbhBF79mOv+abA0Q4e/9C9ckzvPKc=@vger.kernel.org X-Gm-Message-State: AOJu0YyI7uBJQtQWCeRKHAjWLzds6fq96Ps4LueIOoiXe6b3rdJ0rini 9EqUY7qpYtaDX4gUawUfVr721PFiZuYXHtxxfvGfPFe5i/cP5R3G2firs6r/6WZmRF8= X-Gm-Gg: Acq92OHtlo2Fy7kPax25uIBe6eFBB/PtPFPdLODZj11L3OOZqEbmJoHjzgsm8Z6lZCC gbmwfrEU9zDsOcc1NyHxWGQuL6IYfR4slzeQOPM89vHidh+uia7BxoGnKQbw2yuwtpHdwPe/0Lm vrjxB/KgGvfkZEYnqGAzaFiLYvGJ10s1U5IzJ45pD3yuaUztj93up+9cUX2jGM9v8J2e2BOOgt2 SKT6SpchyyMc0xvmI67yP2Qiv++Mg8wCHPmxyLnYQiGRcHrFMDpJZRGBmQ8mPnIitA5SHPY0Vt2 vVwOzxmVu4PiBnpXoV04yszjzehyM3ibrMHuz2lKGwIttxSAXqetTB4IDLyq6tKfyxWMIougBu1 mgBbSdR6ucQRn+D0ez0xEb+4FveiS375L5rl71HUwQSzkcbsVvuXqVqXK1bYqt6ylkSkIr3oLCm zxigjRj/vg2lAHXVU+MGFyMbh7oPdCCFjKT4mfruCiNCPXHac= X-Received: by 2002:a05:600c:c492:b0:490:9d1b:f088 with SMTP id 5b1f17b1804b1-490a29e4383mr256190585e9.2.1780390532358; Tue, 02 Jun 2026 01:55:32 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490b0e823f7sm57545805e9.13.2026.06.02.01.55.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2026 01:55:31 -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 v3 10/11] printk: Try enable preferred consoles only when there are any Date: Tue, 2 Jun 2026 10:53:11 +0200 Message-ID: <20260602085312.228251-11-pmladek@suse.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260602085312.228251-1-pmladek@suse.com> References: <20260602085312.228251-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. The 2nd fix actually helps even the 3rd case. try_enable_default_console() sets CON_ENABLED flag on success and is later handled as pre-enabled. Prevent any future hidden effects and call try_enable_preferred_console() only when some console is preferred. No behavior change. Signed-off-by: Petr Mladek --- kernel/printk/printk.c | 46 +++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index a4eaf157cece..d62901a13bf7 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -4099,35 +4099,35 @@ static int try_enable_console(struct console *newco= n) return err; } =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 (preferred_dev_console >=3D 0) { + /* 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) */ + err =3D try_enable_preferred_console(newcon, false); + if (err !=3D -ENOENT) + return err; + } else { + /* + * 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 (hlist_empty(&console_list) || !console_first()->device || console_first()->flags & CON_BOOT) { try_enable_default_console(newcon); } } =20 - /* 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) */ - 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 --=20 2.54.0 From nobody Mon Jun 8 04:24: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 3E64E199931 for ; Tue, 2 Jun 2026 08:55:46 +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=1780390547; cv=none; b=fuhY+eZ+0SB+lIIuPYdmrKvkdByhFYi6KtJH4IytU+ryQWLZbfXiQbPZcil0gSAQFl1+jgTp3qfTpfuPpYEcxm7e+GD7uiw0QP7TyvYfbahtP47qp8Ay5WqomDtyUw2ZRVn2CuB3zKZ9c76mgQuvpiifxNa2NAJWb/UTnBrcSIQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780390547; c=relaxed/simple; bh=Z6w4sVV6Y/MGRm/HDpSJCbsxtf6Fj65qLXimVXwN4j0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h6v6gECKwBoBy57jJP5EVF1IWhW1nyUgLueoaWIq+Xd9KDtJaF/cr67oHxnFdom8K3/5rn4n5tTczmukU93ZXeInbfE3z3OQWsmUzVVvrYtTuw8kqeXJAxY+/7/cVWH8jj7zTSTJTatbqwz+fhmkQU/fNM+QCd0Z7wMXYixega0= 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=XHInzXLW; 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="XHInzXLW" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-490a76757e5so17056705e9.2 for ; Tue, 02 Jun 2026 01:55:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1780390545; x=1780995345; 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=q4vp2hRjYAf30dTYx0ooLx3waKeJ+Ae1hKG02oNbz80=; b=XHInzXLW/D7tEIlFydEZAHXTJeYlpIm0uDEioXCOTqyN1TqQfa+9mbRcJ6UpHqndUx D0Ajp8K7kPLcF8zT4ZVOck+QFnTy447W5ciueF+y1byP8Oq2P4+ach26WTsgG0mLJq7d 5xBOQ0s4DoLecY40Kig/dt62iMllhKL21LhnHoJKSUjHTACkqsAZvXhcUn0KQXD4VbC9 RbixyUH6AKE1iyDEBkGhc/T8KuHOHafpMC885kemqojYr+sgIATKkG4hZpIJMeJfT0EP SUpWtL0NxOYBS7p/GwVtuYs3KkOoeBQSZPphrvODheLUmxZVIUeSD8sMhegctuVnd+Qj usrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780390545; x=1780995345; 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=q4vp2hRjYAf30dTYx0ooLx3waKeJ+Ae1hKG02oNbz80=; b=TJ0SUCMrUTvLP3ocpB08dwUh+epGbgiv3wfJON8TZhGw9xMHBRwzGkof3Uy4LzVr+h rVWj1r7A1Asc6wBLH4h/YfdPiO/qryzRldoXjLFVTG3S8OgmW7gJIsWTzFMKd/so4phb zx1ohMaEd+uM6AYc/R5gvfUmvlcskxNti5Nqx4o4xDdwUhLWVWBcWPUeBv8Zrps3B06Y 8OGyyO+A5iER595sHgzJbZYoadbMYnRN0ylMvRwIau1cuSJJWkEQzViWg0bV7S1UjS5K k6vlYqL+CoLu4Ibj998BWG1vu4B7TLs0BSvlk5U/ngwH60E2C3tF+vJmMXHstJYFhuOp 3y0A== X-Forwarded-Encrypted: i=1; AFNElJ/J7w+VVl6vgSCWN5QQNF2dhSOApSixT3eW7HZYm+cL8Dun5+eNSzGUDI0Ec81rsHUaHLJIbH2M2vFQnJM=@vger.kernel.org X-Gm-Message-State: AOJu0YxdYljMsnKN6qZiAMR6+nB2RG3+1heEW4Cv+PeH4ddENcvXu2Ea /aO3N8r6qYcvO7Z2zKME3krK4aOf7dFBcH9vmcIuN+7XUq31WpoSkdpTuZAYRg0OB0M= X-Gm-Gg: Acq92OFDy8/X90c0hKBZOlO4XeRTHi2i/jbEwqrimsiQGeEc5fqWDbkhl1WAC9VdoRq PzmoiFpMVgMwVgeCGkCeWcsnRHqjU9jSIgfEr0zhvwtWu2pFHMsL2SF/08FEX7iei5Fq4/V/0z+ woajUYpgZSAl5sbUcXgR6EklrKrR2k3ZEoxxZe4eavieNLCxGpaJdzas6m2zn2//XT/RZ+NLFsT YMDxf/AomGvg9dL6M6eC8SHCMJiHB1KfXWn9hnErCh2oju9UCherAqyk1ZzRrRbujNG68WLDMwk fEeMfl6+JcljHGEN8fn5QSA9LaOZKyTOQbXOzDlPigz+8ks2mrEcDky+PAZLEcV4MQilFlk8zmQ yPakME+NSc+zpldeTg9oVu1o2zOp6U+3QIPHDg4RGaQkEFnsvwgVD30/3SqNd9N8GLmhyLX8STO rjS4ug2tzFxgn7Jj/lQjXbgx2wqD2yzMqRR5fl X-Received: by 2002:a05:600c:5306:b0:490:aeae:1eea with SMTP id 5b1f17b1804b1-490aeae1f1cmr83670215e9.7.1780390544683; Tue, 02 Jun 2026 01:55:44 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490aab4f87esm35666535e9.22.2026.06.02.01.55.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2026 01:55:44 -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 v3 11/11] printk: Modify try_enable_default_console() to return error/success Date: Tue, 2 Jun 2026 10:53:12 +0200 Message-ID: <20260602085312.228251-12-pmladek@suse.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260602085312.228251-1-pmladek@suse.com> References: <20260602085312.228251-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" Currently, try_enable_default_console() has a void return type, and its potential failures (specifically when console_call_setup() fails) are ignored by its caller, try_enable_console(). Modify try_enable_default_console() to return error/success, and update try_enable_console() to capture and propagate this error. With this change, try_enable_console() will no longer return success for a pre-enabled console if try_enable_default_console() failed (such as when newcon->setup() fails). While this might change existing behavior, it is the correct approach to ensure setup errors are not silently ignored or treated as successful registrations simply because the console was marked pre-enabled. Assisted-by: Gemini:gemini-3 # commit message 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 d62901a13bf7..61d3c8877737 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -4060,18 +4060,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() \ @@ -4124,7 +4129,9 @@ static int try_enable_console(struct console *newcon) */ 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.54.0