From: John Ogness <john.ogness@linutronix.de>
To: Marcos Paulo de Souza <mpdesouza@suse.com>,
Petr Mladek <pmladek@suse.com>,
Steven Rostedt <rostedt@goodmis.org>,
Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: linux-kernel@vger.kernel.org, marcos@mpdesouza.com,
Marcos Paulo de Souza <mpdesouza@suse.com>
Subject: Re: [PATCH] printk: nbcon: Check for device_{lock,unlock} callbacks
Date: Mon, 08 Dec 2025 10:21:09 +0106 [thread overview]
Message-ID: <87ecp5wd0i.fsf@jogness.linutronix.de> (raw)
In-Reply-To: <20251205-nbcon-device-cb-fix-v1-1-906bdff5760b@suse.com>
On 2025-12-05, Marcos Paulo de Souza <mpdesouza@suse.com> wrote:
> These callbacks are necessary to synchronize ->write_thread callback
> against other operations using the same device.
>
> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
> ---
> I found this issue while creating a custom kernel module that implements
> the nbcon interfaces.
> ---
> kernel/printk/nbcon.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
> index 3fa403f9831f..02809c44d7ea 100644
> --- a/kernel/printk/nbcon.c
> +++ b/kernel/printk/nbcon.c
> @@ -1764,6 +1764,10 @@ bool nbcon_alloc(struct console *con)
> if (WARN_ON(!con->write_thread))
> return false;
>
> + /* The device_lock() and device_unlock() callbacks are mandatory. */
> + if (WARN_ON(!con->device_lock || !con->device_unlock))
> + return false;
> +
The code itself is fine and this is an important contribution. But I
would prefer to combine it with the previous mandatory check. So it
looks more like this:
diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
index 3fa403f9831f..f096282b0625 100644
--- a/kernel/printk/nbcon.c
+++ b/kernel/printk/nbcon.c
@@ -1760,9 +1758,12 @@ bool nbcon_alloc(struct console *con)
/* Synchronize the kthread start. */
lockdep_assert_console_list_lock_held();
- /* The write_thread() callback is mandatory. */
- if (WARN_ON(!con->write_thread))
+ /* Check for mandatory nbcon callbacks. */
+ if (WARN_ON(!con->write_thread ||
+ !con->device_lock ||
+ !con->device_unlock)) {
return false;
+ }
rcuwait_init(&con->rcuwait);
init_irq_work(&con->irq_work, nbcon_irq_work);
John Ogness
next prev parent reply other threads:[~2025-12-08 9:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-05 18:34 [PATCH] printk: nbcon: Check for device_{lock,unlock} callbacks Marcos Paulo de Souza
2025-12-08 9:15 ` John Ogness [this message]
2025-12-08 13:30 ` Petr Mladek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ecp5wd0i.fsf@jogness.linutronix.de \
--to=john.ogness@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=marcos@mpdesouza.com \
--cc=mpdesouza@suse.com \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox