* [PATCH] tty: don't crash in tty_init_dev when missing tty_port
@ 2019-11-22 10:17 Jiri Slaby
2019-11-25 8:06 ` Geert Uytterhoeven
0 siblings, 1 reply; 2+ messages in thread
From: Jiri Slaby @ 2019-11-22 10:17 UTC (permalink / raw)
To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby, Sudip Mukherjee
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 <jslaby@suse.cz>
Cc: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
---
drivers/tty/tty_io.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index cb6370906a6d..d9f54c7d94f2 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -1345,9 +1345,12 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx)
if (!tty->port)
tty->port = driver->ports[idx];
- WARN_RATELIMIT(!tty->port,
- "%s: %s driver does not set tty->port. This will crash the kernel later. Fix the driver!\n",
- __func__, tty->driver->name);
+ if (WARN_RATELIMIT(!tty->port,
+ "%s: %s driver does not set tty->port. This would crash the kernel. Fix the driver!\n",
+ __func__, tty->driver->name)) {
+ retval = -EINVAL;
+ goto err_release_lock;
+ }
retval = tty_ldisc_lock(tty, 5 * HZ);
if (retval)
--
2.24.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] tty: don't crash in tty_init_dev when missing tty_port
2019-11-22 10:17 [PATCH] tty: don't crash in tty_init_dev when missing tty_port Jiri Slaby
@ 2019-11-25 8:06 ` Geert Uytterhoeven
0 siblings, 0 replies; 2+ messages in thread
From: Geert Uytterhoeven @ 2019-11-25 8:06 UTC (permalink / raw)
To: Jiri Slaby
Cc: Greg KH, open list:SERIAL DRIVERS, Linux Kernel Mailing List,
Sudip Mukherjee
Hi Jiri,
On Fri, Nov 22, 2019 at 11:20 AM Jiri Slaby <jslaby@suse.cz> wrote:
> 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.
As per Greg's comment on another patch in
https://lore.kernel.org/lkml/20191121135743.GA552517@kroah.com/,
that will still cause systems with panic-on-warn to reboot.
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> Cc: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
> ---
> drivers/tty/tty_io.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
> index cb6370906a6d..d9f54c7d94f2 100644
> --- a/drivers/tty/tty_io.c
> +++ b/drivers/tty/tty_io.c
> @@ -1345,9 +1345,12 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx)
> if (!tty->port)
> tty->port = driver->ports[idx];
>
> - WARN_RATELIMIT(!tty->port,
> - "%s: %s driver does not set tty->port. This will crash the kernel later. Fix the driver!\n",
> - __func__, tty->driver->name);
> + if (WARN_RATELIMIT(!tty->port,
> + "%s: %s driver does not set tty->port. This would crash the kernel. Fix the driver!\n",
> + __func__, tty->driver->name)) {
> + retval = -EINVAL;
> + goto err_release_lock;
> + }
>
> retval = tty_ldisc_lock(tty, 5 * HZ);
> if (retval)
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-11-25 8:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-22 10:17 [PATCH] tty: don't crash in tty_init_dev when missing tty_port Jiri Slaby
2019-11-25 8:06 ` Geert Uytterhoeven
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).