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 2065C340281 for ; Thu, 4 Jun 2026 10:16:34 +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=1780568196; cv=none; b=U1o6NR5LvCdQvbAEezcGGuTrmADyLlXpWaAVDxh+UO1GESwZJnYnApjtLCoryGrWTiS5yfYw7UBhEpjVlg+aa/r+/snljXVxEF4INhHXi0Bm5i/vSzzflraMoxzjaN+tdbPceySuwIaBPUIyoeXTQnUzVVKU1hdrpNEQzlL721U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780568196; c=relaxed/simple; bh=9eKAKnmqq4bemoCUeIXfNnYYJ1xbtuVDOjEW0fafd1g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WZag+rT3VhbsQhgZGU7ugEBy9bn1HvfdNLrAunPsyv7nXAEI9+PZowtEweyxQ5TL9nKySuh7q4evCRBvMeMx0n/k5Pr13sO149d7M/LwLHM7j2ZZLDwSLGg37hCwn0MNf3b3yEa5MgIjpoy/fEqKSiFIElYzdv/7QQ593ftjREQ= 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=S9RHSczs; 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="S9RHSczs" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-45ef82204c6so273750f8f.3 for ; Thu, 04 Jun 2026 03:16:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1780568193; x=1781172993; 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=lDVs3yhv8rBGkNhYqR5Gd5egt2imAA/H5dIoEFCHYyA=; b=S9RHSczsVYBwGPfqqY3bHfKGyerWUtgZ593klHHP0UdA0a9iKluW7FqYtnIEAkDdfD X03Dk1JRXnlJavIo/3RVqdV9sBFIJr64PMwcs7GpN/hjcL9l/EHsANKum4DV7BUZsc04 BxR35qq7zThmQx2TQId6VOjg6XzR5lCXv8PwlvIsmg5peSOByX3EwtrcyxOXdQ9pm+Gq 6JLqIfsyncfN0sOBh3skfUb1QhoRO28lmBE+DbVmShOodE+GDXpvjZiLSIYxjk8nuPk0 soD4S1X3iLG+TYuYsTsZI3xc86+bmkN8A9mpP7dD74ys6XHryAlJ5ITCXp2JpnJ1EjQ4 8ZPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780568193; x=1781172993; 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=lDVs3yhv8rBGkNhYqR5Gd5egt2imAA/H5dIoEFCHYyA=; b=iqLGNhoRSKDZSJvTsfM72VDpTwOr7c/Qtcpcadc+7p/EQbbIsF5svLlAMzfj5GUUd6 R5FNFyAEVfql2fPoiGY0NB0rb41+i+W1T+4+Co4twm1SJKn5TY2BdyelNbQT/k1krMYZ GVL+rPZLOjzCVPyjXh9bI9PTRzn722cx+O9iBSJmUh+6O1w9RbmtIbxI90qfva7CV2Bh 7tMwHT+LR69og/8226z3tjo/CrMfN+ooLts8HMnpJbGJDIkFhDjbgbIW/gDt7R3ym1In LDIOEfETtWaMWb6vPuFHyM9QhLld1QJaq6amnZsC2pQu4qB4Mt60N86HAz4I6EffCYcY KGSQ== X-Forwarded-Encrypted: i=1; AFNElJ/q8C8lvg1s5ey3bYvSN+byZy1hQ1sWIG8ONa1MDtxgAWxbI9B+6m7eoAmDs0kr4MjsXEaD4SYDzcfghTU=@vger.kernel.org X-Gm-Message-State: AOJu0YxgRyRyghaTbQwTwayozDsZSDS/0bLpd9/vs7nULaIbKuSV2PNp patToHQvexdKIX3sGbZFkefYv7avi5UD1wr5IknTdsQrUxkkaRSoZ9+xU05/9ad05rw= X-Gm-Gg: Acq92OGtKsFtXObGqpLvwrBMpb2oPJKBqgnfpfXm78h0U2ei9MqASrpNc80K8yqzsS5 /wdYGBFzHGwvI2Stb9Ijm44zLQobegBYsmYTeG25IWEt668ZVhGL9HMC54nQQUUoPM+IP5Tc7RP LZFs39ksuusnq7TjuizLlpzBKtxJigFS8tNf3Bor1EQpVgn3lZ3oYiLwho4SYOWji7xDo/UHvuB ApKQMSq58Pp6cvKJDH2Mg3y5QFnKg0Zsc6Xzf2ZJoLWO2tSuaHS9AIJWdKerUf40QktjvLDyNaS HBvIYTs2lALPZZIJyjM6N02KNyM8CY3JRDUi9QyvDtCnlV22PBc7FKyCGvxJ25EsTuX/6nv+i3J eEGVBxRAQmmxLLLu0B00K2UzugsLOEP+DltCK4hcNnvrjBGtBQAhpEqyUqQCU3FQWljz9G/hwSR 2bzwPNQBDzxwZem1pVDKf5XKduu7OE5EbNK760 X-Received: by 2002:a05:600c:c163:b0:490:b5d0:598e with SMTP id 5b1f17b1804b1-490b5fe9575mr128624785e9.21.1780568193537; Thu, 04 Jun 2026 03:16:33 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490bc23394asm59738965e9.0.2026.06.04.03.16.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2026 03:16:32 -0700 (PDT) From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Steven Rostedt , Marcos Paulo de Souza , Chris Down , Naveen Kumar Chaudhary , linux-kernel@vger.kernel.org, Petr Mladek Subject: [PATCH v4 07/11] printk: Separate code for enabling console Date: Thu, 4 Jun 2026 12:14:54 +0200 Message-ID: <20260604101459.393162-8-pmladek@suse.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260604101459.393162-1-pmladek@suse.com> References: <20260604101459.393162-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 --- kernel/printk/printk.c | 84 ++++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 36 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 4ee98a4d2ce5..5fb9581804c7 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -4034,6 +4034,53 @@ 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) */ + err = try_enable_preferred_console(newcon, false); + if (err != -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 = 0; + + return err; +} + /* Return the starting sequence number for a newly registered console. */ static u64 get_init_console_seq(struct console *newcon, bool bootcon_registered) { @@ -4108,9 +4155,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); /* @@ -4172,39 +4216,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); - - /* - * 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 (err == -ENOENT && (newcon->flags & CON_ENABLED)) - err = 0; + err = try_enable_console(newcon); /* printk() messages are not printed to the Braille console. */ if (err || newcon->flags & CON_BRL) { -- 2.54.0