Skip to content

Commit 2ae0b31

Browse files
Jiri Slabygregkh
authored andcommitted
tty: don't crash in tty_init_dev when missing tty_port
We currently warn the user when tty->port is not set in tty_init_dev yet. The warning says that the kernel will crash later. And it really will only few lines below at: tty->port->itty = tty; So be nice and avoid the crash -- return an error instead. And update the warning. Signed-off-by: Jiri Slaby <[email protected]> Cc: Sudip Mukherjee <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 1250ed7 commit 2ae0b31

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

drivers/tty/tty_io.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,9 +1344,12 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx)
13441344
if (!tty->port)
13451345
tty->port = driver->ports[idx];
13461346

1347-
WARN_RATELIMIT(!tty->port,
1348-
"%s: %s driver does not set tty->port. This will crash the kernel later. Fix the driver!\n",
1349-
__func__, tty->driver->name);
1347+
if (WARN_RATELIMIT(!tty->port,
1348+
"%s: %s driver does not set tty->port. This would crash the kernel. Fix the driver!\n",
1349+
__func__, tty->driver->name)) {
1350+
retval = -EINVAL;
1351+
goto err_release_lock;
1352+
}
13501353

13511354
retval = tty_ldisc_lock(tty, 5 * HZ);
13521355
if (retval)

0 commit comments

Comments
 (0)