From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 5F8D23E6DD0 for ; Thu, 23 Apr 2026 13:01:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776949309; cv=none; b=gYRTklk2BsaVmtwVhDSGHvQvbxw3TvKud5Dp/l0lbJs76SL5Yw6QW29U54nclQQ/y55XnJ0ULe6vsBtoH7DLgu66P0OQ/Ay4rgRAC3BuY+2v5m/36Twt2t8fSWPLmTFmasEZnE/ahC8XHbRDq0cH5AVxDr5h3TwcLPCDXo/UPAo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776949309; c=relaxed/simple; bh=sWEHt4jXjnVtx1hKAGTyEqrt/XaYDLvuDRAPACMvvyA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P/nU7ChRfOm59dg9KrpzaYyF6axeKAZMVNiXkYo/ST7/DHyxzDYLQgg3xzNrZ3HJ+9G7k8azx36q3FzlLIjlKMFpYchesAisWyvHTw5iGXpv8GfDYF9GeNiY7AvZJvqWTxXBH9p0/6AFiFOIveChLA8AsSb1pJ4Nh4Q5ylzmaOY= 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=MjNy/Af4; arc=none smtp.client-ip=209.85.128.48 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="MjNy/Af4" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-488d2079582so77666095e9.2 for ; Thu, 23 Apr 2026 06:01:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1776949307; x=1777554107; 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=RcYfeJ46/SlgH0YRv/BkhmlZvOuSIujY9Aw9ElcLZus=; b=MjNy/Af4Ky2YzNbFf/QyaJxZIWN1W11x7WHIA3YRGyTx0xoVbq01cgbLhyD1DjCTAM gW3UeazerRpfZdEeOcchR3Vc7322tneMPkehDozoskMpTl9RnkeoYGC/6+vGTJyJgHFu ND8YI2QCuR6sBx/PLBqYXltNsWzLfYdse0tct3wsZkyVyX/92l4aTMmbdfTeOzmCY08d 6zHnyzmtO4gR5FH25pAaGHFOvkCP+SKeg/QskCOSe7PbjisG/89tjoiIaQhsE2DO0LS7 GZGSAe4926fkS0M5dK7iJQ4plgXBXEkWObMXy5Sm+C29dcSHEzjgVnaDtD8m7Nd3umvL XJ5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776949307; x=1777554107; 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=RcYfeJ46/SlgH0YRv/BkhmlZvOuSIujY9Aw9ElcLZus=; b=sZaUimYgMms8cfb4DwimH/QqNue55AxO4jFvaR16DkiPP54OYQZhY8OOxbVJ28WetR 03aeiQwVhIs+CA2Avc5bJE5+V+Uy+jmsrN8bMRUEbkXn6Yo3gggky8/5ZwI7y7oNJAVZ OKRmO2J+o49t97CTcCpcglSOZeDU4JkrZU/0llAO7/7xW/y8MKUWSWN9ht6/UsjO6fYM KqVMU2+ZIOd74gk2h2unJFAAKISc7y6En7X7v9nkLno5e4q/pIuNpxcHCTeYoUGn9Jcr huhjhAgTQn2bfR2R5JTMOjRBQ71Ip6+hC10r0IUsO3LxXSZHIJrPgOplEYEdaiq81zzF BDUg== X-Forwarded-Encrypted: i=1; AFNElJ9pqCJnS9NYoLUarm1wWsJzQBnQdqyL/kBl0p5a7iEz2DSwFyne4wMgWPKhEGPFdVYHCN+D16pYil6y2ks=@vger.kernel.org X-Gm-Message-State: AOJu0YyUDFWte1jlfAuAcqc9bxNxaEgugODUNwuYrGsgcEJhkP5F5WUq Ku2oRyTFOeJyHFLA1x5wEnWhlsqwqPClkOmBjaLbQl3fGqY114FI8XoELYzHXf2xOvk= X-Gm-Gg: AeBDieuywpJKubxaxWjVHW7+DeQkQyiZL/HlPdrGtqfv8xZmItRrQ7Ug5o1Aoc1UQNs S3q58UfWRIZEA6w5di2Wu1X6IsgUbZM4eNdLxftaEPkAYrUctbHWjVdhtf3sUP473FXORDzmJXh hP1vRn1PP569UWoEpiNbPIWEmiSgvqN3IspvSOjezU1xtfgCIC1jpjJ+ZyniXCE2T8j3fBxf1KM tWBNMFGhN4Dkeh5WaU+XA9v/OsbiOWZOAGiwz7KgcxYkRIqmim9kdb2o7cyJrHQesUu7hc4Mtc4 tRd4o+wGvPhTDcgQS+RFS3y9QE2rseacjHvUKQILRI7UssILIhmD6fXMQeZ2tlgRyAckQ4J25tK 5cSAqEPtBMLdOMaGMzxxxMHglk3ykjnIvuQaoGuiVWm2CNgAVfeObjln7JcChHgGuR8bQZ14I9o +wGVKkEB6LSFHrelELziAcOIu6WigsTj+5xx+f/B797D8+aeY= X-Received: by 2002:a05:600c:a117:b0:48a:58ae:992f with SMTP id 5b1f17b1804b1-48a58ae9ec5mr97858215e9.16.1776949306523; Thu, 23 Apr 2026 06:01:46 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-488fb74c789sm154931695e9.5.2026.04.23.06.01.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2026 06:01:43 -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 v2 5/9] printk: Separate code for enabling console Date: Thu, 23 Apr 2026 15:00:10 +0200 Message-ID: <20260423130015.85175-6-pmladek@suse.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260423130015.85175-1-pmladek@suse.com> References: <20260423130015.85175-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. The patch does not change the existing behavior. Signed-off-by: Petr Mladek --- 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 7a3bbb0cb794..2543c810efcb 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -4040,6 +4040,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) { @@ -4114,9 +4149,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); /* @@ -4178,31 +4210,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.53.0