diff mbox series

serial: clps711x: Fix error handling in uart_clps711x_init()

Message ID 20221124061236.31050-1-yuancan@huawei.com
State New
Headers show
Series serial: clps711x: Fix error handling in uart_clps711x_init() | expand

Commit Message

Yuan Can Nov. 24, 2022, 6:12 a.m. UTC
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")
Signed-off-by: Yuan Can <yuancan@huawei.com>
---
 drivers/tty/serial/clps711x.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Greg Kroah-Hartman Jan. 19, 2023, 3:03 p.m. UTC | #1
On Thu, Nov 24, 2022 at 06:12:36AM +0000, Yuan Can wrote:
> 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")
> Signed-off-by: Yuan Can <yuancan@huawei.com>
> ---
>  drivers/tty/serial/clps711x.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/serial/clps711x.c b/drivers/tty/serial/clps711x.c
> index 404b43a5ae33..d6284244da1d 100644
> --- a/drivers/tty/serial/clps711x.c
> +++ b/drivers/tty/serial/clps711x.c
> @@ -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;

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
diff mbox series

Patch

diff --git a/drivers/tty/serial/clps711x.c b/drivers/tty/serial/clps711x.c
index 404b43a5ae33..d6284244da1d 100644
--- a/drivers/tty/serial/clps711x.c
+++ b/drivers/tty/serial/clps711x.c
@@ -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);