From nobody Mon Feb 9 13:01:30 2026 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 60FAC2DC765 for ; Fri, 6 Feb 2026 16:50:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770396635; cv=none; b=Vf1ohktzys4tiJRisybLQL7MT5KME6skXiNSEHmN2cPDAGDIJ9+6SKO70dCMJ0+o5SflWz1MxSE6Pa6qxihzOopX9L61EXYf+yIyNrp7Ewl0iFgKt3kolCXgRjS5EfH+B8D88me3ZnjkKQi67LpIXbgWM/i+v+HszrmdwofR/4g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770396635; c=relaxed/simple; bh=/z5oLpM69iaqyxIg6fwqY7Sfpfl9Xx2jBq7E/j6ElcQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sDh23RtIHMw4f2RCfCCXappM5xqOkaGHHeSY0DBE7eB8gMPIPaeg22RmLtlv7E2SBhhlBz4mV+WUwYVliBHwFOYJNUw7PM8t0NgXtgW5JwspAURjH20O82GJBBCONdXNWEIo93bXFgDVnJiy748V8O4CR3guThS4hjOmZHRWRQg= 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 (1024-bit key) header.d=suse.com header.i=@suse.com header.b=KijH+X/H; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=KijH+X/H; arc=none smtp.client-ip=195.135.223.130 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 (1024-bit key) header.d=suse.com header.i=@suse.com header.b="KijH+X/H"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="KijH+X/H" Received: from pathway.suse.cz (unknown [IPv6:2a07:de40:b2bf:1b::12bd]) by smtp-out1.suse.de (Postfix) with ESMTP id 9239D3E6D1; Fri, 6 Feb 2026 16:50:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1770396633; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pXBz24PwjdfFY7YSepgUit3CJ5sw/1zHtZmuS3TqCAk=; b=KijH+X/HmKIwlHcYp693yQ0qamJImKZZJ9kcLwWQFIy0kyuNV7wm+xHlAp9T2DfvUH/y01 QmWYMaLbyq9rKO1iUUrMe8MTfh/RohsHfydZ2tAdV9/llWAxig6KfzjFau0dkv1hxyVaQ0 GDnEUHieAUL5/8NhH02H2vg+3mpuIOI= Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b="KijH+X/H" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1770396633; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pXBz24PwjdfFY7YSepgUit3CJ5sw/1zHtZmuS3TqCAk=; b=KijH+X/HmKIwlHcYp693yQ0qamJImKZZJ9kcLwWQFIy0kyuNV7wm+xHlAp9T2DfvUH/y01 QmWYMaLbyq9rKO1iUUrMe8MTfh/RohsHfydZ2tAdV9/llWAxig6KfzjFau0dkv1hxyVaQ0 GDnEUHieAUL5/8NhH02H2vg+3mpuIOI= 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 5/8] printk: Try to register each console as Braille first Date: Fri, 6 Feb 2026 17:49:59 +0100 Message-ID: <20260206165002.496724-6-pmladek@suse.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260206165002.496724-1-pmladek@suse.com> References: <20260206165002.496724-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 X-Spamd-Result: default: False [16.18 / 50.00]; SPAM_FLAG(5.00)[]; NEURAL_SPAM_LONG(3.50)[1.000]; BAYES_HAM(-3.00)[100.00%]; NEURAL_SPAM_SHORT(2.99)[0.996]; HFILTER_HOSTNAME_UNKNOWN(2.50)[]; RDNS_NONE(2.00)[]; ONCE_RECEIVED(1.20)[]; MID_CONTAINS_FROM(1.00)[]; HFILTER_HELO_IP_A(1.00)[pathway.suse.cz]; HFILTER_HELO_NORES_A_OR_MX(0.30)[pathway.suse.cz]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; DIRECT_TO_MX(0.00)[git-send-email 2.52.0]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b2bf:1b::12bd:from]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_SEVEN(0.00)[7]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_RATELIMIT(0.00)[to_ip_from(RLgy8oz5x7j7it6a73zx4uugbi)]; RCVD_COUNT_ZERO(0.00)[0]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; DKIM_TRACE(0.00)[suse.com:+]; SPAMHAUS_XBL(0.00)[2a07:de40:b2bf:1b::12bd:from]; DNSWL_BLOCKED(0.00)[2a07:de40:b2bf:1b::12bd:from]; FROM_EQ_ENVFROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[pathway.suse.cz:helo,suse.com:mid,suse.com:dkim,suse.com:email] X-Spam-Flag: YES X-Spamd-Bar: ++++++++++++++++ X-Rspamd-Queue-Id: 9239D3E6D1 X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: add header X-Spam-Level: **************** X-Spam-Score: 16.18 X-Spam: Yes 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. The logic relies on non-obvious shortcuts within both try_enable_preferred_console() and register_console(), making the initialization flow fragile and difficult to follow. Refactor the logic by adding a parameter to try_enable_preferred_console() to explicitly handle Braille vs. non-Braille cases. This removes the need for implicit shortcuts in register_console(). 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. 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, 46 insertions(+), 10 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 4b2865831a62..279b36ef90bd 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -365,6 +365,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 @@ -2554,7 +2555,9 @@ static int update_preferred_console(int i, const char= *name, const short idx, =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 /* @@ -3900,8 +3903,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; @@ -3918,6 +3922,12 @@ static int try_enable_preferred_console(struct conso= le *newcon, newcon->match(newcon, pc->name, pc->index, pc->options) !=3D 0) { /* default matching */ BUILD_BUG_ON(sizeof(pc->name) !=3D sizeof(newcon->name)); + /* + * Two entries might have the same pc->name when one was + * defined via "devname". + */ + if (try_only_braille && !is_braille_console_preferred(pc)) + continue; if (strcmp(pc->name, newcon->name) !=3D 0) continue; if (newcon->index >=3D 0 && @@ -3926,7 +3936,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); @@ -3950,6 +3960,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) { @@ -4103,6 +4124,20 @@ void register_console(struct console *newcon) goto unlock; } =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. + */ + if (want_braille_console) { + err =3D try_enable_braille_console(newcon); + /* Return on success or when con->setup failed. */ + if (err !=3D -ENOENT) + goto unlock_free; + } + /* * See if we want to enable this console driver by default. * @@ -4129,12 +4164,8 @@ void register_console(struct console *newcon) if (err =3D=3D -ENOENT) err =3D try_enable_preferred_console(newcon, false); =20 - /* printk() messages are not printed to the Braille console. */ - if (err || newcon->flags & CON_BRL) { - if (newcon->flags & CON_NBCON) - nbcon_free(newcon); - goto unlock; - } + if (err) + goto unlock_free; =20 /* * If we have a bootconsole, and are switching to a real console, @@ -4227,6 +4258,11 @@ void register_console(struct console *newcon) printk_kthreads_check_locked(); unlock: console_list_unlock(); + return; + +unlock_free: + nbcon_free(newcon); + goto unlock; } EXPORT_SYMBOL(register_console); =20 --=20 2.52.0