Skip registration of the platform device used for built-in ports, if no such ports are configured/created. Signed-off-by: Martin Hundebøll <martin@xxxxxxxxxx> --- Change since v1: * call serial8250_pnp_init() also when nr_uarts is zero Change since v2: * invert condition to initialize built-in ports (as suggested by Ilpo) drivers/tty/serial/8250/8250_core.c | 30 +++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c index ba48431ec6e2..a8fbc2325244 100644 --- a/drivers/tty/serial/8250/8250_core.c +++ b/drivers/tty/serial/8250/8250_core.c @@ -1186,22 +1186,26 @@ static int __init serial8250_init(void) if (ret) goto unreg_uart_drv; - serial8250_isa_devs = platform_device_alloc("serial8250", - PLAT8250_DEV_LEGACY); - if (!serial8250_isa_devs) { - ret = -ENOMEM; - goto unreg_pnp; + if (nr_uarts) { + serial8250_isa_devs = platform_device_alloc("serial8250", + PLAT8250_DEV_LEGACY); + if (!serial8250_isa_devs) { + ret = -ENOMEM; + goto unreg_pnp; + } + + ret = platform_device_add(serial8250_isa_devs); + if (ret) + goto put_dev; + + serial8250_register_ports(&serial8250_reg, &serial8250_isa_devs->dev); } - ret = platform_device_add(serial8250_isa_devs); - if (ret) - goto put_dev; - - serial8250_register_ports(&serial8250_reg, &serial8250_isa_devs->dev); - ret = platform_driver_register(&serial8250_isa_driver); if (ret == 0) goto out; + if (!nr_uarts) + goto unreg_pnp; platform_device_del(serial8250_isa_devs); put_dev: @@ -1230,7 +1234,9 @@ static void __exit serial8250_exit(void) serial8250_isa_devs = NULL; platform_driver_unregister(&serial8250_isa_driver); - platform_device_unregister(isa_dev); + + if (nr_uarts) + platform_device_unregister(isa_dev); serial8250_pnp_exit(); -- 2.38.1