* problem in serial_ns16550.c
@ 2011-08-03 15:35 Antony Pavlov
2011-08-03 15:52 ` Sascha Hauer
2011-08-03 16:35 ` Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 2 replies; 4+ messages in thread
From: Antony Pavlov @ 2011-08-03 15:35 UTC (permalink / raw)
To: barebox
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
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: problem in serial_ns16550.c
2011-08-03 15:35 problem in serial_ns16550.c Antony Pavlov
@ 2011-08-03 15:52 ` Sascha Hauer
2011-08-03 16:38 ` Jean-Christophe PLAGNIOL-VILLARD
2011-08-03 16:35 ` Jean-Christophe PLAGNIOL-VILLARD
1 sibling, 1 reply; 4+ messages in thread
From: Sascha Hauer @ 2011-08-03 15:52 UTC (permalink / raw)
To: Antony Pavlov; +Cc: barebox
On Wed, Aug 03, 2011 at 07:35:18PM +0400, Antony Pavlov wrote:
> 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.
Ok, then we have to check for the existence of plat->reg_read/write
first. If the exist, we have to skip further IORESOURCE_MEM_xBIT checks.
If they don't exist we do whatever IORESOURCE_MEM_xBIT indicates.
That only leaves the problem that if a user registers a ns16550 driver
without reg_read/write and does not care about resource types either
the driver defaults to 8 bit mmio accesses, but I think we can live with
that.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: problem in serial_ns16550.c
2011-08-03 15:52 ` Sascha Hauer
@ 2011-08-03 16:38 ` Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 0 replies; 4+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-08-03 16:38 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On 17:52 Wed 03 Aug , Sascha Hauer wrote:
> On Wed, Aug 03, 2011 at 07:35:18PM +0400, Antony Pavlov wrote:
> > 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.
>
> Ok, then we have to check for the existence of plat->reg_read/write
> first. If the exist, we have to skip further IORESOURCE_MEM_xBIT checks.
> If they don't exist we do whatever IORESOURCE_MEM_xBIT indicates.
>
> That only leaves the problem that if a user registers a ns16550 driver
> without reg_read/write and does not care about resource types either
> the driver defaults to 8 bit mmio accesses, but I think we can live with
> that.
that was my idea at the beginning
Best Regards,
J.
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: problem in serial_ns16550.c
2011-08-03 15:35 problem in serial_ns16550.c Antony Pavlov
2011-08-03 15:52 ` Sascha Hauer
@ 2011-08-03 16:35 ` Jean-Christophe PLAGNIOL-VILLARD
1 sibling, 0 replies; 4+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-08-03 16:35 UTC (permalink / raw)
To: Antony Pavlov; +Cc: barebox
On 19:35 Wed 03 Aug , Antony Pavlov wrote:
> 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.
yeah we can drop the check simply
Best Regards,
J.
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-08-03 16:56 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-03 15:35 problem in serial_ns16550.c Antony Pavlov
2011-08-03 15:52 ` Sascha Hauer
2011-08-03 16:38 ` Jean-Christophe PLAGNIOL-VILLARD
2011-08-03 16:35 ` Jean-Christophe PLAGNIOL-VILLARD
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox