Prepare 8250 isa ports to drop kernel command line serial console
handling from console_setup().
We need to set the preferred console in serial8250_isa_init_ports().
Otherwise the console gets initialized only later on when the hardware
specific driver takes over, and console_setup() is no longer handling
the ttyS related quirks.
Note that this mostly affects x86 as this happens based on define
SERIAL_PORT_DFNS.
Signed-off-by: Tony Lindgren <tony@atomide.com>
---
drivers/tty/serial/8250/8250_core.c | 32 +++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
--- a/drivers/tty/serial/8250/8250_core.c
+++ b/drivers/tty/serial/8250/8250_core.c
@@ -15,6 +15,7 @@
*/
#include <linux/acpi.h>
+#include <linux/cleanup.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/ioport.h>
@@ -517,6 +518,35 @@ static struct uart_8250_port *serial8250_setup_port(int index)
return up;
}
+#ifdef CONFIG_SERIAL_8250_CONSOLE
+
+/*
+ * There is no struct device at this point, so let's not try to use
+ * serial_base_add_preferred_console().
+ */
+static void __init serial8250_isa_init_preferred_console(int idx)
+{
+ const char *name __free(kfree);
+ int ret;
+
+ name = kasprintf(GFP_KERNEL, "%s%i", serial8250_reg.dev_name, idx);
+ ret = add_preferred_console_match(name, serial8250_reg.dev_name, idx);
+ if (!ret || ret == -ENOENT)
+ return;
+
+ pr_err("Could not add preferred console for %s idx %i\n",
+ serial8250_reg.dev_name, idx);
+}
+
+#else
+
+static inline void serial8250_isa_init_preferred_console(struct uart_port *port,
+ int idx)
+{
+}
+
+#endif
+
static void __init serial8250_isa_init_ports(void)
{
struct uart_8250_port *up;
@@ -563,6 +593,8 @@ static void __init serial8250_isa_init_ports(void)
port->irqflags |= irqflag;
if (serial8250_isa_config != NULL)
serial8250_isa_config(i, &up->port, &up->capabilities);
+
+ serial8250_isa_init_preferred_console(i);
}
}
--
2.43.0
Hi Tony,
kernel test robot noticed the following build errors:
[auto build test ERROR on tty/tty-testing]
[also build test ERROR on tty/tty-next tty/tty-linus usb/usb-testing usb/usb-next usb/usb-linus linus/master v6.7-rc4 next-20231205]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Tony-Lindgren/printk-Save-console-options-for-add_preferred_console_match/20231205-153731
base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git tty-testing
patch link: https://lore.kernel.org/r/20231205073255.20562-5-tony%40atomide.com
patch subject: [PATCH v4 4/4] serial: 8250: Add preferred console in serial8250_isa_init_ports()
config: m68k-randconfig-r071-20231205 (https://download.01.org/0day-ci/archive/20231206/202312060232.s0uWr7z9-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231206/202312060232.s0uWr7z9-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202312060232.s0uWr7z9-lkp@intel.com/
All error/warnings (new ones prefixed by >>):
drivers/tty/serial/8250/8250_core.c: In function 'serial8250_isa_init_ports':
>> drivers/tty/serial/8250/8250_core.c:597:55: warning: passing argument 1 of 'serial8250_isa_init_preferred_console' makes pointer from integer without a cast [-Wint-conversion]
597 | serial8250_isa_init_preferred_console(i);
| ^
| |
| int
drivers/tty/serial/8250/8250_core.c:543:76: note: expected 'struct uart_port *' but argument is of type 'int'
543 | static inline void serial8250_isa_init_preferred_console(struct uart_port *port,
| ~~~~~~~~~~~~~~~~~~^~~~
>> drivers/tty/serial/8250/8250_core.c:597:17: error: too few arguments to function 'serial8250_isa_init_preferred_console'
597 | serial8250_isa_init_preferred_console(i);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/tty/serial/8250/8250_core.c:543:20: note: declared here
543 | static inline void serial8250_isa_init_preferred_console(struct uart_port *port,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +/serial8250_isa_init_preferred_console +597 drivers/tty/serial/8250/8250_core.c
549
550 static void __init serial8250_isa_init_ports(void)
551 {
552 struct uart_8250_port *up;
553 static int first = 1;
554 int i, irqflag = 0;
555
556 if (!first)
557 return;
558 first = 0;
559
560 if (nr_uarts > UART_NR)
561 nr_uarts = UART_NR;
562
563 /*
564 * Set up initial isa ports based on nr_uart module param, or else
565 * default to CONFIG_SERIAL_8250_RUNTIME_UARTS. Note that we do not
566 * need to increase nr_uarts when setting up the initial isa ports.
567 */
568 for (i = 0; i < nr_uarts; i++)
569 serial8250_setup_port(i);
570
571 /* chain base port ops to support Remote Supervisor Adapter */
572 univ8250_port_ops = *base_ops;
573 univ8250_rsa_support(&univ8250_port_ops);
574
575 if (share_irqs)
576 irqflag = IRQF_SHARED;
577
578 for (i = 0, up = serial8250_ports;
579 i < ARRAY_SIZE(old_serial_port) && i < nr_uarts;
580 i++, up++) {
581 struct uart_port *port = &up->port;
582
583 port->iobase = old_serial_port[i].port;
584 port->irq = irq_canonicalize(old_serial_port[i].irq);
585 port->irqflags = 0;
586 port->uartclk = old_serial_port[i].baud_base * 16;
587 port->flags = old_serial_port[i].flags;
588 port->hub6 = 0;
589 port->membase = old_serial_port[i].iomem_base;
590 port->iotype = old_serial_port[i].io_type;
591 port->regshift = old_serial_port[i].iomem_reg_shift;
592
593 port->irqflags |= irqflag;
594 if (serial8250_isa_config != NULL)
595 serial8250_isa_config(i, &up->port, &up->capabilities);
596
> 597 serial8250_isa_init_preferred_console(i);
598 }
599 }
600
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Hi Tony,
kernel test robot noticed the following build errors:
[auto build test ERROR on tty/tty-testing]
[also build test ERROR on tty/tty-next tty/tty-linus usb/usb-testing usb/usb-next usb/usb-linus linus/master v6.7-rc4 next-20231205]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Tony-Lindgren/printk-Save-console-options-for-add_preferred_console_match/20231205-153731
base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git tty-testing
patch link: https://lore.kernel.org/r/20231205073255.20562-5-tony%40atomide.com
patch subject: [PATCH v4 4/4] serial: 8250: Add preferred console in serial8250_isa_init_ports()
config: powerpc-randconfig-r081-20231205 (https://download.01.org/0day-ci/archive/20231206/202312060101.o6nb55MI-lkp@intel.com/config)
compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231206/202312060101.o6nb55MI-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202312060101.o6nb55MI-lkp@intel.com/
All errors (new ones prefixed by >>):
>> drivers/tty/serial/8250/8250_core.c:597:42: error: too few arguments to function call, expected 2, have 1
597 | serial8250_isa_init_preferred_console(i);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
drivers/tty/serial/8250/8250_core.c:543:20: note: 'serial8250_isa_init_preferred_console' declared here
543 | static inline void serial8250_isa_init_preferred_console(struct uart_port *port,
| ^
1 error generated.
vim +597 drivers/tty/serial/8250/8250_core.c
549
550 static void __init serial8250_isa_init_ports(void)
551 {
552 struct uart_8250_port *up;
553 static int first = 1;
554 int i, irqflag = 0;
555
556 if (!first)
557 return;
558 first = 0;
559
560 if (nr_uarts > UART_NR)
561 nr_uarts = UART_NR;
562
563 /*
564 * Set up initial isa ports based on nr_uart module param, or else
565 * default to CONFIG_SERIAL_8250_RUNTIME_UARTS. Note that we do not
566 * need to increase nr_uarts when setting up the initial isa ports.
567 */
568 for (i = 0; i < nr_uarts; i++)
569 serial8250_setup_port(i);
570
571 /* chain base port ops to support Remote Supervisor Adapter */
572 univ8250_port_ops = *base_ops;
573 univ8250_rsa_support(&univ8250_port_ops);
574
575 if (share_irqs)
576 irqflag = IRQF_SHARED;
577
578 for (i = 0, up = serial8250_ports;
579 i < ARRAY_SIZE(old_serial_port) && i < nr_uarts;
580 i++, up++) {
581 struct uart_port *port = &up->port;
582
583 port->iobase = old_serial_port[i].port;
584 port->irq = irq_canonicalize(old_serial_port[i].irq);
585 port->irqflags = 0;
586 port->uartclk = old_serial_port[i].baud_base * 16;
587 port->flags = old_serial_port[i].flags;
588 port->hub6 = 0;
589 port->membase = old_serial_port[i].iomem_base;
590 port->iotype = old_serial_port[i].io_type;
591 port->regshift = old_serial_port[i].iomem_reg_shift;
592
593 port->irqflags |= irqflag;
594 if (serial8250_isa_config != NULL)
595 serial8250_isa_config(i, &up->port, &up->capabilities);
596
> 597 serial8250_isa_init_preferred_console(i);
598 }
599 }
600
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
On Tue, Dec 05, 2023 at 09:32:36AM +0200, Tony Lindgren wrote:
> Prepare 8250 isa ports to drop kernel command line serial console
ISA
> handling from console_setup().
>
> We need to set the preferred console in serial8250_isa_init_ports().
> Otherwise the console gets initialized only later on when the hardware
> specific driver takes over, and console_setup() is no longer handling
> the ttyS related quirks.
>
> Note that this mostly affects x86 as this happens based on define
> SERIAL_PORT_DFNS.
...
> +static void __init serial8250_isa_init_preferred_console(int idx)
> +{
> + const char *name __free(kfree);
> + int ret;
> +
> + name = kasprintf(GFP_KERNEL, "%s%i", serial8250_reg.dev_name, idx);
No error check?
> + ret = add_preferred_console_match(name, serial8250_reg.dev_name, idx);
> + if (!ret || ret == -ENOENT)
> + return;
ret = serial_base_add_one_prefcon(...);
?
> + pr_err("Could not add preferred console for %s idx %i\n",
> + serial8250_reg.dev_name, idx);
> +}
--
With Best Regards,
Andy Shevchenko
* Andy Shevchenko <andriy.shevchenko@intel.com> [231205 16:08]: > On Tue, Dec 05, 2023 at 09:32:36AM +0200, Tony Lindgren wrote: > > + name = kasprintf(GFP_KERNEL, "%s%i", serial8250_reg.dev_name, idx); > > No error check? Oops > > + ret = add_preferred_console_match(name, serial8250_reg.dev_name, idx); > > + if (!ret || ret == -ENOENT) > > + return; > > ret = serial_base_add_one_prefcon(...); > > ? Yup that should work even before struct device. Will fix the other places too you noticed. Thanks, Tony
On Tue, Dec 05, 2023 at 06:08:37PM +0200, Andy Shevchenko wrote:
> On Tue, Dec 05, 2023 at 09:32:36AM +0200, Tony Lindgren wrote:
...
> > + pr_err("Could not add preferred console for %s idx %i\n",
> > + serial8250_reg.dev_name, idx);
And, btw, you can simply reuse name here
pr_err("Could not add preferred console for %s\n", name);
Would it work?
--
With Best Regards,
Andy Shevchenko
© 2016 - 2025 Red Hat, Inc.