From nobody Mon Jun 8 04:15:57 2026 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (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 08E223446B0 for ; Thu, 4 Jun 2026 10:15:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780568126; cv=none; b=StVcs3kKokvi0frEhegB0Pld8J9ERib8BUviZ/aW1/Xlx3eaIteow4sTb66mUSIkysBhNKNUyNVCRhr30YlxsjBIL2FBCgHO39n0z+uhf55aiZN68mvnaaPVs79mXhQ8oTBJqReC4s1jGasQ4iJo/0zGsKToRzGY4fjWdNF2aK0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780568126; c=relaxed/simple; bh=AFQJL6JMPp0g4kRGcKLKCroOqihJySTVnJoz6vGPvNE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VFcj/SGlx+2eXCQ2tvrPga2sBJJesYAnTVa7rTTFx6pRnQ92Yor+c6Y6Kg3kCIXHiwgoCwBQ6yhpRaYW5NaQDByrxtIu/S2mbVme4ntcOfMZn8sBCS5DqIQiKLSUYL3VwQX12psHHQGmfuuQv4aMVUS9GNmyHLm3t5/FkYQAQjw= 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=ArZMYogq; arc=none smtp.client-ip=209.85.128.54 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="ArZMYogq" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-490be03d47bso4054335e9.0 for ; Thu, 04 Jun 2026 03:15:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1780568123; x=1781172923; 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=LK7n+7e/TNvgLbKlTKXmHKU+0NOtPYFviWK45OYGA68=; b=ArZMYogqvEXPp5xBhchp9Dv7gh1lUyre1oX8DRTASHg6A30fb0/BnTk1Uic67BP2TR GHXCC7tokxxplC5sZ9hdNNqctw9U1fW6vaxFmruafV4eiruYYxKNzrMHmiNjhVUWnCsu 5+TAIS2Z6Af3y/v8GsOJVCeZvrSZd2mbfIr4KBsNaxfdxS8g+oleuV9zmhHM+AhZj7xF krTCxbnWaqefRkPtz16AxkMhj2sO6QGqX+kEJPhbVcCQm/8adYbi1V7jgbDswvarPjk3 8uTuohYyMOfVdWT6MQeehY1NyBGuh4Txz72puVDuosuAIIx4ScEEVMVN9WlVbxBRmDAi dsLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780568123; x=1781172923; 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=LK7n+7e/TNvgLbKlTKXmHKU+0NOtPYFviWK45OYGA68=; b=T6J6yFhQZ/epHBZH0z6Y/1HgE+Ml3FFtUnibV/8l+zXZuL5OKMY89aiaI2pknDqNZi HTGSk/qAVSVONYTUZOjPPoXFGpcDKzfTW098g8fUjLsSszj9415F50DykCu7pTxZ1nhw Ed3JTKhIAvJihwxD11lNXUGRba7sx70vCltudultsoQrhMkZEBgYTLh9jFqr6V7jzW0d UAf5r8bhWWYI3qb9P2/G8TMQrVgqDaSzVdxsTIvkre2NECN/OvZOcu+43hvuAhgoYrM3 8kudCKuxTITxDwOpRcPxatO83bpOH1B8n0l0hpWBHPBz49QbatcGSoOTg8llzvqcknAG IEEQ== X-Forwarded-Encrypted: i=1; AFNElJ/hnFmbQiUsxw6Yg91W177IdE+A5sRHBTh/RePMcpSU3ZTr77Cj+9R5FVQ9V5AWaxuB8OsPy+c6bYQZqEE=@vger.kernel.org X-Gm-Message-State: AOJu0YzJodfkJOFPx6wnqD+dv8NCFvpk24wKRhIcF5zvqBSQpfPoTe86 9BHPYg9ydj+1PMkExszkCV5CLibIjcm35oweO1Gyj+LOLcTtP22g7EJOWSWU9KbRC33hTzyhTO/ AP3G2 X-Gm-Gg: Acq92OH3ovz8u4c/Pssh4Dv5iNoTyDhMV9PjWvM3O/ZI19CvXCpaQZSeouXf7LpvsJi MdznHIkAn7dl0n4J9MNCSfMvzhIyKUf4nha72uSpNynm8is1iT2SVnfd+Ay6xWVU36s9VN1D9c+ Yi0TzJFOi+dagh6gwwQC4+8P1T20PieDMxoDZOoxb4WLB6AqSRCu1FbOs3JnhYmRBfEHkVprEoz STqaXolyMbYYYy9Akwhep1kbgkxowe7lZoXO9ZWvg8xrxEfvz6ey1BELXgn6/zOYYG8YznSmGto l+eOraWqsuBPT4TogjAgHHVbe9/03758wvxKP+0VMu2sZdUgDDMjOHPC9xVw+vAh9tkyDhS+Ksp NS2RSRqj65e/a6MHd3UT/aXM8xo0pKWlfgpNKI92U3O+d2dKOnl4N1SQWzEld1pjtRZu/JYZvW9 sc4nO4NIZfd81PzxjkpEcUEuJCh1mVtIbF9I+5 X-Received: by 2002:a05:600c:1c1f:b0:490:be9e:fd03 with SMTP id 5b1f17b1804b1-490be9efee6mr27751535e9.7.1780568123432; Thu, 04 Jun 2026 03:15:23 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490bc39eb04sm63397445e9.6.2026.06.04.03.15.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2026 03:15:22 -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 01/11] printk: Handle pre-enabled consoles in the top-level register_console() Date: Thu, 4 Jun 2026 12:14:48 +0200 Message-ID: <20260604101459.393162-2-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: quoted-printable Content-Type: text/plain; charset="utf-8" The function try_enable_preferred_console() currently has the non-obvious side effect of returning success for consoles that are already pre-enabled. This obscures the logic flow during console registration. Move the check for pre-enabled consoles directly into the top-level register_console(). This change makes the handling of pre-enabled consoles explicit and easier to follow. Furthermore, this separation lays the groundwork for future cleanups where try_enable_preferred_console() can be restricted to cases where an entry actually exists in the console_cmdline[] array. Also it fixes a possible out-of-bound access when the console_cmdline[] array is full and no console matched. In fact, the check of c->user_specified did not make much sense. The new console either matched and was handled in the for-cycle. Or it did not match and then *c pointed to an unused entry. Possible behavior change: try_enable_preferred_console() will newly be called also with @user_specified parameter set to "false" when it failed with the "true" variant. But it looks like the right way to do. It will allow to call newcon->setup() when the console was preferred by some platform specific code. Reported-by: Naveen Kumar Chaudhary # out-of-bound= access Closes: https://lore.kernel.org/r/7sq4tr2nmlz32tvkf6vpsghv6exvqfghsrlvywjcq= ihzsqqbf7@bspclmti5xg4 Signed-off-by: Petr Mladek --- kernel/printk/printk.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 0323149548f6..aa53d57a524b 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3890,9 +3890,6 @@ static int console_call_setup(struct console *newcon,= char *options) * the newly registered console with any of the ones selected * by either the command line or add_preferred_console() and * setup/enable it. - * - * 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) @@ -3933,14 +3930,6 @@ static int try_enable_preferred_console(struct conso= le *newcon, return 0; } =20 - /* - * Some consoles, such as pstore and netconsole, can be enabled even - * without matching. Accept the pre-enabled consoles only when match() - * and setup() had a chance to be called. - */ - if (newcon->flags & CON_ENABLED && c->user_specified =3D=3D user_specifie= d) - return 0; - return -ENOENT; } =20 @@ -4123,6 +4112,14 @@ void register_console(struct console *newcon) if (err =3D=3D -ENOENT) err =3D try_enable_preferred_console(newcon, false); =20 + /* + * 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 =3D=3D -ENOENT && (newcon->flags & CON_ENABLED)) + err =3D 0; + /* printk() messages are not printed to the Braille console. */ if (err || newcon->flags & CON_BRL) { if (newcon->flags & CON_NBCON) --=20 2.54.0 From nobody Mon Jun 8 04:15:57 2026 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 931AE20010A for ; Thu, 4 Jun 2026 10:15:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780568138; cv=none; b=IuUnooAMOI+21DWOSc3Ed4lGS3FE0jfeNtav8L2vdWHTsO+qphCBt9af/DJw48D/PCrGC6Di9+EU0rS4pXRm+mpZTdmNMtC53lM3uPc98ikW8spcKfQWOCqP006kX44Z106IT1yHZo7KUeblaOAY1KL66qDV2NKGkzFGTZyooE0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780568138; c=relaxed/simple; bh=+WorEY/IOf0/D5vGdyDQd3uLXDJwVW0EZ2F9dhr7O3w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WNnMIjXgdOgGANWUOMPsj/M+a8AMisFSmSjUzHwBaaMw1I+CCeLG5V/npkROusVhCc/YYOk6nQW4ZGoVaPO2zc9Ga4xhNhapNMdQeNYSGx2cDsSykTPEn9Lf8wySyoYizK0q1KAHimVwCVx/CyxftPDumsq4PCDzogw0sn3Pqg8= 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=dMqYV2/7; arc=none smtp.client-ip=209.85.128.46 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="dMqYV2/7" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-490b1bbcf3aso4156305e9.1 for ; Thu, 04 Jun 2026 03:15:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1780568135; x=1781172935; 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=rBj1cyuAXhQLBxGyy9ST5XMG0xF2iGQCJJomXoK/dBA=; b=dMqYV2/7Lric0BMCD0Dg5ctEkBNdovvt6Kbb/gyjsN6U+pigAppI0wr4+DGRaHBMU+ VAjGtabz8R3fBWWsq00MhhF6nrfzGFKqdRIN4JfVuoQ9mJgrh2vjdvYqyLXu22O/w94q rkV3V+iEMTM0ewYPcVSi0k29o+GuNDSUQI8gj3hnXVj74an0Dmxh/ydU3Qxr8ciVLbCa jxHebfH51w8RqVVGxF7dEHQVURNLcbMuAMAqbyV2IjiUds/mlKDnGhHF35xaCeMJTynv jnJwYYrWJr5gSEgzuCxgdlcYN7zK2RTAMPfq0xrm3wNA3xBktxRDpoqBjtcHC6jBGYOQ TW1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780568135; x=1781172935; 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=rBj1cyuAXhQLBxGyy9ST5XMG0xF2iGQCJJomXoK/dBA=; b=Mq39A1KnEUVdwq+2LMA6FH/lR3vEKrA0SV/Yg3QC89J6uoao2ww/uncmDcmLJ/H0A6 TrqQ8Ei5rKfbrlrSVOKcDpteMFZCrfHB1AXTz92Tm8bog4wt9BHfpMxfVLZPmD66npyo hGkc0a9SDejRGDqY8KJqCqfVR9HWuhgAg+5kueE3YYi8pptOvKOFIV4PtMqRIYveTEr4 ZKutDSutvpiCFl+P5tDr5S2j2+EyEArgpW1BsuYZGyudAT+/X4CaWsoSc2oBTK/DhdlV o1G1ShsSSCEL9Ka4l6AE72QFA4njWcaLhTw7/2mfQjuEuo5xTzKO5kbVrEx4U6Jce9Wk 55GQ== X-Forwarded-Encrypted: i=1; AFNElJ9L+FZw8wYoN4v7AUSHJiyQUjPnXnNsWaID1hUEI2nHJRz0W4FKDmQcNDAAx7BRYk/MMi8Fv3FWGoPiBdA=@vger.kernel.org X-Gm-Message-State: AOJu0YwhyHPQ79lRzGv5gTDrBSq2iAkaybTUeGwMkojepHzZWfDqxZ4o FfgqHmLQQDGRa4GNztIJVJRaI1W7RJRIRVmddEv+Wv94yQVXzdoGgBwbwSziTnIFmFw= X-Gm-Gg: Acq92OFtVniiH21Aajv+eGNpyo1aTqKBJyo2aOLwAtc4oc+Cy/9i2Z2tC7kcwIcufpn haGjgr4ZisiphDCnknDr13n6ZYND7epoXOwIpW5QefvpJ/GRSX8MHnl654OREMS6kUggdAYXRBj 414Y8Q8wLzJ2/f6A5korSiXgA9NX3yBkAWL1YJyxcUyGyyTQmuz5kf64B9G4tAeAsjufBoIAXK5 itdhwxyayWVmG3rVY0loTfeP9LF8WQd+LiGjab1Sm/gJ6J0srQnW0p5qaZr7dSo9OMyALXTsrzj 9iLPQNlYJPXhSssCsYVNhVICJWEltIrsSi3LyWjs5eS/RKOEtp+yrNZZ3TJplcUUlYJ5ZilE1Ug +XpWecm+uWDQy2Vmzwztygup/0409kmlNGnWjJIx+SdWF7CXP/+sX8TzVVgMblRwZGWtLD2oRFR I/hcor5suwIi6ZFdDh/jmhtR71fBCyv95yFS5j X-Received: by 2002:a05:600c:5288:b0:490:5191:6e26 with SMTP id 5b1f17b1804b1-490b5ecbd41mr116250245e9.18.1780568134839; Thu, 04 Jun 2026 03:15:34 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490bc3cc140sm72381395e9.9.2026.06.04.03.15.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2026 03:15:34 -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 02/11] printk: Rename struct console_cmdline to preferred_console Date: Thu, 4 Jun 2026 12:14:49 +0200 Message-ID: <20260604101459.393162-3-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: quoted-printable Content-Type: text/plain; charset="utf-8" The structure 'console_cmdline' was originally intended to store details about consoles defined on the kernel command line. However, its usage has since expanded; it now stores information for consoles preferred via SPCR, device tree, or by particular platforms, e.g. XEN. The current naming is misleading as it implies the configuration only originates from the command line. Rename the structure and associated artifacts to better reflect their current purpose, for example: - struct console_cmdline c -> struct preferred_console pc - console_cmdline[] -> preferred_consoles[] - console_cmdline.h -> console_register.h - c -> pc Additionally, renaming the header file to console_register.h would eventually allow to decouple console registration logic from the monolithic printk.c. Finally, renaming the local variable from "c" to "pc" helps to distinguish it from struct console variables. Note that "c" is used for struct console in some code, for example see vt_console_device() function definition. No functional changes. Signed-off-by: Petr Mladek Acked-by: Chris Down Acked-by: Marcos Paulo de Souza Reviewed-by: John Ogness --- kernel/printk/braille.c | 10 +-- kernel/printk/braille.h | 10 +-- .../{console_cmdline.h =3D> console_register.h} | 6 +- kernel/printk/printk.c | 85 ++++++++++--------- 4 files changed, 57 insertions(+), 54 deletions(-) rename kernel/printk/{console_cmdline.h =3D> console_register.h} (83%) diff --git a/kernel/printk/braille.c b/kernel/printk/braille.c index 17a9591e54ff..9d21a2bb1d38 100644 --- a/kernel/printk/braille.c +++ b/kernel/printk/braille.c @@ -6,7 +6,7 @@ #include #include =20 -#include "console_cmdline.h" +#include "console_register.h" #include "braille.h" =20 int _braille_console_setup(char **str, char **brl_options) @@ -35,14 +35,14 @@ int _braille_console_setup(char **str, char **brl_optio= ns) } =20 int -_braille_register_console(struct console *console, struct console_cmdline = *c) +_braille_register_console(struct console *console, struct preferred_consol= e *pc) { int rtn =3D 0; =20 - if (c->brl_options) { + if (pc->brl_options) { console->flags |=3D CON_BRL; - rtn =3D braille_register_console(console, c->index, c->options, - c->brl_options); + rtn =3D braille_register_console(console, pc->index, pc->options, + pc->brl_options); } =20 return rtn; diff --git a/kernel/printk/braille.h b/kernel/printk/braille.h index 123154f86304..55cd3178a17a 100644 --- a/kernel/printk/braille.h +++ b/kernel/printk/braille.h @@ -5,9 +5,9 @@ #ifdef CONFIG_A11Y_BRAILLE_CONSOLE =20 static inline void -braille_set_options(struct console_cmdline *c, char *brl_options) +braille_set_options(struct preferred_console *pc, char *brl_options) { - c->brl_options =3D brl_options; + pc->brl_options =3D brl_options; } =20 /* @@ -21,7 +21,7 @@ int _braille_console_setup(char **str, char **brl_options); =20 int -_braille_register_console(struct console *console, struct console_cmdline = *c); +_braille_register_console(struct console *console, struct preferred_consol= e *pc); =20 int _braille_unregister_console(struct console *console); @@ -29,7 +29,7 @@ _braille_unregister_console(struct console *console); #else =20 static inline void -braille_set_options(struct console_cmdline *c, char *brl_options) +braille_set_options(struct preferred_console *pc, char *brl_options) { } =20 @@ -40,7 +40,7 @@ _braille_console_setup(char **str, char **brl_options) } =20 static inline int -_braille_register_console(struct console *console, struct console_cmdline = *c) +_braille_register_console(struct console *console, struct preferred_consol= e *pc) { return 0; } diff --git a/kernel/printk/console_cmdline.h b/kernel/printk/console_regist= er.h similarity index 83% rename from kernel/printk/console_cmdline.h rename to kernel/printk/console_register.h index 0ab573b6d4dc..9ab3e1cc749b 100644 --- a/kernel/printk/console_cmdline.h +++ b/kernel/printk/console_register.h @@ -1,8 +1,8 @@ /* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _CONSOLE_CMDLINE_H -#define _CONSOLE_CMDLINE_H +#ifndef _CONSOLE_REGISTER_H +#define _CONSOLE_REGISTER_H =20 -struct console_cmdline +struct preferred_console { char name[16]; /* Name of the driver */ int index; /* Minor dev. to use */ diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index aa53d57a524b..0099e46a223b 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -58,7 +58,7 @@ #include =20 #include "printk_ringbuffer.h" -#include "console_cmdline.h" +#include "console_register.h" #include "braille.h" #include "internal.h" =20 @@ -362,9 +362,9 @@ static int console_locked; * Array of consoles built from command line options (console=3D) */ =20 -#define MAX_CMDLINECONSOLES 8 +#define MAX_PREFERRED_CONSOLES 8 =20 -static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES]; +static struct preferred_console preferred_consoles[MAX_PREFERRED_CONSOLES]; =20 static int preferred_console =3D -1; int console_set_on_cmdline; @@ -2544,16 +2544,16 @@ asmlinkage __visible void early_printk(const char *= fmt, ...) } #endif =20 -static void set_user_specified(struct console_cmdline *c, bool user_specif= ied) +static void set_user_specified(struct preferred_console *pc, bool user_spe= cified) { if (!user_specified) return; =20 /* - * @c console was defined by the user on the command line. + * @pc console was defined by the user on the command line. * Do not clear when added twice also by SPCR or the device tree. */ - c->user_specified =3D true; + pc->user_specified =3D true; /* At least one console defined by the user on the command line. */ console_set_on_cmdline =3D 1; } @@ -2562,7 +2562,7 @@ static int __add_preferred_console(const char *name, = const short idx, const char *devname, char *options, char *brl_options, bool user_specified) { - struct console_cmdline *c; + struct preferred_console *pc; int i; =20 if (!name && !devname) @@ -2581,30 +2581,30 @@ static int __add_preferred_console(const char *name= , const short idx, * See if this tty is not yet registered, and * if we have a slot free. */ - for (i =3D 0, c =3D console_cmdline; - i < MAX_CMDLINECONSOLES && (c->name[0] || c->devname[0]); - i++, c++) { - if ((name && strcmp(c->name, name) =3D=3D 0 && c->index =3D=3D idx) || - (devname && strcmp(c->devname, devname) =3D=3D 0)) { + for (i =3D 0, pc =3D preferred_consoles; + i < MAX_PREFERRED_CONSOLES && (pc->name[0] || pc->devname[0]); + i++, pc++) { + if ((name && strcmp(pc->name, name) =3D=3D 0 && pc->index =3D=3D idx) || + (devname && strcmp(pc->devname, devname) =3D=3D 0)) { if (!brl_options) preferred_console =3D i; - set_user_specified(c, user_specified); + set_user_specified(pc, user_specified); return 0; } } - if (i =3D=3D MAX_CMDLINECONSOLES) + if (i =3D=3D MAX_PREFERRED_CONSOLES) return -E2BIG; if (!brl_options) preferred_console =3D i; if (name) - strscpy(c->name, name); + strscpy(pc->name, name); if (devname) - strscpy(c->devname, devname); - c->options =3D options; - set_user_specified(c, user_specified); - braille_set_options(c, brl_options); + strscpy(pc->devname, devname); + pc->options =3D options; + set_user_specified(pc, user_specified); + braille_set_options(pc, brl_options); =20 - c->index =3D idx; + pc->index =3D idx; return 0; } =20 @@ -2624,8 +2624,7 @@ __setup("console_msg_format=3D", console_msg_format_s= etup); */ static int __init console_setup(char *str) { - static_assert(sizeof(console_cmdline[0].devname) >=3D sizeof(console_cmdl= ine[0].name) + 4); - char buf[sizeof(console_cmdline[0].devname)]; + char buf[sizeof(preferred_consoles[0].devname)]; char *brl_options =3D NULL; char *ttyname =3D NULL; char *devname =3D NULL; @@ -2633,6 +2632,10 @@ static int __init console_setup(char *str) char *s; int idx; =20 + static_assert(sizeof(preferred_consoles[0].devname) >=3D + sizeof(preferred_consoles[0].name) + 4); + + /* * console=3D"" or console=3Dnull have been suggested as a way to * disable console output. Use ttynull that has been created @@ -2730,19 +2733,19 @@ int match_devname_and_update_preferred_console(cons= t char *devname, const char *name, const short idx) { - struct console_cmdline *c =3D console_cmdline; + struct preferred_console *pc =3D preferred_consoles; int i; =20 if (!devname || !strlen(devname) || !name || !strlen(name) || idx < 0) return -EINVAL; =20 - for (i =3D 0; i < MAX_CMDLINECONSOLES && (c->name[0] || c->devname[0]); - i++, c++) { - if (!strcmp(devname, c->devname)) { + for (i =3D 0; i < MAX_PREFERRED_CONSOLES && (pc->name[0] || pc->devname[0= ]); + i++, pc++) { + if (!strcmp(devname, pc->devname)) { pr_info("associate the preferred console \"%s\" with \"%s%d\"\n", devname, name, idx); - strscpy(c->name, name); - c->index =3D idx; + strscpy(pc->name, name); + pc->index =3D idx; return 0; } } @@ -3894,33 +3897,33 @@ static int console_call_setup(struct console *newco= n, char *options) static int try_enable_preferred_console(struct console *newcon, bool user_specified) { - struct console_cmdline *c; + struct preferred_console *pc; int i, err; =20 - for (i =3D 0, c =3D console_cmdline; - i < MAX_CMDLINECONSOLES && (c->name[0] || c->devname[0]); - i++, c++) { + for (i =3D 0, pc =3D preferred_consoles; + i < MAX_PREFERRED_CONSOLES && (pc->name[0] || pc->devname[0]); + i++, pc++) { /* Console not yet initialized? */ - if (!c->name[0]) + if (!pc->name[0]) continue; - if (c->user_specified !=3D user_specified) + if (pc->user_specified !=3D user_specified) continue; if (!newcon->match || - newcon->match(newcon, c->name, c->index, c->options) !=3D 0) { + newcon->match(newcon, pc->name, pc->index, pc->options) !=3D 0) { /* default matching */ - BUILD_BUG_ON(sizeof(c->name) !=3D sizeof(newcon->name)); - if (strcmp(c->name, newcon->name) !=3D 0) + BUILD_BUG_ON(sizeof(pc->name) !=3D sizeof(newcon->name)); + if (strcmp(pc->name, newcon->name) !=3D 0) continue; if (newcon->index >=3D 0 && - newcon->index !=3D c->index) + newcon->index !=3D pc->index) continue; if (newcon->index < 0) - newcon->index =3D c->index; + newcon->index =3D pc->index; =20 - if (_braille_register_console(newcon, c)) + if (_braille_register_console(newcon, pc)) return 0; =20 - err =3D console_call_setup(newcon, c->options); + err =3D console_call_setup(newcon, pc->options); if (err) return err; } --=20 2.54.0 From nobody Mon Jun 8 04:15:57 2026 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (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 C5D631A9F9F for ; Thu, 4 Jun 2026 10:15:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780568149; cv=none; b=YrwVzXxb7nBL5NqcKaXxbetIB0L7rppSUw3fEC5B+pSTfc8I5JKgU6hPyNWnoFbixAKihkaZ05HXK9gfLeDIrMlE9WjX8f9TSVUhF7ru7T7vjEWpOmlZAIUIl1fQbNLa40KDL+cXg3/vt4Hug0DTSl8Jgd8Dt7+DlNOl0qL+rfo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780568149; c=relaxed/simple; bh=PKx+4p2oo7yw9KtyV9BniWGNJqsloScBjEKE1xOhTSo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CiabF0k4EijiPO5+0Hfiz/2kNlVNmGXWSPq7aCXJdi57mxnFFJmY+CR4SEmxvT9qP+WVRp3T5P0Ym52HEF54lnY0LUMqHpmpZJDrEOOLL0IdJaYX789iEQLA/UTSaP0fD2nOsz05UAi1Jtmbt30XNCfi+CPbkZ/Kqn+JbucTgpk= 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=RiwVerEE; arc=none smtp.client-ip=209.85.221.51 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="RiwVerEE" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-45f3cf907ceso250838f8f.2 for ; Thu, 04 Jun 2026 03:15:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1780568146; x=1781172946; 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=Jqnkdv7gOOQHjNT4TjbRQTMZUJtL1maCS95fBdLSvUE=; b=RiwVerEEja1X4gWdvtmUVlJWetJ7RpoxKPnXLmXvNuT9Ef7o/HlH1IWzBVIaFjNhn8 G7NleYuHkaD8s9KmJIKm7ZiuMsSlyDpqHmy2YYPi+WGa16axeW1bj3zJmEW7t2K3etpZ 28TbIICHk2u3jB70weWZ4mWD9xIKTYaiHVMWwYwAl8ncZ/PSik1oU+zeUpTtFQYZ7Z/4 e2euXqCQtWAJmZs+yHIeG33jMqYJPuwc7Yi3DN5ObZ1fYc4Q66UsD+kTdYNl7mYoV26x cOvNdTHyQKKkWIKsXNJREKt26vGDjNd3jTvrBXbHJ+MhWPFE6+4TNVMwgXRf0ZX7w7NJ hAWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780568146; x=1781172946; 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=Jqnkdv7gOOQHjNT4TjbRQTMZUJtL1maCS95fBdLSvUE=; b=q0c3zDK7gdrcbbPFsFyO9uOMP0ZtVmo4Q854iwAMnz8wUHDCU9/MPZ9m1Lai3utJKs 2OdHFJWmmM+EYB24Tbo3xpklSJBJd01kKvXEwX1GV5xFD37pyaXnzqVdEKu835yDdw7t 9WxVHBFIHPeggqtuNqc05yBez/5R0ZIMJPGf/wIQVXvsGNQu8dfu0R3zfRr1NuTBF1dh OuaXUD0NcT8XPNsiJos9kGoKK1ffSnpJtL9+7S+/ofyhLzvcIrgn4QAzmQN1BjugSTPI VEaMDJPwMkQzAuFbiXRQ6+yVT/cRRyLEUnhHnwvtvXMzgqHiWr19RngzpgyNB+1oTuAa 8iUg== X-Forwarded-Encrypted: i=1; AFNElJ8aufhIz+kxgmPkBdZQhiV9rlXMWCla9fCsLo+qLGWeKyFc0QTOxRRKJ2Q09vsd0i5VdAmkjN0pxf5Fauk=@vger.kernel.org X-Gm-Message-State: AOJu0Yxcs0tuv3NBWruRqMYsbQsBWIz7dVdghIov/GGEzUf2f0y/kfYc zaD9cnA7WqAu0EYBIuL6Le2LFDeXFmZgwSsr5qAWEDfHFPOJWwJcYJcP/xQKYJTjhro= X-Gm-Gg: Acq92OHiZ7uPLJofq40S51ulfxrwk1/+cnsqfK8n7pI6XDciHMgluxHooXmpKUpYdye Ui2LAcq5akE7VjOrIN2lEack2okEKGoAEoE1UZ0obXTl3EU/ULjPWC6AjW9QI6AdLwy/56NKSv5 XLDi3YvPu8sgU+bZr40Ph6/8a6scytrLiamPwFUYHvIDDRakRJeOb/o6EUIIx0E0N7sElPVAVFh ZdsxmjFaqahUMeg2cC7uXg0ntkc2vF9w9Rx3/xGqalz0xqQ14n4OmK3VJH/G7CPUfe/bFhapdpz Hcx1lDpJEODVsjzE4bO1BSp47RAJ64KxL0hQG3uJ52CJAXTx6WBseVKRGy71r6dYJuUdUZqq14r qVS88S8B0MHjBxRgfBwoTflq1m4Nlyfc4MEg+zyu2EY+J/bZZlJ1pALqXT3/7Q0aqy6uVLfT6yq xAyaLH4eD728321nZt1qJNr7vTxqjijRNC47jP X-Received: by 2002:a05:600c:5394:b0:490:b0e0:3de2 with SMTP id 5b1f17b1804b1-490b60f9e98mr120597835e9.33.1780568146175; Thu, 04 Jun 2026 03:15:46 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490bc23394asm59694355e9.0.2026.06.04.03.15.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2026 03:15:45 -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 03/11] printk: Rename preferred_console to preferred_dev_console Date: Thu, 4 Jun 2026 12:14:50 +0200 Message-ID: <20260604101459.393162-4-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: quoted-printable Content-Type: text/plain; charset="utf-8" The preferred_consoles[] array stores information about consoles requested via the command line, SPCR, Device Tree, or platform-specific code. Within this array, the 'preferred_console' variable tracks the specific index that should be associated with /dev/console (typically the last non-braille console defined). The current name "preferred_console" is ambiguous and leads to confusion. It does not clearly communicate why one console is "more preferred" than others in the array. Furthermore, entries for Braille consoles can exist within the preferred_consoles[] array, yet they are never associated with /dev/console and do not receive standard printk() output. Consequently, the 'preferred_console' index must skip these entries, which is not immediately obvious from the name. Rename the variable to 'preferred_dev_console' to explicitly clarify its role in identifying which entry is linked to /dev/console. No behavior change. Signed-off-by: Petr Mladek Acked-by: Chris Down Acked-by: Marcos Paulo de Souza Reviewed-by: John Ogness --- kernel/printk/printk.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 0099e46a223b..e162e8836683 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -366,7 +366,7 @@ static int console_locked; =20 static struct preferred_console preferred_consoles[MAX_PREFERRED_CONSOLES]; =20 -static int preferred_console =3D -1; +static int preferred_dev_console =3D -1; int console_set_on_cmdline; EXPORT_SYMBOL(console_set_on_cmdline); =20 @@ -2587,7 +2587,7 @@ static int __add_preferred_console(const char *name, = const short idx, if ((name && strcmp(pc->name, name) =3D=3D 0 && pc->index =3D=3D idx) || (devname && strcmp(pc->devname, devname) =3D=3D 0)) { if (!brl_options) - preferred_console =3D i; + preferred_dev_console =3D i; set_user_specified(pc, user_specified); return 0; } @@ -2595,7 +2595,7 @@ static int __add_preferred_console(const char *name, = const short idx, if (i =3D=3D MAX_PREFERRED_CONSOLES) return -E2BIG; if (!brl_options) - preferred_console =3D i; + preferred_dev_console =3D i; if (name) strscpy(pc->name, name); if (devname) @@ -3928,7 +3928,7 @@ static int try_enable_preferred_console(struct consol= e *newcon, return err; } newcon->flags |=3D CON_ENABLED; - if (i =3D=3D preferred_console) + if (i =3D=3D preferred_dev_console) newcon->flags |=3D CON_CONSDEV; return 0; } @@ -4101,7 +4101,7 @@ void register_console(struct console *newcon) * Note that a console with tty binding will have CON_CONSDEV * flag set and will be first in the list. */ - if (preferred_console < 0) { + if (preferred_dev_console < 0) { if (hlist_empty(&console_list) || !console_first()->device || console_first()->flags & CON_BOOT) { try_enable_default_console(newcon); --=20 2.54.0 From nobody Mon Jun 8 04:15:57 2026 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 6D1BE202963 for ; Thu, 4 Jun 2026 10:15:59 +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=1780568161; cv=none; b=I8GN/jVpCVJUWHvtXmBLG3PyKb9P4ZAVRpUoZ1KES7vR3637Gw6d7s6ttiwEtTaLgOqKIJeUW4RYkI41q3rCJUk9JiAvGR2qmyy7OlDFo+r1i7lmYDZX0OgkxNGP2OBmaxt9eNpPtgSMsVZ9kJPDJVU0fdMBcBJun5WOEz2eK+Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780568161; c=relaxed/simple; bh=u0r2/NOEJXm5YiZGZN67/Pj5cyou6Ya5Uo8MlDCjWtc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Cb+1vv+hXWQsrDaXHLEG0JSwhB/HYsQ5hh96aREeoOy0iUGMAZfveYVH9IyRk7qSb9kKg5esUf1MdNGMv8rkhAhcSxkOFyJN5Oi4YVQf4TVYVTTsEqmlY/HyzRdkVxtCJQ/2u2bPV7mF3HvHd28pGBhKptYClB/u5hgjXZzQGkQ= 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=BnwNuLN4; 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="BnwNuLN4" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-46019edc13dso253387f8f.1 for ; Thu, 04 Jun 2026 03:15:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1780568158; x=1781172958; 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=AQVYOmOVM1Z0u9gQ0UIAJfJqJI6MAk0H44mTuTI8sK4=; b=BnwNuLN4rdDQC4H9CdOL9ThtXn/n6K0/3Gx0HiB2L73n3KW9yh/2j5DIfpS7u3FtbB Dbe7KqWAmZ+aWngIsSQuyTA8Yllm2YgBltiLPaFsDQIcW1fCX5xpnD3oyBVxeqQ3HE0G Pj/aGZ4/Cf2fALN9m9rA5+QfkHRjvP4PgcmokT+sPhmsCc3jPIU9h97bDTnornp+MKm/ 13WSZlpukSyC52fUuI832PMEvZfKI9F9/bPCyLmJrAcvT8o3W2xbSrQnclEHNlKgbHln aS8kXy5K+nn7IyshzL1uh5Rs6lZfGNcsfe0kuc3ibVAcNxpI9MuD2k5HTmVX/oF+TI0k QUOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780568158; x=1781172958; 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=AQVYOmOVM1Z0u9gQ0UIAJfJqJI6MAk0H44mTuTI8sK4=; b=JLkZGWm5DFzdof88Z8esTIIvooAmc8xxpwuvpxereoqCp8mAe8UeK0vEuDCPOEcb+l VJ8dkxSE4Kl1EJimzkGeT8LPkumph66T/ZfyypjhSnui3LBV53ePIrVCWPF+esYXGGQf wD/xaRIZvzI75kbMoiIzVzL+/MmtPKZZHMPUNI+Zs8T2z8YqeOyAP0ueka9XecUcFPkb j9NGpJHCq1WfqLg7DUV1uW+x4NI8VOl2tLCrFvU6A/NterdAqUyd5SeUWwmWXBoMe6JQ fVEmDoSsck5RwlvNjSKpdHWvGRRLSx6P5MDdakueuc99MM2i6n/8tKba5vt2kxECDyE3 IspA== X-Forwarded-Encrypted: i=1; AFNElJ+Jh4xQzLKfpOQc2x7S36b2K4ox2MYYJa0AQ3oqo6QYlwSf5j4sllZNSjTXYI31w1mfcvMbQUbBXBfXFzk=@vger.kernel.org X-Gm-Message-State: AOJu0Yw43RrUIucfu9MkuMObUUJzsiyB8udrzOlho/VfH+tGQ7RNYTIC 1KRlvK20Zq0jK19coRYPH1yofq7EdPwseS3YBC2vTeGbv3nibBDulrrPlXDX75ts6is= X-Gm-Gg: Acq92OH+4uaD0D+D1ZN8UNci3kYs9onUEZozsXWbVekp5Mh6QztwKJbExUz5Ujwyivi gxd4YN+75KgJAqqtdTe686NBmi+YPpWeC5+MHfcFvPbLdrxOzJpbPhMuvWjXYPl96fCme4iaksR Y7d5uwW9sdZ5aoe0S7+s3sNHAhNajqxZeQR68PPLNanTczaNfl6kJ98sMl8p856vaaTDf61G/vq 5IRKRvkrNxzH9N0mzkTxOSMVbw+3avo+5SnKXaqxmDqSfo83whSZoFE+PKmqQX+qOw8DJ9T37Z8 MAeLl5T1yukL9dnX4K12x1sZi79oZv0nl0simk9zqP9Hwk+wya17zMx1GtUWMoPZzYIUc3NEatJ 98PoB2JxCCPVa8vXDZub99VZVsfbhTaPHlHar8fzs0mxX/W3v3FD75t8bJikUS44/gLlSZ5I+yY cgDD0sX+ksE1QFVpq7D388ZAQqWpNwP41FEaeT X-Received: by 2002:a05:6000:2401:b0:43b:5097:6f62 with SMTP id ffacd0b85a97d-46021760f85mr11617971f8f.36.1780568157787; Thu, 04 Jun 2026 03:15:57 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f2e4004sm15200176f8f.9.2026.06.04.03.15.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2026 03:15:57 -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 04/11] printk: Separate code for adding/updating preferred console metadata Date: Thu, 4 Jun 2026 12:14:51 +0200 Message-ID: <20260604101459.393162-5-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: quoted-printable Content-Type: text/plain; charset="utf-8" The logic for adding or updating a preferred console is currently duplicated within __add_preferred_console(), making the code difficult to follow and prone to consistency issues. Introduce update_preferred_console() to centralize the initialization and updating of struct preferred_console entries. This refactoring explicitly defines and enforces the following rules: 1. Console names and/or indexes are not set when a console is preferred via devname; these are resolved later during device matching. 2. Console names are only added alongside a valid index. 3. Only matching entries are updated. 4. Console and Braille options are never cleared. They are updated only via the command line. 5. The global 'preferred_dev_console' index and 'console_set_on_cmdline' flag are updated consistently. Additionally, rename braille_set_options() to braille_update_options() to better reflect its conditional behavior. Behavior change: The original code never updated the preferred console options when it was preferred more times, e.g. via the command line and/or some platform specific code, e.g. SPCR or device tree. The new code explicitly allows to update the console options when they are preferred over the command line. It mostly worked even before but only because the command line was processed early enough before handling SPCR, device tree, or other platform specific init code. The main behavior change is when the same console is preferred more times on the command line. Newly, the later or Braille variant wins. It is a more common and expected behavior. Signed-off-by: Petr Mladek --- kernel/printk/braille.h | 7 +- kernel/printk/printk.c | 153 +++++++++++++++++++++++++++++++--------- 2 files changed, 122 insertions(+), 38 deletions(-) diff --git a/kernel/printk/braille.h b/kernel/printk/braille.h index 55cd3178a17a..0bdac303f8b1 100644 --- a/kernel/printk/braille.h +++ b/kernel/printk/braille.h @@ -5,9 +5,10 @@ #ifdef CONFIG_A11Y_BRAILLE_CONSOLE =20 static inline void -braille_set_options(struct preferred_console *pc, char *brl_options) +braille_update_options(struct preferred_console *pc, char *brl_options) { - pc->brl_options =3D brl_options; + if (brl_options) + pc->brl_options =3D brl_options; } =20 /* @@ -29,7 +30,7 @@ _braille_unregister_console(struct console *console); #else =20 static inline void -braille_set_options(struct preferred_console *pc, char *brl_options) +braille_update_options(struct preferred_console *pc, char *brl_options) { } =20 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index e162e8836683..b7dbbc1baeb1 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2544,18 +2544,123 @@ asmlinkage __visible void early_printk(const char = *fmt, ...) } #endif =20 -static void set_user_specified(struct preferred_console *pc, bool user_spe= cified) +/** add_or_update_preferred_console - Add or update a given entry in + * the preferred_consoles[] table. + * @i: index of the entry in @preferred_consoles table which should get up= dated. + * @name: The name of the preferred console driver. + * @idx: Preferred console index, e.g. port number. + * @devname: The name of the preferred physical device. + * @options: Options used when setting up the console driver. + * @brl_options: Options used when setting up the console driver + * as a braille console. + * @user_specified: True if preferred via the kernel command line. + * + * The function ensures that the given values are consistent. Also + * it updates some global variables which are used to make the right + * decisions in register_console(). + * + * Rules: + * + * 1. Either @name and valid @idx OR @devname and @idx=3D-1 are allowed. + * Note that a valid @name and @idx will get assigned later when + * @devname matches during the device initialization. + * 2. Specify @brl_options if the console should be enabled as + * a Braille console [*] + * 3. Only matching entries can be updated. + * 4. @options passed via the command line are used when the same + * console is preferred also by some platform-specific code. + * + * [*] Braille console is using the mechanism for registering consoles + * but it is very special. It is primarily used for user interaction + * with the system. It neither gets printk() messages nor is associated + * with /dev/console. + */ +static int add_or_update_preferred_console(unsigned int i, + const char *name, const short idx, + const char *devname, char *options, + char *brl_options, bool user_specified) { - if (!user_specified) - return; + struct preferred_console *pc; + + if (i >=3D MAX_PREFERRED_CONSOLES) { + pr_err_once("Reached maximal number of preferred consoles.\n"); + return -E2BIG; + } + + pc =3D &preferred_consoles[i]; + + if (WARN_ON(!name && !devname)) + return -EINVAL; + + if (devname) { + /* + * A valid console name and index will get assigned when + * a matching device gets registered. + */ + if (name) { + pr_err("Adding a preferred console devname with a hard-coded console na= me: %s, %s\n", + devname, name); + return -EINVAL; + } + if (pc->name[0]) { + pr_err("Updating a preferred console entry with an already assigned con= sole name via devname: %s, %s\n", + devname, pc->name); + return -EINVAL; + } + if (idx !=3D -1) { + pr_err("Adding a preferred console devname with a hard-coded index: %s,= %d\n", + devname, idx); + return -EINVAL; + } + + if (!pc->devname[0]) { + /* This is a new entry. */ + strscpy(pc->devname, devname); + pc->index =3D idx; + } else if (strcmp(pc->devname, devname) !=3D 0) { + pr_err("Updating a preferred console with an invalid devname: %s vs. %s= \n", + pc->devname, devname); + return -EINVAL; + } + } + + if (name) { + /* A console name must be defined with a valid index. */ + if (idx < 0) { + pr_err("Adding a preferred console with an invalid index: %s, %d\n", + name, idx); + return -EINVAL; + } + + if (!pc->name[0]) { + /* This is a new entry. */ + strscpy(pc->name, name); + pc->index =3D idx; + } else if (strcmp(pc->name, name) !=3D 0 || pc->index !=3D idx) { + pr_err("Updating a preferred console with an invalid name or index: %s%= d vs. %s%d\n", + pc->name, pc->index, name, idx); + return -EINVAL; + } + } + + if (!pc->options || (user_specified && options)) + pc->options =3D options; + + braille_update_options(pc, brl_options); + + if (!brl_options) + preferred_dev_console =3D i; =20 /* * @pc console was defined by the user on the command line. * Do not clear when added twice also by SPCR or the device tree. */ - pc->user_specified =3D true; - /* At least one console defined by the user on the command line. */ - console_set_on_cmdline =3D 1; + if (user_specified) { + pc->user_specified =3D true; + console_set_on_cmdline =3D 1; + } + + return 0; } =20 static int __add_preferred_console(const char *name, const short idx, @@ -2563,19 +2668,11 @@ static int __add_preferred_console(const char *name= , const short idx, char *brl_options, bool user_specified) { struct preferred_console *pc; - int i; + unsigned int i; =20 if (!name && !devname) return -EINVAL; =20 - /* - * We use a signed short index for struct console for device drivers to - * indicate a not yet assigned index or port. However, a negative index - * value is not valid when the console name and index are defined on - * the command line. - */ - if (name && idx < 0) - return -EINVAL; =20 /* * See if this tty is not yet registered, and @@ -2584,28 +2681,14 @@ static int __add_preferred_console(const char *name= , const short idx, for (i =3D 0, pc =3D preferred_consoles; i < MAX_PREFERRED_CONSOLES && (pc->name[0] || pc->devname[0]); i++, pc++) { - if ((name && strcmp(pc->name, name) =3D=3D 0 && pc->index =3D=3D idx) || - (devname && strcmp(pc->devname, devname) =3D=3D 0)) { - if (!brl_options) - preferred_dev_console =3D i; - set_user_specified(pc, user_specified); - return 0; - } + if (name && strcmp(pc->name, name) =3D=3D 0 && pc->index =3D=3D idx) + break; + if (devname && strcmp(pc->devname, devname) =3D=3D 0) + break; } - if (i =3D=3D MAX_PREFERRED_CONSOLES) - return -E2BIG; - if (!brl_options) - preferred_dev_console =3D i; - if (name) - strscpy(pc->name, name); - if (devname) - strscpy(pc->devname, devname); - pc->options =3D options; - set_user_specified(pc, user_specified); - braille_set_options(pc, brl_options); =20 - pc->index =3D idx; - return 0; + return add_or_update_preferred_console(i, name, idx, devname, options, + brl_options, user_specified); } =20 static int __init console_msg_format_setup(char *str) --=20 2.54.0 From nobody Mon Jun 8 04:15:57 2026 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 4149C3431EF for ; Thu, 4 Jun 2026 10:16:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780568172; cv=none; b=EzngmZAwSm4Cnj2/9mNvQis7FZ3MNH+aAczUNZ3OuarGFmjgozVe6uehwrztH/0ncIanKGIBu/y06M1rbf6E1IErJAtzsg7gZ5nSpLqm4yG6gHnyGRV4u4lOeRZWA/H86qolF0wEHI18I4eW33biztgj94U0CFAdjxesbS4Mwio= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780568172; c=relaxed/simple; bh=B9t+QC+dNCG4cjJ/lPOcvwGISuX//DyjsNtkJLRYxjE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H4swC1mVSn3XU+tABW5yVdd4k5XNirQ1uL136sa3qjFaN9kPfO3bM8j6nBbt8k7wiJpQdRz5A5g8Jhv4YOsjxYWhMRzP97UhvQKS+/lGL0OSHRM4ybp0Gmr1eaJWQSNBz4OLA/jsrrikItefdY0/aqNFCT23d6rkgBX0jTeI90U= 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=FohMz8yo; arc=none smtp.client-ip=209.85.128.45 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="FohMz8yo" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-490af320e2aso6266395e9.2 for ; Thu, 04 Jun 2026 03:16:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1780568170; x=1781172970; 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=EZRiwF7pwuo2FecZRPUOws87FlaHbZze5014dvSa7OA=; b=FohMz8yo+RpTAc8EBBC5/RlkF4HhfWgHWyxFX4kZ6nQL0T5Uaq46fp1eVl3bJQQuBg DUzn3pn/xiDTJhKuxNBnld1x0EGeTHg4/2BmGoOgrip3pXXbphx18uufoYNXvzAf7io+ ZdqKbLHMwZINW7G293BuFbRxKyXRap6k+uIzsM65nxxTd3EVqE+Y7JKmzvKwhoNCmjo5 kjs/LreOrlKpzmMnX1EV6Wm9DrJr666QoeGLaaxgyIbvzX6KjdkUPre6FZ0gVNr3xlEl lC+XRzthMY+Cd7r41q0XLJHs7GXfT5A2DRomAvUuIsWKA3V4d28QUl8eY3Aqx072ctr7 zG5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780568170; x=1781172970; 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=EZRiwF7pwuo2FecZRPUOws87FlaHbZze5014dvSa7OA=; b=MadBx8aNECNy5IO/LGQK9KdoI0RKKt4FDkoqCumb4WrRoAlHWoRL0NUQJLcXJv+uLD dPOtbtnXL/dgNPhjWzdyhUSkA16DDN+IzJZYBH7h4Ce8LeWufgDB8vk9p+xGrlaMphPF N1mbnTQRdaDhQtIejbTq53w2bR8PNJlE0UqribIjJyY891946sxe7mA+4tMDaGy550Cr 9P+o02Cfa/UYtpIWpPB0r4pUgI10M7gefqd45/vR53zYuiU9hIIWOa1E81hgVyJxGgqv EaXd44Hl01QgMO7VYh1RDEHhbiEsfslZCni6ZqR+kfYzWKY4/sktlkIIwwtQ/LLNUwKw 5Fqg== X-Forwarded-Encrypted: i=1; AFNElJ+D7yxCJi9ov7mjk5sjTWFEj9R8MpG6pxuMNt3oG8HrIuX1egL2v3YGlroxlR3/VxMgiMTAgMwf9OqSrdY=@vger.kernel.org X-Gm-Message-State: AOJu0Yxllz0Jo/94QFOF1YzAFNaxWg0Omav5iIo6DINH3ziFsMHAaUNl 8uElmA4xUt/XxibuGpxmZu42MBOxtHSolNL/BgccScd0uDg6pqyxhfPbvxRDCANqqbQ= X-Gm-Gg: Acq92OEtUw08UodrycjqEjr2iHGUhBrbXeVyOIo8CI/fN77Ul6aRMWQ2ty1hQTSpJgS CRU7TI8HrkyinMU2VQbU3PjPUl3+A65VolDHy6UFBbM+FuKCymDNA6i8GGKamrI4qhI1CnTWTLl 0uWUAK8U3M7wWz7Sh1Szzjc4ShbwaQTqMKzFqSAusq0BEgC0GYJkqbRcl46CRe7NLA6Nj89gEm0 NcOf7dd+j6YjresIm3JQ0Agrg2WxXQrDfBbmRKRlCO6Iqf6q8zuAM4a5OMLicJa9vzcmiluA4lL cGeRK9rNyHMQnyxH2RIxQvTOaimhy5BIVOyImc4eseJq8gNnYJVkk8IPoQycOdj3Arhl1bFa+WC 6kQhEkMjrQtRhZo8nC+yS6qSB2Ji7tWuxKbbVP1yr2sOspApmSm/Quo9kjXvhDJX/59Hokqzhjq sx15jlCxbVg/MUexO3gRWDq1kieIAbiaufiR4V X-Received: by 2002:a05:600c:8b48:b0:490:9df1:f0cf with SMTP id 5b1f17b1804b1-490b5e94e13mr115360955e9.2.1780568169630; Thu, 04 Jun 2026 03:16:09 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490bc3e4b5asm60075625e9.13.2026.06.04.03.16.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2026 03:16:08 -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 05/11] printk: Cleanup _braille_(un)register_console() wrappers Date: Thu, 4 Jun 2026 12:14:52 +0200 Message-ID: <20260604101459.393162-6-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: quoted-printable Content-Type: text/plain; charset="utf-8" The _braille_(un)register_console() wrappers currently attempt to hide implementation details like the CON_BRL flag and pc->brl_options. This forces callers to handle an unconventional tri-state return value (0 for NOP, >0 for success, <0 for error), which makes the control flow harder to follow and non-standard. Refactor the wrappers to use standard kernel return codes (0 for success, -ERRCODE on failure). Move the responsibility of checking brl_options to the caller to make the logic more explicit. Additionally, move the assignment of the CON_BRL flag from the internal wrapper to braille_register_console(). This aligns it with how CON_ENABLED is handled. To maintain symmetry and fix a potential bug where flags might persist after removal, explicitly clear both CON_ENABLED and CON_BRL in braille_unregister_console(). No behavior change. Signed-off-by: Petr Mladek Acked-by: Chris Down Reviewed-by: Marcos Paulo de Souza Reviewed-by: John Ogness --- drivers/accessibility/braille/braille_console.c | 7 ++++--- kernel/printk/braille.c | 16 +++------------- kernel/printk/braille.h | 12 ++++++++++++ kernel/printk/printk.c | 13 +++++-------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/drivers/accessibility/braille/braille_console.c b/drivers/acce= ssibility/braille/braille_console.c index 06b43b678d6e..7b324329882f 100644 --- a/drivers/accessibility/braille/braille_console.c +++ b/drivers/accessibility/braille/braille_console.c @@ -360,12 +360,12 @@ int braille_register_console(struct console *console,= int index, if (ret !=3D 0) return ret; } - console->flags |=3D CON_ENABLED; + console->flags |=3D CON_ENABLED | CON_BRL; console->index =3D index; braille_co =3D console; register_keyboard_notifier(&keyboard_notifier_block); register_vt_notifier(&vt_notifier_block); - return 1; + return 0; } =20 int braille_unregister_console(struct console *console) @@ -375,5 +375,6 @@ int braille_unregister_console(struct console *console) unregister_keyboard_notifier(&keyboard_notifier_block); unregister_vt_notifier(&vt_notifier_block); braille_co =3D NULL; - return 1; + console->flags &=3D ~(CON_ENABLED | CON_BRL); + return 0; } diff --git a/kernel/printk/braille.c b/kernel/printk/braille.c index 9d21a2bb1d38..593f83eb0487 100644 --- a/kernel/printk/braille.c +++ b/kernel/printk/braille.c @@ -37,22 +37,12 @@ int _braille_console_setup(char **str, char **brl_optio= ns) int _braille_register_console(struct console *console, struct preferred_consol= e *pc) { - int rtn =3D 0; - - if (pc->brl_options) { - console->flags |=3D CON_BRL; - rtn =3D braille_register_console(console, pc->index, pc->options, - pc->brl_options); - } - - return rtn; + return braille_register_console(console, pc->index, pc->options, + pc->brl_options); } =20 int _braille_unregister_console(struct console *console) { - if (console->flags & CON_BRL) - return braille_unregister_console(console); - - return 0; + return braille_unregister_console(console); } diff --git a/kernel/printk/braille.h b/kernel/printk/braille.h index 0bdac303f8b1..ec5feac1f508 100644 --- a/kernel/printk/braille.h +++ b/kernel/printk/braille.h @@ -11,6 +11,12 @@ braille_update_options(struct preferred_console *pc, cha= r *brl_options) pc->brl_options =3D brl_options; } =20 +static inline bool +is_braille_console_preferred(struct preferred_console *pc) +{ + return (!!pc->brl_options); +} + /* * Setup console according to braille options. * Return -EINVAL on syntax error, 0 on success (or no braille option was @@ -34,6 +40,12 @@ braille_update_options(struct preferred_console *pc, cha= r *brl_options) { } =20 +static inline bool +is_braille_console_preferred(struct preferred_console *pc) +{ + return false; +} + static inline int _braille_console_setup(char **str, char **brl_options) { diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index b7dbbc1baeb1..4ee98a4d2ce5 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -4003,8 +4003,8 @@ static int try_enable_preferred_console(struct consol= e *newcon, if (newcon->index < 0) newcon->index =3D pc->index; =20 - if (_braille_register_console(newcon, pc)) - return 0; + if (is_braille_console_preferred(pc)) + return _braille_register_console(newcon, pc); =20 err =3D console_call_setup(newcon, pc->options); if (err) @@ -4316,17 +4316,14 @@ static int unregister_console_locked(struct console= *console) bool found_boot_con =3D false; unsigned long flags; struct console *c; - int res; + int res =3D 0; =20 lockdep_assert_console_list_lock_held(); =20 con_printk(KERN_INFO, console, "disabled\n"); =20 - res =3D _braille_unregister_console(console); - if (res < 0) - return res; - if (res > 0) - return 0; + if (console->flags & CON_BRL) + return _braille_unregister_console(console); =20 if (!console_is_registered_locked(console)) res =3D -ENODEV; --=20 2.54.0 From nobody Mon Jun 8 04:15:57 2026 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (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 A91E92F7EF8 for ; Thu, 4 Jun 2026 10:16:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780568186; cv=none; b=dLoRGZhcDkRjXilnMUYxZeT/ugLZcch0qu030u+4jdsLhOI4Yluf1eUudF/KnoWhjUBbOTWXmAPn/zIa0ih1bLliXw4Z3FgVq01iuZmvMI4m35FTOrZSdozjCPl340gZ0/Am4ZJHt9M6PI/oUhOna8t6L4RW26p2qZ/qeONt/c0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780568186; c=relaxed/simple; bh=ZaT+/7I10sjNAE33VAam3Fr1U5ow7W6JonB5Vz+sqe0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=alC2v2sS6WKLjuh3plCAPmVp59m/Essd2mC/RQjzN1LJ3ezpGxQpnnJ22hv2PfI4/toGjvo1ALVZ4ukblwnoG8v+XUhxQZW9MdgQ6cNd7B8iqByn3qc+BOrD4OoLLobqVUTSaVl+unfuf9BxsfYX8PXs4B4EJxhHCWCgTVsKvoE= 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=JEz06TGL; arc=none smtp.client-ip=209.85.128.54 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="JEz06TGL" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-490a76757e5so3695115e9.2 for ; Thu, 04 Jun 2026 03:16:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1780568182; x=1781172982; 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=myNFao4QCXHlYEfG8LUTprsTeobP90lLd7U+QggG78M=; b=JEz06TGLZQGOwAGLzpwKbJ591Jy+7v+Tu7jyB76l88nHsjoWFW4VxHvSC83Qxdw2Yl xRt7qWf0cOJAEUiKFsXfRAoFrtVWN2a91BylDDv1V0ybz/MWA8IJsWWCKQlAIVWzJs33 aCwWlCw97ehlvCKwwOO+1QNX2GnQjsxggTjV/rjg+srK4FtaBKG3UBSPkX4ZqlmQkCBx B1xovjDJ0uN6xcniMpZxyzvOf22NxtbQCUbwVKpeII6dwVEzOOErOLMWvtCg+Ag/IDZH lfLPAixSiTtWlclDcppAkKGmKjc7odSRjiN/qPIVVDa0whE69GEXbJQy6dLZxXYlDnfm J/8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780568182; x=1781172982; 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=myNFao4QCXHlYEfG8LUTprsTeobP90lLd7U+QggG78M=; b=S6nRCQL0/5voaFFgUsJ4iArD6KiO/vHz+qE8LF4Yar2vaCdfjstkeRSoOJcydnB+BN JXINlN4ESX7A8ftm9BG9OMiKzf5VF4zOwK5r6iwCW9mMvayGsw84Sd0qB2KE0VQ/GEKo ZW9UNA4EnJTWDEkyOZGSB/iJV58X7GiAAW795Oa24vDOqO+xXvZJqRG8HsR1qIPTKrvD FIGHOE4Gsjv1Vdh5wz/GpTgQEP95kHBGTV77W67+THHG0eH3qwn9fkIvU9+FGNK2Ek6b C+8mBCAXM+U2c/6OoNz6gBG0FZZCnN2Fc1vVXk6dPQV+Y29cZ8m99ByyZQWEbLvhdTyU wb6w== X-Forwarded-Encrypted: i=1; AFNElJ8jcNjyMCyvUlgaNwO7QO5LmqzO3PCZj0JGeA9XaF7BPemRNxsWWIa16srSqnYM4fw4gxbWA/Qz8qRF7KA=@vger.kernel.org X-Gm-Message-State: AOJu0Yx0TN6yqXW0Ts1fjwxHsGVMDfbO8umW+noD/7pmpcl1QYBvhqXo 0IGFKo9EnDtvs6OlIdExfz1u0MluBgBxHVeHVJFPOYygeYdcCsHeYVjXn2mSTE8t/FA= X-Gm-Gg: Acq92OH8ioy2/H+C2JtzB2DVE/0FGhTkdKv7cxgPWi1Ua+rvAmnukUmsvIDsxxmO4I0 G9AKd689981XSR5izK3MTmNasOAH7J8awdo3aqy2Fcqn9npLK32XhA4JXodUyUFwEcRvScywLNh imvUxvNFp1wEe3qlseygv18wHckm7DUguo+qUqh4UFgtEydYQ7v1YX34qNQT1qoSy9HTrbQ6HuD dwvKi7z/vI8nwVZYchAjLwVPXVElyPcsQADjudt8IzbZyf/6AMVVl8wbIJIQ1bCjr8cIydLufOu DYCsiM0HAqXBrLZ7Yr2lHuc9ZJI+xWo0DWT8AhHuzABk8d3UfZ00l0Nwz0VqgvHv+0U2IghzVF6 Ncr2IPyM6TWHv1jGvOOtNyby2rPUqjwEFMvn0KgJfCUMjg75mJWpfJgAGbB8cbovGbfMQE1DlzL CH91VXvXstd3W7CHsIKzTxJaO3uuXVoFVCGM9TxKWpwyI2Mtc= X-Received: by 2002:a05:600c:354a:b0:48a:5301:bb5c with SMTP id 5b1f17b1804b1-490b5fe0e41mr118251255e9.16.1780568181917; Thu, 04 Jun 2026 03:16:21 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490bc3fd663sm67054775e9.10.2026.06.04.03.16.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2026 03:16:21 -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 , Sashiko Subject: [PATCH v4 06/11] console/braille: Lock console->setup() call during the registration Date: Thu, 4 Jun 2026 12:14:53 +0200 Message-ID: <20260604101459.393162-7-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: quoted-printable Content-Type: text/plain; charset="utf-8" In braille_register_console(), the console->setup() callback must be called while holding the console_lock. This prevents a race condition with a possible active boot console that might be using the same hardware registers. This applies the same protection to the braille console registration that was introduced for regular console registration in commit 801410b26a0e ("serial: Lock console when calling into driver before registration"). Reported-by: Sashiko Closes: https://sashiko.dev/#/patchset/20260423130015.85175-1-pmladek%40sus= e.com Assisted-by: Gemini:gemini-3 Signed-off-by: Petr Mladek --- drivers/accessibility/braille/braille_console.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/accessibility/braille/braille_console.c b/drivers/acce= ssibility/braille/braille_console.c index 7b324329882f..9ed3abffb687 100644 --- a/drivers/accessibility/braille/braille_console.c +++ b/drivers/accessibility/braille/braille_console.c @@ -356,7 +356,9 @@ int braille_register_console(struct console *console, i= nt index, if (braille_co) return -ENODEV; if (console->setup) { + console_lock(); ret =3D console->setup(console, console_options); + console_unlock(); if (ret !=3D 0) return ret; } --=20 2.54.0 From nobody Mon Jun 8 04:15:57 2026 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: quoted-printable Content-Type: text/plain; charset="utf-8" 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 consol= e *newcon) newcon->flags |=3D CON_CONSDEV; } =20 +#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 =3D try_enable_preferred_console(newcon, true); + if (err !=3D -ENOENT) + return err; + + /* If not, try to match against the platform default(s) */ + err =3D try_enable_preferred_console(newcon, false); + if (err !=3D -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 =3D 0; + + return err; +} + /* Return the starting sequence number for a newly registered console. */ static u64 get_init_console_seq(struct console *newcon, bool bootcon_regis= tered) { @@ -4108,9 +4155,6 @@ static u64 get_init_console_seq(struct console *newco= n, bool bootcon_registered) return init_seq; } =20 -#define console_first() \ - hlist_entry(console_list.first, struct console, node) - static int unregister_console_locked(struct console *console); =20 /* @@ -4172,39 +4216,7 @@ void register_console(struct console *newcon) goto unlock; } =20 - /* - * 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 =3D try_enable_preferred_console(newcon, true); - - /* If not, try to match against the platform default(s) */ - if (err =3D=3D -ENOENT) - err =3D 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 =3D=3D -ENOENT && (newcon->flags & CON_ENABLED)) - err =3D 0; + err =3D try_enable_console(newcon); =20 /* printk() messages are not printed to the Braille console. */ if (err || newcon->flags & CON_BRL) { --=20 2.54.0 From nobody Mon Jun 8 04:15:57 2026 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (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 18C823431EF for ; Thu, 4 Jun 2026 10:16:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780568208; cv=none; b=AVLfSoyeeoZ4hAyXDx8IK6MkfW8vlV3pqp+qcHTGdix9pj+jZ+Lu7EarN0Gv03IoNHaBrYLmvuplAKG43cFrWczGR00sjqVmSqTR7jS0HCKJCt922TTy/RZya4eOVfVsDj2x4tNM/R29Xt1y0Pkqfzcb09YJtopEVaH7vWK54ZU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780568208; c=relaxed/simple; bh=at0OIgZBiCeeSsvWFnZVpQSCQeUWoWqhwj7/d5V8a48=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kQVTGNFTb+6DvAeK3yzGGVvhYloIQOaJ6zRHov7D+QjY7tDKp3+tlnXWJQEYOkM9+Ubs3DdusJKngXgajmKJ+Abg+H2NXVg9zEJdN6tZJT3eGCbNKu2lZzZUCMU82Qzu2BWxQB/CSP7G+3CVAfA7QTzzJITTx13KroSLfCXHvPw= 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=CWqHH2xn; arc=none smtp.client-ip=209.85.221.46 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="CWqHH2xn" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-45e9f4a3510so290957f8f.1 for ; Thu, 04 Jun 2026 03:16:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1780568205; x=1781173005; 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=7CkHpXRMc1nizWSGdPZBUG3xtGvnOF2T1RLJ8fvw1Y4=; b=CWqHH2xn1OQ+dHZp3AxqIiAla0x1pdWaniDwGSYUNfDWns+OO8tQFK0XfHiGm4pmhx +tril7Te6WbSFQm1YP6EYROhLy4mrB9FfKS8DD3Tm7Epk+IDcXQGKf/LOmw3XNQMNTNi XONAIK44B0iDDJhpF1WbJHTfN+E6zC66GIeXpuarwtzk5WUreoxO4fmjx72cwg1R6qjY sWxe1X+wxg3ia/2ud3CYaNF7DjvxOI7HDZPV9VpvBM+Uck/81RCYQeLECFWifHZH7DcW 465K7abUOoh8FquMTg5CZo7m2CBSf9ZSl6rbVQ1trn+3+QS1UFVBlQCrNKjeDfYGE3Xp FFfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780568205; x=1781173005; 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=7CkHpXRMc1nizWSGdPZBUG3xtGvnOF2T1RLJ8fvw1Y4=; b=gT86JVRD1s8Yz7YAdQOtCM/Owrtj4li69a+W/Uhy+MWgM7IuFEn4yt+gm1BNPTuQ5q 0OvDQd01poC+77W458oHvaVnddvcRFReFrQOOogz61rHhtMsRJGukfC18jHe5feXFsCR KbAoxR6qLPC9p48JhCJKLmDqehMKQBTXOhR0l+rnRzhDEugY3ZTmR7IzeKHyzrJAgrTM lmRQTMIf4OPPhx1E8Qm7SyquT/4FvEbe6S6CkGwY6mkxIjfNT6VE6xukVY8wpUj91ZM2 tB90Cy2/qoHyrenr9B4uM27wxVsWtaXCQ6TCCTzmPSktq4jNTAg8VAs3rfUIwUFuX9fD g9yQ== X-Forwarded-Encrypted: i=1; AFNElJ9pLS/0lpggHSMvcilYEARzsB1VIkitbl3p28dAT9wq9zmZEC8omBvbxHhYbW3CZaGSohbmTqsePQmXXOk=@vger.kernel.org X-Gm-Message-State: AOJu0YzHk4dH44UHGnLbl4QhHfzpr92oUn1VkIEeWB5rOI8XUfauswdM r0qXs5xV8mgZFq6bdep5T1zocpdMffbd5pZt5yl9CzAHKz8BXa9KY3KwRVgviwWxSdw= X-Gm-Gg: Acq92OE6EM7RaMLBBFRSiZWEGH+/IeWWtzNPpwmwa44w2t6XpzTdxzzPH4GMUd3kmE2 ZgFI/NbBljbwstsxgKdAy9W5Ak3OO/RBEChdLtz3A5wp7Xrzma8gvdNdZ+EF2HWbza0bvjyAJmf cyRk1cSZsfm+aodqDHslLjYCw8Ky+F/b4dkcuzzk6LEu5oDU6v3JAVZ4yvjU5xydbO1oPWrFOIO 6tZWp0rhuoLpeInVstPvfIEu8LBTAOjZcizwxp//Y9w5ANHFllVqiqvHCoZW1brM69+O9I+wmUU chb0EvCe02eFNE+k3pS7I0Y8a9DyhiUlbxT1JpyabBn1/RxoJ9f51Y4VxOz9d44VBNSQuKhwuNf b6gice6bt7K5QrjLYDlsKSjqA/4+Lxzkl2wOqn4qAUUrKDUnJHi/G2JQgf6DEPQwISIzK3NNRr4 rlPN6pZ6DVHATn4GPMhmnHhZ5Wm7SeojVdWdkTom6pclEw7LI= X-Received: by 2002:adf:e743:0:b0:43d:733f:aee6 with SMTP id ffacd0b85a97d-460217920damr7772447f8f.10.1780568205412; Thu, 04 Jun 2026 03:16:45 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f2dcad5sm16421060f8f.5.2026.06.04.03.16.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2026 03:16:44 -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 08/11] printk: Try to register each console as Braille first Date: Thu, 4 Jun 2026 12:14:55 +0200 Message-ID: <20260604101459.393162-9-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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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. Refactor the logic by adding a parameter to try_enable_preferred_console() to explicitly handle Braille vs. non-Braille cases. 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. Note that _braille_register_console() is skipped when the given console driver has a match() callback and it succeeded. It means that it took over an early console and can't be used as a Braille console. As a result try_enable_braille_console() might return success even when it did not enabled the console in the Braille mode. It is the reason why register_console() has to explicitly check whether CON_BRL flag was really set and could skip the further steps. 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, 50 insertions(+), 6 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 5fb9581804c7..3a645558c18a 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -367,6 +367,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 @@ -2648,7 +2649,9 @@ static int add_or_update_preferred_console(unsigned i= nt i, =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 /* @@ -3977,8 +3980,9 @@ static int console_call_setup(struct console *newcon,= char *options) * by either the command line or add_preferred_console() and * setup/enable it. */ -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; @@ -3989,8 +3993,19 @@ static int try_enable_preferred_console(struct conso= le *newcon, /* Console not yet initialized? */ if (!pc->name[0]) continue; - if (pc->user_specified !=3D user_specified) - continue; + + /* + * @try_only_braille and @user_specifified define which + * preferred console entries are handled in this round. + */ + if (try_only_braille) { + if (!is_braille_console_preferred(pc)) + continue; + } else { + if (pc->user_specified !=3D user_specified) + continue; + } + if (!newcon->match || newcon->match(newcon, pc->name, pc->index, pc->options) !=3D 0) { /* default matching */ @@ -4003,7 +4018,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); @@ -4019,6 +4034,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) { @@ -4041,6 +4067,24 @@ static int try_enable_console(struct console *newcon) { int err; =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. + * + * Note that it might succeed also when the driver has a match() + * callback and it took over a boot console. In this case, + * the driver will continue working as a classic non-Braille + * console. + */ + if (want_braille_console) { + err =3D try_enable_braille_console(newcon); + if (err !=3D -ENOENT) + return err; + } + /* * See if we want to enable this console driver by default. * --=20 2.54.0 From nobody Mon Jun 8 04:15:57 2026 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (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 311962F693B for ; Thu, 4 Jun 2026 10:16:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780568220; cv=none; b=HmRTNhw/2ZR1WmCYHpNAwyZTUV3zvr+6A1yreaM4vCbFOyRyewvmRKUziMBtzKX1JkWkrI+Men637GCQxzau85hptnKIHkcelx59lHBX4oVmFT+BOcDWfj3+u+M4o/nMNpkXrWzABGgGZFT16NgfgbgR5LtnGRAGWaM+wD20VyU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780568220; c=relaxed/simple; bh=VCsLyFxHscTUS9oWvKhuTa5oEdz2tMyHJsu0SzPLGuo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b9MZ827rAWIgt9oVxFeBUNn2VWfQpXdpts3cD+gZFcZG7+qa2VByRbHBMmBP7eiG8lI6wZCgq+g3kMGT31+1fOxF+uJc1ZYpxx/9lZe1ziy5QJyNg3BObozwWaIojbt53OWcryx7KjXHaPr09HKsKd4lU0ox1/aJKAvHC+Q6YgQ= 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=YIYgnXCo; arc=none smtp.client-ip=209.85.128.43 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="YIYgnXCo" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-490b3637b90so4739005e9.3 for ; Thu, 04 Jun 2026 03:16:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1780568218; x=1781173018; 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=fybwUUcgvAmcpQ3ZjDoHTmIuRtRDI1Lr+X8F/Nj3OTs=; b=YIYgnXCotYZJafwvyTRP8DLAalp47E2+DSmgONcMGnHiG0AkyE/tI5RUXMEquf2Cwb 8ryzWZS133H3+hZFBAo7cK51GPWHRCkH0ATbaMd56j65xXpxCZ2TQWs+WthQrWvxirxe VytnOcyDjwt35KXLLLqeOx5aJfJL0Sx139y3JSLJNJb0e57ojXag+9PbyA300pxSy4BL tv9vU+apRwP+5HDnxmuSNIVNwDsIua7xLbZh8kMwPVZbkvV3KmNEUO1EpqO958DRd9ag dIZb+39iT0zzATfa8l1Uxuav3k0pdLvOZyMPAF++J1Ai6+vAWvBXhqbLpPDmXU8OF2JV vRqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780568218; x=1781173018; 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=fybwUUcgvAmcpQ3ZjDoHTmIuRtRDI1Lr+X8F/Nj3OTs=; b=L2e8VxWrUY21YaVtFKGKw3lu8IT9Yl9ysrxwO+Qv0I2CDr85Zk0I/JuOEiw2f7MQJV uNgkFRhs2xNF68COR1zqr2mu4ijClEAu/henv2r38dGSEckYx5UDjMjb9FHySwOPjIg+ JoS1Gz38pvYLBzaWEBz6c+lpwnqxoq1E49P3OTzA/2Q0ajuOhezDaJHyMhAPUDDHzq4+ m36R/WkblqoH3q0UOh4wcjW3Zmg0wt4/IvWAGn1/1m5ubXE/R/8H1O+3sH8+twPs0PZo B8jz//9nRrNHI+KH+ijrk8o/XasM4chB0EK/yC5Kyenb19omt8OpLwu6jMBV53D3MRIW zWpw== X-Forwarded-Encrypted: i=1; AFNElJ/MsqxnR+GPZJO7158JFAFtHnvuGXkGujs/ZvNxOCuRHO4hHV5HVUFH2fKHaaOw3VdmBhOiwwA/skJhNWM=@vger.kernel.org X-Gm-Message-State: AOJu0YyxWoRixyzym78RJNSXUgcl364URikIaeJJ0Nre2puSlymK6AV1 yK9xkTc3imhF6QaKzR61fPLP7JRGy9kYJW57bC7n9fJDxxHt8eCkiQMWC+XfH1s5fDI= X-Gm-Gg: Acq92OFUKHPO749AOtDTOrq+zlGYyjVJhLC92eDPPNmqirbQEHl1x7t0PXgiHJgXm5x KNd2H6FLYeUrGyg6lDPxA4mudtoTDC/B6eykJ9z5YwOwz8Lk96oEMhK3gQjhsBPlGX8ozw76pIC 2WsEeud0MpDoYmLVtArwMjaaVNagAsIdZkppD9a3b4YIrjXCOWfsstWD+1rcLL7tE+U3P/VCQKi kl05CPu5ST4b+CesM4aO1Cz/kxC+yi+wKTjPZV7TgTwkEGPMSo+PPYkg33ru81wTIrYeK0rVYav F0ZkS4vPLik/axohlyYlx4da+6jpw17zLzmUMmveHXec5qWBXoJDFxkXnkuEy/I3hdT58n9rtaw OcgCtcBwknZG4RYPYfLQ8pEwPqyntdfHGh3NrJbkOp5lo6UicC+GPr6IcGWFen2grbxBCeuQHen KsRfFnEcFyDXRdtxF7bxYtFNMwjD+FEod4polP X-Received: by 2002:a05:600c:a09:b0:490:958f:2a5c with SMTP id 5b1f17b1804b1-490b5ed6375mr120898895e9.17.1780568217220; Thu, 04 Jun 2026 03:16:57 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490bc39e024sm73701835e9.4.2026.06.04.03.16.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2026 03:16:56 -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 09/11] printk: Do not set Braille console as preferred_console Date: Thu, 4 Jun 2026 12:14:56 +0200 Message-ID: <20260604101459.393162-10-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: quoted-printable Content-Type: text/plain; charset="utf-8" The Braille console reuses the framework for handling consoles preferred via the command line. However, it is a special-purpose interface that neither receives standard printk messages nor associates with /dev/console. Currently, the "preferred_dev_console" variable can point to a Braille console entry in the "preferred_consoles[]" array. This occurs if an entry was first created for a non-Braille console, but a later 'console=3D' parameter redefined it as a Braille console. Since a Braille console will only ever be enabled as such, it should not be tracked as the primary system console. Adjust the logic to ensure "preferred_dev_console" continues to point to the previously designated normal console instead. Signed-off-by: Petr Mladek --- kernel/printk/printk.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 3a645558c18a..a4eaf157cece 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -367,6 +367,7 @@ static int console_locked; static struct preferred_console preferred_consoles[MAX_PREFERRED_CONSOLES]; =20 static int preferred_dev_console =3D -1; +static int preferred_dev_console_prev =3D -1; static bool want_braille_console; int console_set_on_cmdline; EXPORT_SYMBOL(console_set_on_cmdline); @@ -2566,10 +2567,11 @@ asmlinkage __visible void early_printk(const char *= fmt, ...) * Note that a valid @name and @idx will get assigned later when * @devname matches during the device initialization. * 2. Specify @brl_options if the console should be enabled as - * a Braille console [*] + * a Braille console. * 3. Only matching entries can be updated. * 4. @options passed via the command line are used when the same * console is preferred also by some platform-specific code. + * 5. Braille console is never associated with /dev/console.[*] * * [*] Braille console is using the mechanism for registering consoles * but it is very special. It is primarily used for user interaction @@ -2649,10 +2651,22 @@ static int add_or_update_preferred_console(unsigned= int i, =20 braille_update_options(pc, brl_options); =20 - if (brl_options) + /* + * The last preferred console should get associated with /dev/console. + * Except for the Braille console which can't get associated with + * /dev/console. One level history should be enough because only one, + * the VisioBraille device, is supported at the moment. + */ + if (brl_options) { want_braille_console =3D true; - else + if (preferred_dev_console =3D=3D i) { + preferred_dev_console =3D preferred_dev_console_prev; + preferred_dev_console_prev =3D -1; + } + } else if (!is_braille_console_preferred(pc)) { + preferred_dev_console_prev =3D preferred_dev_console; preferred_dev_console =3D i; + } =20 /* * @pc console was defined by the user on the command line. --=20 2.54.0 From nobody Mon Jun 8 04:15:57 2026 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (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 6BC571A9F9F for ; Thu, 4 Jun 2026 10:17:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780568232; cv=none; b=oFYjTUI6UlDA4AxvneZO58DlupUq0Kz2KXesHa+F9ZqHhwSUiN+zaQnUseCosYQY7F8AHxrIwyznvVCcxmfqyiKCW+/+EQYzbT7PVDRGsR5gKlMv3sIfVeuI7K7/Bc9eauqaYgZfRNixa04zaTVUnUzl3fYWDVK2eSU29qF0nCU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780568232; c=relaxed/simple; bh=OhlPCZKHpFc/1MXB5axzKBR3R03Mebv+nxjSEXr9JMY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y6wVXbcK2j9Ybo+g5Vj5B81oqs1/sVf1D9etbGElmKU4t3euxTAv1Tfd1rAAP3jq93is02/VQXxP5CmNZv8bOuQ9hqk82p+r+5+7P5HWM/7jA6f4Y1B7b/zLwZ6vzo+PGrxiCEAaNLl/3vqW2Bz2WHxLTfVkxvF8ff6CvIBgBSI= 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=Rwg2qb1w; arc=none smtp.client-ip=209.85.221.49 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="Rwg2qb1w" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-45eedc94d37so258999f8f.3 for ; Thu, 04 Jun 2026 03:17:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1780568230; x=1781173030; 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=1Axeu4fMcBEJteme8OlMPdFFTSrwMBXiECzKN1qnIMQ=; b=Rwg2qb1wDgFfm7bxyIFJL6mdUuUC7QK90Xu2/TkXTCYt1y/PnqV7k+7SaZoroNYf5Y Si2pKrGTK27KCNHDfqnshTSHXlHZZOr0XAtHFNmDk7PCXSvMlHKIFfnUyBhOJls74zR1 Z0+/0hPcT5pRoAGW8zvKWL8VPnsMPoekNegToGyVkCMSIh6Nl6Yjwv6BKLG//M+08Q9b 90UvX/2qkLi8oKXyflJdV5WIfoL/kGwCBl1W6jTjbFjG/+0MmAc5JcorJ6APW64yIqKZ lfi0ptvRz3Y0L6IR717BgIxlGin/SpintVsw2Zd15RUWrSTuHObG2NEWNIoCqWIOEb/2 rK8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780568230; x=1781173030; 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=1Axeu4fMcBEJteme8OlMPdFFTSrwMBXiECzKN1qnIMQ=; b=Bgd2pMTHcRWaqKj1yQRocuJNAmD/k7VziU1Pwbn3Rjr1xytJs3ylifFS+5epCY4L4G K8yvdlNKlG0x1qwRce+7FPc0DVIGbsAsYazyBzhuEGBA31ekBY46BBVUMoyMA4cDPEme hMM2eYu3N2EsU9nCvQJueH7z/gsbxottNJMRuEYNa+MNCkemcOWZe0Eevp50jPLballB Unwai3eB4bgQEgAHPcIUaF5tOA8kqXY3nHLwA5Mn1Im8nWIg8+sSdUhA2wE7TJTL/qlS ao4YsFuj67uH3cGumgjUwoj4MBGLR6NQEn9RO7zOcqsNC0MAMCAeUNkSmANiWSZ/D0vP Uwgw== X-Forwarded-Encrypted: i=1; AFNElJ/xWtemiioHCWhJUBf/VsFhxqrdTudP9EFWYLNBCQUIVDzhV8xyqdZtm9SYdOVDqFzt5mGRbtNsNVxjSSQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yy6k8nTVBvi3o2kY2egAtcToZ2xLKOXq4c+IreOIOz9lizaMu18 GwqPCvzRKsWFOT05ZXgvvZepBM4KvjPD69cjd7A3gTldLWYVgjTT6TEmjmc+Is6/CsrQYNKAQQC B+KOb X-Gm-Gg: Acq92OEioSONm/LNytpWaHNfE79gCg1UC9qAf0u/P36emi1E407q7N8Uocxa7ZadnSd jJF9N0Ja3+GVWD7DTPeLdsQVxiTj/EoNt4iuv38lUkvfWw3ijLNPQ4aiTwFP2++bzEyeVBlHlxI C2dHrLi7Ds2cop4oG7dytK7i9FM20f3byZi9iBFEzB6AXqxK50EAkgFx14uXAJGKrap7hZ0W75k XuctUyKa/eOqTty28ZnRj7NaALXLOoxMCb85t4LowLMdHBRB7qjKp5pRF9B9Lq9FCI9gYgxDx3i 5E5cDBIG/0MY+YTIl2h51qhrtXY9C6e2v7kEMIM6wQjUTVgHoLWVlpjh6Gx1eYYXNh1afT3Uylw bz3SYnmvHWCjFFnuJLLJbfVhjZVkbZpZTVZw0H3eRTNyNFjjrFPgUE3SQxCH9JBXjQJ/xXw6I4z jWivFuvbaEaX4niJLcfy0sezCeqicNjdrf5zvG8RjJKNbEk78= X-Received: by 2002:a5d:5702:0:b0:43d:775b:c9bd with SMTP id ffacd0b85a97d-460217a6ff6mr8303264f8f.10.1780568229625; Thu, 04 Jun 2026 03:17:09 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f35fd33sm16574514f8f.35.2026.06.04.03.17.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2026 03:17:08 -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 10/11] printk: Modify try_enable_default_console() to return error/success Date: Thu, 4 Jun 2026 12:14:57 +0200 Message-ID: <20260604101459.393162-11-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: quoted-printable Content-Type: text/plain; charset="utf-8" Currently, try_enable_default_console() has a void return type, and its potential failures (specifically when console_call_setup() fails) are ignored by its caller, try_enable_console(). Modify try_enable_default_console() to return error/success, and update try_enable_console() to capture and propagate this error. With this change, try_enable_console() will no longer return success for a pre-enabled console if try_enable_default_console() failed (such as when newcon->setup() fails). While this might change existing behavior, it is the correct approach to ensure setup errors are not silently ignored or treated as successful registrations simply because the console was marked pre-enabled. Assisted-by: Gemini:gemini-3 # commit message Signed-off-by: Petr Mladek --- kernel/printk/printk.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index a4eaf157cece..b0df4a23252d 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -4060,18 +4060,23 @@ static int try_enable_braille_console(struct consol= e *newcon) } =20 /* Try to enable the console unconditionally */ -static void try_enable_default_console(struct console *newcon) +static int try_enable_default_console(struct console *newcon) { + int err; + if (newcon->index < 0) newcon->index =3D 0; =20 - if (console_call_setup(newcon, NULL) !=3D 0) - return; + err =3D console_call_setup(newcon, NULL); + if (err) + return err; =20 newcon->flags |=3D CON_ENABLED; =20 if (newcon->device) newcon->flags |=3D CON_CONSDEV; + + return 0; } =20 #define console_first() \ @@ -4114,7 +4119,9 @@ static int try_enable_console(struct console *newcon) if (preferred_dev_console < 0) { if (hlist_empty(&console_list) || !console_first()->device || console_first()->flags & CON_BOOT) { - try_enable_default_console(newcon); + err =3D try_enable_default_console(newcon); + if (err !=3D -ENOENT) + return err; } } =20 --=20 2.54.0 From nobody Mon Jun 8 04:15:57 2026 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (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 720AC340281 for ; Thu, 4 Jun 2026 10:17:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780568244; cv=none; b=RBEWyejFgGc1bsYzLmqq+E5CCjruv1PYuqryfuqdjThvC9QJv6P7H2KgxLeGicgMY4mf0/xq/tPYznFHxGhBtZ9OCZLW3uzlLywZ2AUOJh2O+6WCK9ChE7dhXjCbCIpRvtHWtIO9XS/BJ0/bmbiReOcaH9O02PyHWcAjhTCOro8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780568244; c=relaxed/simple; bh=HyZ0J3MTzcMxzlECLbFR83/l6z2kx/PNT/4qjaM9qoY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZaVxCFSwnqkK+XPxP2tYvqc2ePbq0+GHVEqtpuOqY0rfbX/5Ui71wYQ7zLkHjv1Pdf1i1pptn96uxBQuI0xhvOE44g2hNXdWsQ6sJZ9MwCPO13ZS+Z8eaidoFmbZ2u4aVrQ8OGXgqWseGcUIitsLUAQLPwal0/m9TL56fJKEAEE= 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=YIevJ0ZX; arc=none smtp.client-ip=209.85.128.43 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="YIevJ0ZX" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-490b64c8311so6579515e9.3 for ; Thu, 04 Jun 2026 03:17:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1780568241; x=1781173041; 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=X9o/Y/HJTc1QZg0UhBXwki+53QuzO6Spow5+XOE6FcE=; b=YIevJ0ZXKLh1ezOeqXcogCeLe4GUl6nDBNMDpkhzzUa18WQReSEfzped7Q2olgzeSm TLh9sst8tTeaK0MTwRQOb7JhD69FDwaSIyJGTRDwpcjBMnRLFhTSdhK1Yo8cXJvnri3V yunZ0uaNmQzmRxoP0wV6p0WSfOOYiRz/kSR9hmN2xrV0qSRxum9/jiHFuZrViEW8NVye jEQoo1p2AAj0dc5FgF8U+dL6mVf9mmAwNjnTDA/YwVOMcuq0bx+pe7FiupuDveAMrUnM Rm3nQzLe16GLMGRqvMF9fo1VVC1OuBurQtke/rj8qHBAcvmf7cx0iKqB1nSLb/GyojyK TszA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780568241; x=1781173041; 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=X9o/Y/HJTc1QZg0UhBXwki+53QuzO6Spow5+XOE6FcE=; b=XSJK98LsWdWouPsVyLiYUGUdJnITQf9afpiiNmkTfZe0ZIEkskjpuaAKyxUyltobyZ ILVz4I0Rd/CWUdUVkIkk/grKVW10+hADMqXhC45xuoqf95oXL94ca+fBNkbsupwwzcuP 1wG9JFKQ6+EGnNcY/EhAqhmY4z2+wakX/aOxJlJJ67yYyb+TP1rN7BkL4FThgSaOkDfM b6P/KQZcXQqEcwkIps90E2TSyDtIzSYBzvrO6FnheuZrAaYCXvxME4RE4eYQnY+MtPhm dcqPU7Lx+Gm4/tcU0AjP90vcsgMYDaBRF2EKVliTbvyOuLzsatpzplJXIlPY5LEZiIKn o+OQ== X-Forwarded-Encrypted: i=1; AFNElJ+vSmtOgaQhG+4zlKi1SXd59XUKkdlqXE+1e3YWtc6fbmKLpvE3bw11rBRNyCCICBJqpMstvl/lhsVTfW0=@vger.kernel.org X-Gm-Message-State: AOJu0Yy2CjRE9ehjYkhf7YJkZ5QoZxkVwNYu5sYp6nzsH/6UVo+Eaa62 jj45CCdPn2Y2aMZ415BAG2H3eHwVGfe+SvGP2x81bnygV804RMZ3FqFFAsvSGErX9Bo= X-Gm-Gg: Acq92OEbUdIKOFOin2NjGyBQCSAiopfxw54wexWQKopQ0pSoZVd6BQ0KU/T+wJyigzg 52l4dx0wCx58u6pJvIjdLRAXrhpaON+tcm3QWTJn24TmAm1K8AiCWODUSC6WSulhrEi8HgLA/2t JKFzsQhmX3t444C3X0kfdGxGBTvKrhi7Z4zLAbJRn5jNHz3zVWV0ECqlWvydARqf9v6/QW/Laq9 STFv/3NyD8l41IhdaKRbcdpLtP3ZFtZhrza2KQgTA8xAkHD497NL1Zmf3iU/h6gx9WhkcDd/L8c AOg3x6tbKbTdTkzQ7gH1T0+dqZLwbOZguzJzGyg2XIG/C0k05eC2z2h8Ub/bxSur97AqpYineTa aRoBqbfJMaJZ7WFTwILROeeUzZUZLL0/3D9aI8srbZnPGTmmdxBiLY6LvCcPUYFsH2DMSCJT5ru bdm49K3DNkx4LQzx8zx9i2D71tomo1kPZjVlZi X-Received: by 2002:a05:600c:a0c:b0:490:bd66:e522 with SMTP id 5b1f17b1804b1-490bd66e594mr45137635e9.29.1780568240997; Thu, 04 Jun 2026 03:17:20 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f368e9fsm14671140f8f.37.2026.06.04.03.17.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2026 03:17:20 -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 11/11] printk: Try enable preferred consoles only when there are any Date: Thu, 4 Jun 2026 12:14:58 +0200 Message-ID: <20260604101459.393162-12-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: quoted-printable Content-Type: text/plain; charset="utf-8" try_enable_preferred_console() used to be always called because it had several hidden effects, namely: - returned success when a console was pre-enabled using CON_ENABLED flag. - enabled Braille consoles which were ignored by "preferred_dev_console" because they were not associated with /dev/console. - returned success when a console was enabled by default because try_enable_default_console() did not return success. The first two hidden effects were removed in previous patches. The already fixed handling of pre-enabled consoles actually helps even the 3rd case. try_enable_default_console() sets CON_ENABLED flag on success and is later handled as pre-enabled. Prevent any future hidden effects and call try_enable_preferred_console() only when some console is preferred. No behavior change. Signed-off-by: Petr Mladek --- kernel/printk/printk.c | 51 ++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index b0df4a23252d..21a9c78f4deb 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -4084,7 +4084,7 @@ static int try_enable_default_console(struct console = *newcon) =20 static int try_enable_console(struct console *newcon) { - int err; + int err =3D -ENOENT; =20 /* * First, try to enable the console driver as a Braille console. @@ -4104,19 +4104,29 @@ static int try_enable_console(struct console *newco= n) return err; } =20 - /* - * 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 (preferred_dev_console >=3D 0) { + /* See if this console matches one we selected on the command line */ + err =3D try_enable_preferred_console(newcon, true); + if (err !=3D -ENOENT) + return err; + + /* If not, try to match against the platform default(s) */ + err =3D try_enable_preferred_console(newcon, false); + if (err !=3D -ENOENT) + return err; + } else { + /* + * 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 (hlist_empty(&console_list) || !console_first()->device || console_first()->flags & CON_BOOT) { err =3D try_enable_default_console(newcon); @@ -4125,14 +4135,11 @@ static int try_enable_console(struct console *newco= n) } } =20 - /* See if this console matches one we selected on the command line */ - err =3D try_enable_preferred_console(newcon, true); - if (err !=3D -ENOENT) - return err; - - /* If not, try to match against the platform default(s) */ - err =3D try_enable_preferred_console(newcon, false); - if (err !=3D -ENOENT) + /* + * Make sure that pre-enabled consoles won't get registered when + * something went wrong. + */ + if (WARN_ON(err !=3D -ENOENT)) return err; =20 /* --=20 2.54.0