From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 3B8233EF0A8 for ; Fri, 29 May 2026 15:22:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780068169; cv=none; b=guq6cHaCj9wIZIuJglOeVh0boCF044pRfzEHaGRj4bNFsy4rW33QGRJOLPa5hSoJLUQU2ggIY9kHopOtS3IlM2YQiiXGFWGAN9AU0D/FVztilzPU5VwX1sJjBnrbiXoMtsqVqYAPWGdOW9jQF/+JIfmtFReZU3Ks/6H0fV1BdgM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780068169; c=relaxed/simple; bh=PGlOCSurY6tkl07qBN16plyebQ4Dcr4TRlGCTd+03Aw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=b8q0OssxIJtL3gk4uaV/oWzZPM9I6MjyhRr+PuBO7rQL7ZmgiloepqoJoEENStrWAsA2yjMhvlOTAvZ68VSon3Yg6BuZ6RNPMCFO8GMoJCwLd7Wr7szZQ2RhBWxsrkPJfaQG2B1daBXpXew0AcMcbFEhkIFx4zFoKlJOt83R878= 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=aH2uLmOD; arc=none smtp.client-ip=209.85.128.50 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="aH2uLmOD" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-48a563e4ef7so99455235e9.0 for ; Fri, 29 May 2026 08:22:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1780068166; x=1780672966; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Q6+n1EmGX8LN63Z4anqIdaVWAERyoiS1nCbOH+oHEB0=; b=aH2uLmOD0W2msWVWuUhptMfE5eBWIcG4x7xRTVI+ZFvV/BG0LSobgW1Cgg36lUObze 7Wztf2s5JcgCZ/+X6LHd5qMH9la52DcDZPEOkf1IDSUJeREB1EdFwreVdIQXNczZ3IGG QFsGtNIDbXEWDV7onHMYRS+JyAQn6hkavNp1xijneMmKPlwp37l8DTLaN9T2lLJ+MDy+ p4PLN0X17+Rqjy3uPikT5aumxqOMnfxZdqK/xHkoDy//Kw7tGsAx9I+/YPenpytoZeqs UKBuzvFYwHH6NNmQplsqNcIQmNipeqEyqe79Z1OdzmxuA8INqpFdtuGf1lYe/bq1vuq1 rzKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780068166; x=1780672966; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Q6+n1EmGX8LN63Z4anqIdaVWAERyoiS1nCbOH+oHEB0=; b=RsmlxjUXa8lJXb8CBlDIi8dBzAiFzXe9w0ddGavcdJDrskhjshkkQTH0cN33LZLBFe tf/K2dnD05iU6M0MSF2O7XBBC0QB4iPfZrAWLqy25AlX2u1WGfS9zvDGNPbqRZ4uK0++ et2mz+/VVOAsPFBXpk37ydgyuMy7oZyJKEHruzoLJM80EtK1eY7lsoD2wodBEDyvz5LX vccQ2Ous9R83APfFPVrIecbutmKQONeCMJ83lG7C7FodGLVJVVCvjZ+jTf7wigNtPFwx xGt/BCmhP5P1+TqLsfNHqrQd5JYXAC8HqLRzl1MAzUsY9zrKjozRx2vbfs0aQBQ1e+gi u0Jg== X-Forwarded-Encrypted: i=1; AFNElJ+ah2Si6/P3JkHr3khBK2n0sJcxVTAY0BDwjjzPWf7lsipHtGlTLw64EewHsuQ35a/gzG6Go4ykE1e5NIo=@vger.kernel.org X-Gm-Message-State: AOJu0YzTG3QgtxVyZY0+iQT3R3/q1YUVnimZjl//Mxnzm1eEmmxxbYIT jtN50yjneLK+YpAJ76KiOG3B4GDLrjGHT3T4pYKtOAadhZyjnWyIKr+ObAeRdmyQRig= X-Gm-Gg: Acq92OF28RxilEQo3OKPF6b4rIKYJWVrHTdPMMn58K+LhyacAk2dW8XCw+1bLx+NIyf uDtanzh6JRjDuTJ9YSFNBNWzEcafCgDyX6iSJJhv1vqdNWJ2T2uQnfVNw3mB+LJsP4COsGqJ9jw vKA8gwerykgHkBH3pOjRJgJsjWgZyEBbP5bAal7w4V6M0fpHA1yG8B5XLskX4SoQ8aPLq47DUI+ ifsOQfx1+nu99xv9aD8R7nxZsD01QCSHvvVZ3gAgQK2t7fJJpHuIQ3jbyheLTsTtSE8BuP7f6J0 OfVayvNtQmyh+0be5NYKl+iN1myxZGMrxnAewXMynzt29C+wccJnS58e2dWylYxhfLuSRRxG/TL pA7Fy18Y7t9qW6y9YMDWYmRKiD+2kkH0E3TX2qLjRqpGH8M7dABPuoE9yrVGF1Z14fvZcnZf99d T50fu4MUlXaDfij4dq8TxJw0oWzA== X-Received: by 2002:a05:600c:4f08:b0:48a:581c:ead with SMTP id 5b1f17b1804b1-490a290da24mr2045425e9.10.1780068166558; Fri, 29 May 2026 08:22:46 -0700 (PDT) Received: from pathway ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45ef3563cb9sm4270497f8f.29.2026.05.29.08.22.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 08:22:46 -0700 (PDT) Date: Fri, 29 May 2026 17:22:42 +0200 From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Steven Rostedt , Marcos Paulo de Souza , Chris Down , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 9/9] printk: Try enable preferred consoles only when there are any Message-ID: References: <20260423130015.85175-1-pmladek@suse.com> <20260423130015.85175-10-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=us-ascii Content-Disposition: inline In-Reply-To: <20260423130015.85175-10-pmladek@suse.com> On Thu 2026-04-23 15:00:14, Petr Mladek wrote: > try_enable_preferred_console() used to be always called because it > had several hidden effects, namely: > > - enabled Braille consoles which were ignored by "preferred_dev_console" > because they were not associated with /dev/console. > > - returned success when a console was pre-enabled using CON_ENABLED > flag. > > - 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. Remove > the last one so that try_enable_preferred_console() can be called only > when any non-Braille console is preferred. > > --- a/kernel/printk/printk.c > +++ b/kernel/printk/printk.c > @@ -4055,18 +4055,23 @@ static int try_enable_braille_console(struct console *newcon) > } > > /* 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 = 0; > > - if (console_call_setup(newcon, NULL) != 0) > - return; > + err = console_call_setup(newcon, NULL); > + if (err) > + return err; > > newcon->flags |= CON_ENABLED; > > if (newcon->device) > newcon->flags |= CON_CONSDEV; > + > + return 0; > } > > #define console_first() \ > @@ -4109,7 +4114,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 = try_enable_default_console(newcon); > + if (err != -ENOENT) > + return err; > } > } I am working on v3 and I realized that this is not enough. try_enable_preferred_console() is still called when there already was default console (the if-condition above failed). But it makes sense only when preferred_dev_console >= 0. I am going to go further and put it into "else" part. I'll actually invert the check and do: static int try_enable_console(struct console *newcon) { int err; /* * 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 = try_enable_braille_console(newcon); if (err != -ENOENT) return err; } 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); if (err != -ENOENT) return err; } } /* * Some consoles, such as pstore and netconsole, can be enabled even * without matching. Accept them at this stage when they had a chance * to match() and call setup(). */ if (newcon->flags & CON_ENABLED) err = 0; return err; } I am going to split this into two patches: 1. Invert the logic and add the "else" part. This should not change the behavior at this stage. 2. Add the return value for try_enabled_default_console() and return immediately on success or error. It might actually change the behavior because pre-enabled console won't be registered when newcon->setup() failed. Best Regards, Petr