Skip to contentSkip to conversation

serial: clps711x: Fix error handling in uart_clps711x_init()

PATCH In review Yuan Can 2 participants 2 messages Nov 24, 2022 – Jan 19, 2023 TTY layer and serial drivers

lore
Share & tools
lore

Yuan Can

author
#0 lore raw

PATCH 1/1 serial: clps711x: Fix error handling in uart_clps711x_init()

The uart_clps711x_init() returns the platform_driver_register() directly without checking its return value, if platform_driver_register() failed, the clps711x_uart is not unregistered.

Fix by unregister clps711x_uart when platform_driver_register() failed.

Fixes bc00024502ed ("serial: clps711x: Driver refactor")
---
 drivers/tty/serial/clps711x.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/tty/serial/clps711x.c +7 -1
index 404b43a5ae33..d6284244da1d 100644
@@ -546,7 +546,13 @@ static int __init uart_clps711x_init(void)
 	if (ret)
 		return ret;
 
-	return platform_driver_register(&clps711x_uart_platform);
+	ret = platform_driver_register(&clps711x_uart_platform);
+	if (ret) {
+		uart_unregister_driver(&clps711x_uart);
+		return ret;
+	}
+
+	return 0;
 }
 module_init(uart_clps711x_init);
 
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 18 lines · Yuan Can

The uart_clps711x_init() returns the platform_driver_register() directly without checking its return value, if platform_driver_register() failed, the clps711x_uart is not unregistered.

Fix by unregister clps711x_uart when platform_driver_register() failed.

Fixes bc00024502ed ("serial: clps711x: Driver refactor")
---
 drivers/tty/serial/clps711x.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/tty/serial/clps711x.c +0 -0
index 404b43a5ae33..d6284244da1d 100644
@@ -546,7 +546,13 @@ static int __init uart_clps711x_init(void)
 	if (ret)

drivers/tty/serial/clps711x.c static int __init uart_clps711x_init(void) · line 555

Quoted 10 lines
drivers/tty/serial/clps711x.c +7 -1
 		return ret;
 
-	return platform_driver_register(&clps711x_uart_platform);
+	ret = platform_driver_register(&clps711x_uart_platform);
+	if (ret) {
+		uart_unregister_driver(&clps711x_uart);
+		return ret;
+	}
+
+	return 0;

Minot nit, but this can be cleaned up to be even smaller:

	ret = platform_driver_register(&clps711x_uart_platform);
	if (ret)
		uart_unregister_driver(&clps711x_uart);

	return ret;

thanks,

greg k-h