* [PATCH] tty: n_null: remove legacy BUG_ON() from module initialization
@ 2026-11-08 12:50 Bramwel Barack
2026-11-08 13:43 ` Greg KH
0 siblings, 1 reply; 2+ messages in thread
From: Bramwel Barack @ 2026-11-08 12:50 UTC (permalink / raw)
To: gregkh, jirislaby; +Cc: linux-kernel, linux-serial, Bramwel Barack
The use of BUG_ON() in module initialization paths is heavily deprecated
as it triggers a kernel panic and crashes the entire system for non-fatal
registration failures. If tty_register_ldisc() fails (e.g., if the slot
is already occupied), it should be handled gracefully.
Modernize the initialization path by capturing the return value of
tty_register_ldisc(), logging a clean error message via pr_err(), and
propagating the error code back up to the module loader.
Signed-off-by: Bramwel Barack <bramwelbarack89@gmail.com>
---
drivers/tty/n_null.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/tty/n_null.c b/drivers/tty/n_null.c
index 5a429d923eb3..886f6789f872 100644
--- a/drivers/tty/n_null.c
+++ b/drivers/tty/n_null.c
@@ -32,7 +32,14 @@ static struct tty_ldisc_ops null_ldisc = {
static int __init n_null_init(void)
{
- BUG_ON(tty_register_ldisc(&null_ldisc));
+ int ret;
+
+ ret = tty_register_ldisc(&null_ldisc);
+ if (ret) {
+ pr_err("n_null: failed to register line discipline (%d)\n", ret);
+ return ret;
+ }
+
return 0;
}
--
2.56.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] tty: n_null: remove legacy BUG_ON() from module initialization
2026-11-08 12:50 [PATCH] tty: n_null: remove legacy BUG_ON() from module initialization Bramwel Barack
@ 2026-11-08 13:43 ` Greg KH
0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2026-11-08 13:43 UTC (permalink / raw)
To: Bramwel Barack; +Cc: jirislaby, linux-kernel, linux-serial
On Sun, Nov 08, 2026 at 03:50:31PM +0300, Bramwel Barack wrote:
> The use of BUG_ON() in module initialization paths is heavily deprecated
> as it triggers a kernel panic and crashes the entire system for non-fatal
> registration failures. If tty_register_ldisc() fails (e.g., if the slot
> is already occupied), it should be handled gracefully.
>
> Modernize the initialization path by capturing the return value of
> tty_register_ldisc(), logging a clean error message via pr_err(), and
> propagating the error code back up to the module loader.
Nice try, but no, this isn't going to work at all. Please test this by
actually testing if this code path can ever fail. (hint, look in the
mailing list archives...)
Why did you decide to make this change if you can't ever hit it?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-08 13:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-08 12:50 [PATCH] tty: n_null: remove legacy BUG_ON() from module initialization Bramwel Barack
2026-11-08 13:43 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®