From mboxrd@z Thu Jan 1 00:00:00 1970 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: 8bit 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) static int try_enable_console(struct console *newcon) { - int err; + int err = -ENOENT; /* * First, try to enable the console driver as a Braille console. @@ -4104,19 +4104,29 @@ static int try_enable_console(struct console *newcon) return 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 (preferred_dev_console >= 0) { + /* See if this console matches one we selected on the command line */ + err = try_enable_preferred_console(newcon, true); + if (err != -ENOENT) + return err; + + /* If not, try to match against the platform default(s) */ + err = try_enable_preferred_console(newcon, false); + if (err != -ENOENT) + return err; + } 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 = try_enable_default_console(newcon); @@ -4125,14 +4135,11 @@ static int try_enable_console(struct console *newcon) } } - /* See if this console matches one we selected on the command line */ - err = try_enable_preferred_console(newcon, true); - if (err != -ENOENT) - return err; - - /* If not, try to match against the platform default(s) */ - err = try_enable_preferred_console(newcon, false); - if (err != -ENOENT) + /* + * Make sure that pre-enabled consoles won't get registered when + * something went wrong. + */ + if (WARN_ON(err != -ENOENT)) return err; /* -- 2.54.0