Re: [RFC/PATCH] printk: Fix preferred console selection with multiple matches

From: Petr Mladek
Date: Wed Dec 11 2019 - 07:53:08 EST

On Wed 2019-12-11 15:02:02, Benjamin Herrenschmidt wrote:
> On Wed, 2019-12-11 at 11:01 +0900, Sergey Senozhatsky wrote:
> > On (19/12/11 09:26), Benjamin Herrenschmidt wrote:
> >
> > As far as I know, ->match() does not only match but also does ->setup().
> > If we have two console list entries that match (one via aliasing and one
> > via exact match) then the console driver is setup twice. Do all console
> > drivers handle it? [double setup]
> I don't think it's an issue but I may be wrong. I had a quick look
> at some of the drivers and I don't really see why they would break but
> I couldn't look at them all and I might be mistaken.
> We could skip setup if the console is already enabled but I would
> advise against that since the two calls might have different options
> (the firmware baud rate could be different from the command line one
> for example) and we want the options for the last one.

For example:

+ ip22zilog_console_setup() calls __ip22zilog_startup() that does
some initialization of the device

+ pl011_console_setup() does some non-trivial things as well.

Honestly, I am not familiar with these devices. I am not sure if it is
dangerous or safe to call these functions twice.

I am not sure if anybody would know this for sure. Therefore I suggest a
conservative approach and avoid calling setup() twice().

I think that it is dangerous and error-prone design. The best solution
would be to split setup() and match() functionality.

Best Regards,