From nobody Tue Feb 10 15:44:29 2026 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 423B5314A90 for ; Sat, 27 Dec 2025 12:17:16 +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=1766837840; cv=none; b=hJAQXcbVxbSjgeZ/GdTQYHHg+pECkU0aEvivRNxquDX+SfykR9AdwPLMtUJsEKx7QXmfqVXbvnUl6EdjrD8Abb75SybWsQ39SUN5lKl61moH8IhC8ra5poj+nJirghVFAGV+7B1K9sF6AelXqvRmtS6i0DcOw5muoaSFAfvVRJs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766837840; c=relaxed/simple; bh=vcl36sWudeP+4+BFFAGNAn9YWtzCJyjmd2BzAWTnD/U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GU2gYFYpkE2EgTM31R5Tcc8PgG32SLAc6OJiUJWvKJFNiFZAraqK1iqpp1ZWUuM53xNX3UIg649fSIaIy5/zp9SnFm2s7tvQVJRt8Cojc2g+TgVUzqUoU9/3Oox+N554iLcreTm9H3n/1KZ7Kwwag4D1fINOTo3ejjwlVSf0mnk= 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=NXWK6S0A; 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="NXWK6S0A" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-47775fb6c56so59040795e9.1 for ; Sat, 27 Dec 2025 04:17:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1766837835; x=1767442635; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=uTPebJjNeKwkChbLQ9kmEHnfHiLVqL0OXrUmcfcwYxQ=; b=NXWK6S0ACaSgQaSFIonroOyyns/rivmpoluuxUW/K9Zi41lIb3jtECLiSX5c5qrZjf wqqyIr5VBK7CKSGBktMRkJY3bQs9W7yURvjPpVLUTIpALUUfB+x1A57I9PiJMNgzUzbu awDSS40GPWbiEJ2xZq1Fa2mkqbSeCF89UTLwJF6+uN87wIV+Og7lHMIY8u6IYCNB25zF anEun/A6wUP7bpF9FO2eD+aRABRDQXPncxnyc5Wkphp5jEIzWSZYkY9/AvKubpKgWQ+h fFBE8k9dJZ4W6HqDsio5QTPvIB5Bm4rkT87osuIRyye4YVNZIqkLUbXD5DwCn1LbXAyD nTGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766837835; x=1767442635; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=uTPebJjNeKwkChbLQ9kmEHnfHiLVqL0OXrUmcfcwYxQ=; b=shdDTYylqSNOGVvitqpQ7PpmemqI/e613s2JHKgp4+Cv8sotm9tgHQjv0RXgCCMG1E Zlj3Ct7F5l3jou0KkikKqAZYHa5w0m+g9uvRBxHHuSoZzBeawniLzc8tQ6hosrw/kLAh xhJqWLJ6XSBtMllzbgURDQ7mCr/Z3joh0NvDMoN+iapiuwcjMlLzm2CqopNAlJv8QE8m UX5hgKtt7Y9MNsITKXm1hgTwYq2WijQ8kpujt+QIuLdFpjdugqLM5P9kvu6HyTB/tBZ7 VJ4smfjhS5ky/PX7k/Fxb+3ihQUf5w7xW2zMC+kSPh4qtRKtMNAqvoa+TQ2gffSzkqmP W5Ug== X-Forwarded-Encrypted: i=1; AJvYcCUv3/gAoD18F7HXXSNIecLDS1bksfWqxxaVxtIJGsalgJK3P5KQ8I2sUyPV/KrNSXMHdmErvYoEDm9ehVQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyLv8h19Bwa426ci5Ykcf+OrWXit3OAqLiPJZmnOJMIO1CqZBkJ SGxeJOtoznqb1KC2hb/pbEtjZAUO7adlnwQLtdh1lvN9fm1nUTOptm9pHSKegSxg5zk= X-Gm-Gg: AY/fxX4fPmnWBTtNHsSkzudkjAyjb9/BvuRLgbaBpdNoS1f9EoRjBtMlRLJ6EOb3ouY UF5YfpKlJoQ/llv1wnaZMf7EPIcKX/mNZEmnTXwkH/j0GWXvqOwEFAQCg2Z9kKphj3tcT2dPbwF WKWBPmH2R4FwK3c4ih5Vn8HXvvZiD7dFx947EyLZ4gTMv3hfimkE2OsLOz+Bj0FDIZ/o17p2rfw 5q+m3/gMzgrrGMMbxhJ5AntUIR+BDUeANOoYKq2qMblJhnFMRi3tpRFNbEDuQeXi22d212BHGvG yc0ogZp/Rm4fQDokAkjy1OKrbY8j+74E2B8djonrEhnHUC/6I/CBQQogld+WP1gNbMKBe3M2UT5 y/+hRuvf8rWOOpwCjaOuUVSeyBSVLMv/si3O+5QyDvTaDEoaTAwKW4aIGdHy6tyfXzlLA03xRqK NYJbNTheAgJIDRnesKa0s= X-Google-Smtp-Source: AGHT+IGwp3EjluLXDesoC0JEyXRGphsbQ8YoWlvkj2Od8DQXEn5G/ySQT/x4pqGRl4etLgLjbGQKkA== X-Received: by 2002:a05:600c:1912:b0:477:89d5:fdac with SMTP id 5b1f17b1804b1-47d1959f714mr329425925e9.31.1766837835139; Sat, 27 Dec 2025 04:17:15 -0800 (PST) Received: from [127.0.0.1] ([2804:5078:811:d400:58f2:fc97:371f:2]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-121724cfdd0sm97940127c88.4.2025.12.27.04.17.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Dec 2025 04:17:14 -0800 (PST) From: Marcos Paulo de Souza Date: Sat, 27 Dec 2025 09:16:10 -0300 Subject: [PATCH 03/19] printk: Drop flags argument from console_is_usable 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 Message-Id: <20251227-printk-cleanup-part3-v1-3-21a291bcf197@suse.com> References: <20251227-printk-cleanup-part3-v1-0-21a291bcf197@suse.com> In-Reply-To: <20251227-printk-cleanup-part3-v1-0-21a291bcf197@suse.com> To: Richard Weinberger , Anton Ivanov , Johannes Berg , Greg Kroah-Hartman , Jason Wessel , Daniel Thompson , Douglas Anderson , Petr Mladek , Steven Rostedt , John Ogness , Sergey Senozhatsky , Jiri Slaby , Breno Leitao , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Geert Uytterhoeven , Kees Cook , Tony Luck , "Guilherme G. Piccoli" , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Andreas Larsson , Alexander Shishkin , Maxime Coquelin , Alexandre Torgue , Jacky Huang , Shan-Chun Hung , Laurentiu Tudor Cc: linux-um@lists.infradead.org, linux-kernel@vger.kernel.org, kgdb-bugreport@lists.sourceforge.net, linux-serial@vger.kernel.org, netdev@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-hardening@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, sparclinux@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-fsdevel@vger.kernel.org, Marcos Paulo de Souza X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1766837798; l=9456; i=mpdesouza@suse.com; s=20231031; h=from:subject:message-id; bh=vcl36sWudeP+4+BFFAGNAn9YWtzCJyjmd2BzAWTnD/U=; b=iD+souMtKfrrqeYTmzgK7GoB+YnYwBZz+b3u1u3z79Hjhj/LyjffFTb6T+KYy3fwP+rT9y9HK hjNxNGyaArtAX5IV24Lh1tykQ434DvLfReICQgaATUhSR+uxoFOqy3O X-Developer-Key: i=mpdesouza@suse.com; a=ed25519; pk=/Ni/TsKkr69EOmdZXkp1Q/BlzDonbOBRsfPa18ySIwU= The flags argument was also used to check if CON_NBCON was set, but their usage was fixed in the last commit. All current users are reading the variable just to call console_is_usable. By calling console_srcu_read_flags inside console_is_usable makes the code cleaner and removes one argument from the function. Along with it, create a variant called __console_is_usable that can be used under console_list_lock(), like unregister_console_locked. Signed-off-by: Marcos Paulo de Souza --- arch/um/kernel/kmsg_dump.c | 3 +-- include/linux/console.h | 25 +++++++++++++++++-------- kernel/debug/kdb/kdb_io.c | 4 +--- kernel/printk/nbcon.c | 15 ++++----------- kernel/printk/printk.c | 20 +++++++------------- 5 files changed, 30 insertions(+), 37 deletions(-) diff --git a/arch/um/kernel/kmsg_dump.c b/arch/um/kernel/kmsg_dump.c index 8ae38308b67c..ca80232cfa2a 100644 --- a/arch/um/kernel/kmsg_dump.c +++ b/arch/um/kernel/kmsg_dump.c @@ -31,8 +31,7 @@ static void kmsg_dumper_stdout(struct kmsg_dumper *dumper, * expected to output the crash information. */ if (strcmp(con->name, "ttynull") !=3D 0 && - console_is_usable(con, console_srcu_read_flags(con), - NBCON_USE_ATOMIC)) { + console_is_usable(con, NBCON_USE_ATOMIC)) { break; } } diff --git a/include/linux/console.h b/include/linux/console.h index dd4ec7a5bff9..648cf10e3f93 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -656,13 +656,8 @@ extern bool nbcon_kdb_try_acquire(struct console *con, struct nbcon_write_context *wctxt); extern void nbcon_kdb_release(struct nbcon_write_context *wctxt); =20 -/* - * Check if the given console is currently capable and allowed to print - * records. Note that this function does not consider the current context, - * which can also play a role in deciding if @con can be used to print - * records. - */ -static inline bool console_is_usable(struct console *con, short flags, +/* Variant of console_is_usable() when the console_list_lock is held. */ +static inline bool __console_is_usable(struct console *con, short flags, enum nbcon_write_cb nwc) { if (!(flags & CON_ENABLED)) @@ -707,6 +702,18 @@ static inline bool console_is_usable(struct console *c= on, short flags, return true; } =20 +/* + * Check if the given console is currently capable and allowed to print + * records. Note that this function does not consider the current context, + * which can also play a role in deciding if @con can be used to print + * records. + */ +static inline bool console_is_usable(struct console *con, + enum nbcon_write_cb nwc) +{ + return __console_is_usable(con, console_srcu_read_flags(con), nwc); +} + #else static inline void nbcon_cpu_emergency_enter(void) { } static inline void nbcon_cpu_emergency_exit(void) { } @@ -719,7 +726,9 @@ static inline void nbcon_reacquire_nobuf(struct nbcon_w= rite_context *wctxt) { } static inline bool nbcon_kdb_try_acquire(struct console *con, struct nbcon_write_context *wctxt) { return false; } static inline void nbcon_kdb_release(struct nbcon_write_context *wctxt) { } -static inline bool console_is_usable(struct console *con, short flags, +static inline bool __console_is_usable(struct console *con, short flags, + enum nbcon_write_cb nwc) { return false; } +static inline bool console_is_usable(struct console *con, enum nbcon_write_cb nwc) { return false; } #endif =20 diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index d6de512b433a..642eab746577 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -589,9 +589,7 @@ static void kdb_msg_write(const char *msg, int msg_len) */ cookie =3D console_srcu_read_lock(); for_each_console_srcu(c) { - short flags =3D console_srcu_read_flags(c); - - if (!console_is_usable(c, flags, NBCON_USE_ATOMIC)) + if (!console_is_usable(c, NBCON_USE_ATOMIC)) continue; if (c =3D=3D dbg_io_ops->cons) continue; diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index f0f42e212caa..f0659c1e50ed 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -1164,7 +1164,6 @@ static bool nbcon_emit_one(struct nbcon_write_context= *wctxt, bool use_atomic) static bool nbcon_kthread_should_wakeup(struct console *con, struct nbcon_= context *ctxt) { bool ret =3D false; - short flags; int cookie; =20 if (kthread_should_stop()) @@ -1183,8 +1182,7 @@ static bool nbcon_kthread_should_wakeup(struct consol= e *con, struct nbcon_contex =20 cookie =3D console_srcu_read_lock(); =20 - flags =3D console_srcu_read_flags(con); - if (console_is_usable(con, flags, NBCON_USE_THREAD)) { + if (console_is_usable(con, NBCON_USE_THREAD)) { /* Bring the sequence in @ctxt up to date */ ctxt->seq =3D nbcon_seq_read(con); =20 @@ -1209,7 +1207,6 @@ static int nbcon_kthread_func(void *__console) .ctxt.prio =3D NBCON_PRIO_NORMAL, }; struct nbcon_context *ctxt =3D &ACCESS_PRIVATE(&wctxt, ctxt); - short con_flags; bool backlog; int cookie; =20 @@ -1249,9 +1246,7 @@ static int nbcon_kthread_func(void *__console) */ cookie =3D console_srcu_read_lock(); =20 - con_flags =3D console_srcu_read_flags(con); - - if (console_is_usable(con, con_flags, NBCON_USE_THREAD)) + if (console_is_usable(con, NBCON_USE_THREAD)) backlog =3D nbcon_emit_one(&wctxt, false); =20 console_srcu_read_unlock(cookie); @@ -1645,12 +1640,10 @@ static void __nbcon_atomic_flush_pending(u64 stop_s= eq) =20 cookie =3D console_srcu_read_lock(); for_each_console_srcu(con) { - short flags =3D console_srcu_read_flags(con); - if (!console_is_nbcon(con)) continue; =20 - if (!console_is_usable(con, flags, NBCON_USE_ATOMIC)) + if (!console_is_usable(con, NBCON_USE_ATOMIC)) continue; =20 if (nbcon_seq_read(con) >=3D stop_seq) @@ -1904,7 +1897,7 @@ void nbcon_device_release(struct console *con) */ cookie =3D console_srcu_read_lock(); printk_get_console_flush_type(&ft); - if (console_is_usable(con, console_srcu_read_flags(con), NBCON_USE_ATOMIC= ) && + if (console_is_usable(con, NBCON_USE_ATOMIC) && !ft.nbcon_offload && prb_read_valid(prb, nbcon_seq_read(con), NULL)) { /* diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index bd0d574be3cf..b03ffc23c27c 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3191,7 +3191,6 @@ static bool console_flush_one_record(bool do_cond_res= ched, u64 *next_seq, bool * =20 cookie =3D console_srcu_read_lock(); for_each_console_srcu(con) { - short flags =3D console_srcu_read_flags(con); u64 printk_seq; bool progress; =20 @@ -3203,9 +3202,8 @@ static bool console_flush_one_record(bool do_cond_res= ched, u64 *next_seq, bool * if (console_is_nbcon(con) && (ft.nbcon_atomic || ft.nbcon_offload)) continue; =20 - if (!console_is_usable(con, flags, - do_cond_resched ? NBCON_USE_THREAD - : NBCON_USE_ATOMIC)) + if (!console_is_usable(con, do_cond_resched ? NBCON_USE_THREAD + : NBCON_USE_ATOMIC)) continue; any_usable =3D true; =20 @@ -3394,7 +3392,7 @@ void console_unblank(void) */ cookie =3D console_srcu_read_lock(); for_each_console_srcu(c) { - if (!console_is_usable(c, console_srcu_read_flags(c), NBCON_USE_ATOMIC)) + if (!console_is_usable(c, NBCON_USE_ATOMIC)) continue; =20 if (c->unblank) { @@ -3434,7 +3432,7 @@ void console_unblank(void) =20 cookie =3D console_srcu_read_lock(); for_each_console_srcu(c) { - if (!console_is_usable(c, console_srcu_read_flags(c), NBCON_USE_ATOMIC)) + if (!console_is_usable(c, NBCON_USE_ATOMIC)) continue; =20 if (c->unblank) @@ -3621,7 +3619,6 @@ static bool legacy_kthread_should_wakeup(void) =20 cookie =3D console_srcu_read_lock(); for_each_console_srcu(con) { - short flags =3D console_srcu_read_flags(con); u64 printk_seq; =20 /* @@ -3632,7 +3629,7 @@ static bool legacy_kthread_should_wakeup(void) if (console_is_nbcon(con) && (ft.nbcon_atomic || ft.nbcon_offload)) continue; =20 - if (!console_is_usable(con, flags, NBCON_USE_THREAD)) + if (!console_is_usable(con, NBCON_USE_THREAD)) continue; =20 if (console_is_nbcon(con)) { @@ -4203,7 +4200,7 @@ static int unregister_console_locked(struct console *= console) =20 if (!console_is_registered_locked(console)) res =3D -ENODEV; - else if (console_is_usable(console, console->flags, NBCON_USE_ATOMIC)) + else if (__console_is_usable(console, console->flags, NBCON_USE_ATOMIC)) __pr_flush(console, 1000, true); =20 /* Disable it unconditionally */ @@ -4430,7 +4427,6 @@ static bool __pr_flush(struct console *con, int timeo= ut_ms, bool reset_on_progre struct console *c; u64 last_diff =3D 0; u64 printk_seq; - short flags; int cookie; u64 diff; u64 seq; @@ -4477,14 +4473,12 @@ static bool __pr_flush(struct console *con, int tim= eout_ms, bool reset_on_progre if (con && con !=3D c) continue; =20 - flags =3D console_srcu_read_flags(c); - /* * If consoles are not usable, it cannot be expected * that they make forward progress, so only increment * @diff for usable consoles. */ - if (!console_is_usable(c, flags, NBCON_USE_ANY)) + if (!console_is_usable(c, NBCON_USE_ANY)) continue; =20 if (console_is_nbcon(c)) { --=20 2.52.0