2008-06-21 22:45:38

by Guennadi Liakhovetski

[permalink] [raw]
Subject: [PATCH] Fix serial_match_port() for dynamic major tty-device numbers

As reported by Vipul Gandhi, the current serial_match_port() doesn't work
for tty-devices using dynamic major number allocation. Fix it.

Signed-off-by: Guennadi Liakhovetski <[email protected]>
Tested-by: Vipul Gandhi <[email protected]>

---

diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c
index 0f5a179..593ae85 100644
--- a/drivers/serial/serial_core.c
+++ b/drivers/serial/serial_core.c
@@ -1949,7 +1949,9 @@ struct uart_match {
static int serial_match_port(struct device *dev, void *data)
{
struct uart_match *match = data;
- dev_t devt = MKDEV(match->driver->major, match->driver->minor) + match->port->line;
+ struct tty_driver *tty_drv = match->driver->tty_driver;
+ dev_t devt = MKDEV(tty_drv->major, tty_drv->minor_start) +
+ match->port->line;

return dev->devt == devt; /* Actually, only one tty per port */
}


2008-06-24 22:23:46

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH] Fix serial_match_port() for dynamic major tty-device numbers

On Sun, 22 Jun 2008 00:45:25 +0200 (CEST)
Guennadi Liakhovetski <[email protected]> wrote:

> As reported by Vipul Gandhi, the current serial_match_port() doesn't work
> for tty-devices using dynamic major number allocation. Fix it.
>
> Signed-off-by: Guennadi Liakhovetski <[email protected]>
> Tested-by: Vipul Gandhi <[email protected]>
>
> ---
>
> diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c
> index 0f5a179..593ae85 100644
> --- a/drivers/serial/serial_core.c
> +++ b/drivers/serial/serial_core.c
> @@ -1949,7 +1949,9 @@ struct uart_match {
> static int serial_match_port(struct device *dev, void *data)
> {
> struct uart_match *match = data;
> - dev_t devt = MKDEV(match->driver->major, match->driver->minor) + match->port->line;
> + struct tty_driver *tty_drv = match->driver->tty_driver;
> + dev_t devt = MKDEV(tty_drv->major, tty_drv->minor_start) +
> + match->port->line;
>
> return dev->devt == devt; /* Actually, only one tty per port */

Well that sounds bad. We need to work out whether this fix is needed
in 2.6.25 and possibly eariler.

What are the consequences of this error?

2008-06-24 22:54:53

by Guennadi Liakhovetski

[permalink] [raw]
Subject: Re: [PATCH] Fix serial_match_port() for dynamic major tty-device numbers

On Tue, 24 Jun 2008, Andrew Morton wrote:

> On Sun, 22 Jun 2008 00:45:25 +0200 (CEST)
> Guennadi Liakhovetski <[email protected]> wrote:
>
> > As reported by Vipul Gandhi, the current serial_match_port() doesn't work
> > for tty-devices using dynamic major number allocation. Fix it.
> >
> > Signed-off-by: Guennadi Liakhovetski <[email protected]>
> > Tested-by: Vipul Gandhi <[email protected]>
> >
> > ---
> >
> > diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c
> > index 0f5a179..593ae85 100644
> > --- a/drivers/serial/serial_core.c
> > +++ b/drivers/serial/serial_core.c
> > @@ -1949,7 +1949,9 @@ struct uart_match {
> > static int serial_match_port(struct device *dev, void *data)
> > {
> > struct uart_match *match = data;
> > - dev_t devt = MKDEV(match->driver->major, match->driver->minor) + match->port->line;
> > + struct tty_driver *tty_drv = match->driver->tty_driver;
> > + dev_t devt = MKDEV(tty_drv->major, tty_drv->minor_start) +
> > + match->port->line;
> >
> > return dev->devt == devt; /* Actually, only one tty per port */
>
> Well that sounds bad. We need to work out whether this fix is needed
> in 2.6.25 and possibly eariler.

Not earlier, this code is only there since 2.6.25.

> What are the consequences of this error?

It Oopses, if you suspend a serial port with _dynamic_ major number. ATM,
I think, there's only the drivers/serial/jsm/jsm_driver.c driver, that
does it in-tree.

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer