diff mbox series

[v2,3/3] serial: 8250: skip platform device registration with no runtime ports

Message ID 20221018133419.134110-3-martin@geanix.com
State New
Headers show
Series [v2,1/3] serial: 8250: allow use of non-runtime configured uart ports | expand

Commit Message

Martin Hundebøll Oct. 18, 2022, 1:34 p.m. UTC
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@geanix.com>
---

Change since v1:
 * call serial8250_pnp_init() also when nr_uarts is zero

 drivers/tty/serial/8250/8250_core.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

Comments

Ilpo Järvinen Oct. 20, 2022, 1 p.m. UTC | #1
On Tue, 18 Oct 2022, Martin Hundebøll wrote:

> 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@geanix.com>

For the whole series:

Tested-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

> ---
> 
> Change since v1:
>  * call serial8250_pnp_init() also when nr_uarts is zero
> 
>  drivers/tty/serial/8250/8250_core.c | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
> index ba48431ec6e2..f4a08fb74c31 100644
> --- a/drivers/tty/serial/8250/8250_core.c
> +++ b/drivers/tty/serial/8250/8250_core.c
> @@ -1186,6 +1186,14 @@ static int __init serial8250_init(void)
>  	if (ret)
>  		goto unreg_uart_drv;
>  
> +	if (nr_uarts == 0) {
> +		ret = platform_driver_register(&serial8250_isa_driver);
> +		if (ret)
> +			goto unreg_pnp;
> +
> +		goto out;
> +	}
> +

I'd reverse the condition:

	if (nr_uarts) {
		platform stuff
	}

	ret = platform_driver_register(&serial8250_isa_driver);
        if (ret == 0)
		goto out;
	if (!nr_uarts)
		goto unreg_pnp;

I believe the logic would be easier to follow if you do that.
diff mbox series

Patch

diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
index ba48431ec6e2..f4a08fb74c31 100644
--- a/drivers/tty/serial/8250/8250_core.c
+++ b/drivers/tty/serial/8250/8250_core.c
@@ -1186,6 +1186,14 @@  static int __init serial8250_init(void)
 	if (ret)
 		goto unreg_uart_drv;
 
+	if (nr_uarts == 0) {
+		ret = platform_driver_register(&serial8250_isa_driver);
+		if (ret)
+			goto unreg_pnp;
+
+		goto out;
+	}
+
 	serial8250_isa_devs = platform_device_alloc("serial8250",
 						    PLAT8250_DEV_LEGACY);
 	if (!serial8250_isa_devs) {
@@ -1230,7 +1238,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();