From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 C0CF1361DD0 for ; Tue, 5 May 2026 17:56:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778003771; cv=none; b=FT+QmzaSSoy328ahknT5sJYeCnWTKszOzkkXBi60gBFGxIXmNtXlq6M2tEjjOj6DkshJMc5Wp+OLL8cHBk/soAVNXAzRYo9o5/kXaVeUMXcONQ5yNlxfME70DrPcOMB3GVsMWjABrecWv+BRCAGTk4F7lJ3etmFVMGGtMIjvB9A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778003771; c=relaxed/simple; bh=1M5gO3ht3k6ulwoecyQ+Qvt2AjNkLyoHzXrAst+lWcY=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=nk6BuCeK6u5zaGgupl3ZzPPfRA2syb3rBLIIS3tCVt64WB8nni/pbNn5PY5g5wwPCUYJUV/Id0hXFlO+OvUvupvM0Tt9VqL1pmRl8M39HgB4meHSMwUnaaZTNL7yN8jBtCVm1LphzVmY4Q50cj9DqQOW2mDtLbEGo+VPOv/rVgw= 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=X7CxEhP0; arc=none smtp.client-ip=209.85.128.42 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="X7CxEhP0" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-48909558b3aso60599655e9.0 for ; Tue, 05 May 2026 10:56:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1778003768; x=1778608568; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:autocrypt :references:in-reply-to:date:cc:to:from:subject:message-id:from:to :cc:subject:date:message-id:reply-to; bh=iVTTEwn3WqcNHNzNMPDPQMVkRXNP8jpAJ2cOyWcrjmA=; b=X7CxEhP0l08GucIBDNjXabtj/ux6+DuPYM0fEQmPz949awOy+VfsFW/jdicgOUT6CB iTr3kzF+8aq9F0dZ0FV3QbU9y+KmeklZenq7P63DhZsa7gcCOQiNJJd4V7mRkod2yw2S p1SShMBH6i+fhW9ydw5+ZVQ1PYCEDsy5IQfkAnQ9Zqku9iZxufOH+zTcdyCKPEM8TNw8 e78HnBGMPuQ0Vnvu2mG/69m/gHs8o0Xxit5A6B9HjnTQtKtsNLmIRpHNl0SWhiK9gyYp orLmvBy4Pid9vqiZ/plHMgQ2+UVFx4eSLx/LH/o09BkCEOm3d1X14s9mFuTTZBrj4gw6 O90Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778003768; x=1778608568; h=mime-version:user-agent:content-transfer-encoding:autocrypt :references:in-reply-to:date:cc:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=iVTTEwn3WqcNHNzNMPDPQMVkRXNP8jpAJ2cOyWcrjmA=; b=msxf2Mp1EWMWhT5JMZokq0qxuNzLcA9T8JePi9lOC7WwVCc60kWFqf/95c6NlG2GZg hL3Gfh3eN+Z5NbZrLRUfqhjgsLmIuOkWMAJRRAoAno/zzbN1eVIaQloilB/CvJBkxayE MMymiH0JprJKxSO9s3C4MpBKpkMGjZ8ifLgySI8rWNWEfkZBI1afOThDDSj4ZunudPql t4zvw/px2lw8JHBk06UYOw19rWylPuZxJDkDYSFoR4RlrImGwliuwMtjNqLR0XGE0WXW VqZcLaJMF6AemnHf8S9O5ItgddOudZUR91iXOMpqNKZm5yiqXPphqTN/vxlA84JaBbry foYQ== X-Forwarded-Encrypted: i=1; AFNElJ9YHZUhoSbBiPjRE1jYB0JalSxCzlkah5zV5Q2C6XyXC3acsgYt+QmzK161w8LDzwIGQ+EuF1hFmjaqDsk=@vger.kernel.org X-Gm-Message-State: AOJu0YzcaQt+JJKguFczTsifbuKGUzh2SuTR6U55n/TlKBsIzmUsab4u wpS/DdxlpUylXaj0+4ruRCzKtVHEL9D/H37J5HYEEeJq4R63Xgvsk3xAyOdLQKf/JWk= X-Gm-Gg: AeBDiesd0pGHkL4LavqQbti8E/hZKdDbx0dkraN63+5SWFRegstkup1l0T3DrDwkahH dwjDhPY2IxSmINsEaGALLLaVCfB5BLKHHA62ZiK8BUXdZxbWspwHJt5Wj4jW9MXs3Hq3eX+0pF+ oVBAydzkSiD9RxOVE8dTt80JG8ePpWaodysc9k9PnIza/CEi9TJ7NjGcIh10R+w/qQIJMeCbmXa 1PbT078Q9MLc7+A3RzsoRqe6liLoLRqB4Cc58vgbMkTdx8Re9kyAACuNTawVVdRveV1OOHq5jQb WPmOuO9frys+ghYNcVJYol0pd6zP08v9zNriItOnLXxmiMPfTZlflpe4UMz6Hg0WOPtchrj+YYB hFEbhTaGQyd228h9YNfx29BTtIRjuI4rd4DsgEhB7MDRBWe/hSMXP03PECqCB5tmie4XRdkHxpR 2yGHk0GkFUujeRBEzgBh24lix/Hxg8zVqUBdfBtXt8YWG8kvkS1Z/txHPWMljDw+MGO0dU+u17z qiIPw== X-Received: by 2002:a05:600c:3b0f:b0:48a:7965:b943 with SMTP id 5b1f17b1804b1-48e51f4e9admr3786745e9.29.1778003767974; Tue, 05 May 2026 10:56:07 -0700 (PDT) Received: from ?IPv6:2804:1bc4:224:7800:585c:db3a:fcb:e21f? ([2804:1bc4:224:7800:585c:db3a:fcb:e21f]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a820c865esm406330555e9.5.2026.05.05.10.56.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2026 10:56:07 -0700 (PDT) Message-ID: <2a0aea8414c505058ef290d4530aae48475b11b8.camel@suse.com> Subject: Re: [PATCH v2 5/9] printk: Separate code for enabling console From: Marcos Paulo de Souza To: Petr Mladek , John Ogness Cc: Sergey Senozhatsky , Steven Rostedt , Chris Down , linux-kernel@vger.kernel.org Date: Tue, 05 May 2026 14:56:01 -0300 In-Reply-To: <20260423130015.85175-6-pmladek@suse.com> References: <20260423130015.85175-1-pmladek@suse.com> <20260423130015.85175-6-pmladek@suse.com> Autocrypt: addr=mpdesouza@suse.com; prefer-encrypt=mutual; keydata=mDMEZ/0YqhYJKwYBBAHaRw8BAQdA4JZz0FED+JD5eKlhkNyjDrp6lAGmgR3LPTduPYGPT Km0Kk1hcmNvcyBQYXVsbyBkZSBTb3V6YSA8bXBkZXNvdXphQHN1c2UuY29tPoiTBBMWCgA7FiEE2g gC66iLbhUsCBoBemssEuRpLLUFAmf9GKoCGwMFCwkIBwICIgIGFQoJCAsCBBYCAwECHgcCF4AACgk QemssEuRpLLWGxwD/S1I0bjp462FlKb81DikrOfWbeJ0FOJP44eRzmn20HmEBALBZIMrfIH2dJ5eM GO8seNG8sYiP6JfRjl7Hyqca6YsE Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.60.1 (by Flathub.org) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Thu, 2026-04-23 at 15:00 +0200, Petr Mladek wrote: > There are several code paths which try to enable a newly registered > console. Move the logic into a separate try_enable_console() > function. >=20 > It simplifies a bit the long register_console() function definition. >=20 > 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. >=20 > The patch does not change the existing behavior. >=20 > Signed-off-by: Petr Mladek Acked-by: Marcos Paulo de Souza > --- > =C2=A0kernel/printk/printk.c | 64 ++++++++++++++++++++++++---------------= - > -- > =C2=A01 file changed, 36 insertions(+), 28 deletions(-) >=20 > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c > index 7a3bbb0cb794..2543c810efcb 100644 > --- a/kernel/printk/printk.c > +++ b/kernel/printk/printk.c > @@ -4040,6 +4040,41 @@ static void try_enable_default_console(struct > console *newcon) > =C2=A0 newcon->flags |=3D CON_CONSDEV; > =C2=A0} > =C2=A0 > +#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 || > + =C2=A0=C2=A0=C2=A0 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) */ > + return try_enable_preferred_console(newcon, false); > +} > + > =C2=A0/* Return the starting sequence number for a newly registered > console. */ > =C2=A0static u64 get_init_console_seq(struct console *newcon, bool > bootcon_registered) > =C2=A0{ > @@ -4114,9 +4149,6 @@ static u64 get_init_console_seq(struct console > *newcon, bool bootcon_registered) > =C2=A0 return init_seq; > =C2=A0} > =C2=A0 > -#define console_first() \ > - hlist_entry(console_list.first, struct console, node) > - > =C2=A0static int unregister_console_locked(struct console *console); > =C2=A0 > =C2=A0/* > @@ -4178,31 +4210,7 @@ void register_console(struct console *newcon) > =C2=A0 goto unlock; > =C2=A0 } > =C2=A0 > - /* > - * 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 || > - =C2=A0=C2=A0=C2=A0 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); > + err =3D try_enable_console(newcon); > =C2=A0 > =C2=A0 /* printk() messages are not printed to the Braille console. > */ > =C2=A0 if (err || newcon->flags & CON_BRL) {