From nobody Thu Jun 25 02:18:36 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A7C5C61DA3 for ; Fri, 24 Feb 2023 04:46:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229568AbjBXEqZ (ORCPT ); Thu, 23 Feb 2023 23:46:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229506AbjBXEqW (ORCPT ); Thu, 23 Feb 2023 23:46:22 -0500 X-Greylist: delayed 341 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 23 Feb 2023 20:46:18 PST Received: from mailout2.hostsharing.net (mailout2.hostsharing.net [IPv6:2a01:37:3000::53df:4ee9:0]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B25E351F87 for ; Thu, 23 Feb 2023 20:46:18 -0800 (PST) Received: from h08.hostsharing.net (h08.hostsharing.net [IPv6:2a01:37:1000::53df:5f1c:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "*.hostsharing.net", Issuer "RapidSSL Global TLS RSA4096 SHA256 2022 CA1" (verified OK)) by mailout2.hostsharing.net (Postfix) with ESMTPS id 2C44310189CFC; Fri, 24 Feb 2023 05:40:34 +0100 (CET) Received: from localhost (unknown [89.246.108.87]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by h08.hostsharing.net (Postfix) with ESMTPSA id EA28561CE0A1; Fri, 24 Feb 2023 05:40:33 +0100 (CET) X-Mailbox-Line: From 13e4bdf7677924c689a70d0b7ad970a3255a8d41 Mon Sep 17 00:00:00 2001 Message-Id: <13e4bdf7677924c689a70d0b7ad970a3255a8d41.1677213245.git.lukas@wunner.de> From: Lukas Wunner Date: Fri, 24 Feb 2022 05:40:33 +0100 Subject: [PATCH for-6.4] printk: Unregister boot consoles on register of 1st real console To: Petr Mladek , Sergey Senozhatsky Cc: Steven Rostedt , John Ogness , Lino Sanfilippo , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The code comment preceding register_console() claims that: "There are two types of consoles - bootconsoles (early_printk) and "real" consoles (everything which is not a bootconsole) which are handled differently. [...] As soon as a "real" console is registered, all bootconsoles will be unregistered automatically." But that's not what the code does: The code unregisters bootconsoles only when the *preferred* console registers, i.e. the last one on the command line. If that console's driver never registers (e.g. because it is disabled in the kernel config), bootconsoles stay around indefinitely. Should the command line contain both a bootconsole as well as a real console on the same serial port, all messages are logged twice once the real console registers. Moreover, the log buffer is replayed once the real console registers even though the messages were already emitted by the bootconsole. Amend the code to be congruent with the above-quoted code comment and thereby avoid these issues. Signed-off-by: Lukas Wunner --- kernel/printk/printk.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index fd0c9f913940..f89e865c6b23 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3423,10 +3423,8 @@ void register_console(struct console *newcon) * the real console are the same physical device, it's annoying to * see the beginning boot messages twice */ - if (bootcon_registered && - ((newcon->flags & (CON_CONSDEV | CON_BOOT)) =3D=3D CON_CONSDEV)) { + if (bootcon_registered && !(newcon->flags & CON_BOOT)) newcon->flags &=3D ~CON_PRINTBUFFER; - } =20 newcon->dropped =3D 0; console_init_seq(newcon, bootcon_registered); @@ -3465,8 +3463,7 @@ void register_console(struct console *newcon) * went to the bootconsole (that they do not see on the real console) */ con_printk(KERN_INFO, newcon, "enabled\n"); - if (bootcon_registered && - ((newcon->flags & (CON_CONSDEV | CON_BOOT)) =3D=3D CON_CONSDEV) && + if (bootcon_registered && !(newcon->flags & CON_BOOT) && !keep_bootcon) { struct hlist_node *tmp; =20 --=20 2.39.1