problem in serial_ns16550.c

Antony Pavlov antonynpavlov at gmail.com
Wed Aug 3 11:35:18 EDT 2011


Hi!

IMHO there is a problem in ns16550_probe() (see
drivers/serial/serial_ns16550.c:243).

There is the construction:
------
if (!(dev->resource[0].flags & IORESOURCE_MEM_TYPE_MASK) &&
            ((plat->reg_read == NULL) || (plat->reg_write == NULL)))
                return -EINVAL;
------

Imagine creation of typical serial port:
------
static struct NS16550_plat plat = {
        .clock = 1843200,
};

...

add_ns16550_device(-1, UART_ADDR, 8, IORESOURCE_MEM_8BIT, &plat);
------

Here we have plat.reg_read == NULL, plat.reg_write == NULL.
Usage of add_ns16550_device will make
dev->resource[0].flags & IORESOURCE_MEM_TYPE_MASK == IORESOURCE_MEM_8BIT.

But take into account this (see include/linux/ioport.h):
------
#define IORESOURCE_MEM_TYPE_MASK        (3<<3)
#define IORESOURCE_MEM_8BIT             (0<<3)
------

So IORESOURCE_MEM_8BIT == 0 (sic!)

A son tour, !(dev->resource[0].flags & IORESOURCE_MEM_TYPE_MASK) give
true, if flags select IORESOURCE_MEM_8BIT.

As a result, if add_ns16550_device() take IORESOURCE_MEM_8BIT, and
plat->reg_read == NULL, plat->reg_write == NULL then ns16550_probe()
will return -EINVAL.

-- 
Best regards,
  Antony Pavlov



More information about the barebox mailing list