[PATCH] tty: n_null: remove legacy BUG_ON() from module initialization
From: Bramwel Barack
Date: Sun Nov 08 2026 - 07:51:53 EST
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@xxxxxxxxx>
---
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