From mboxrd@z Thu Jan 1 00:00:00 1970 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: 8bit 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 console *newcon) newcon->flags |= CON_CONSDEV; } +#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 = try_enable_preferred_console(newcon, true); + if (err != -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_registered) { @@ -4119,9 +4154,6 @@ static u64 get_init_console_seq(struct console *newcon, bool bootcon_registered) return init_seq; } -#define console_first() \ - hlist_entry(console_list.first, struct console, node) - static int unregister_console_locked(struct console *console); /* @@ -4183,31 +4215,7 @@ void register_console(struct console *newcon) goto unlock; } - /* - * 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 = try_enable_preferred_console(newcon, true); - - /* If not, try to match against the platform default(s) */ - if (err == -ENOENT) - err = try_enable_preferred_console(newcon, false); + err = try_enable_console(newcon); /* printk() messages are not printed to the Braille console. */ if (err || newcon->flags & CON_BRL) { -- 2.54.0