linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] serial: clps711x: Fix error handling in uart_clps711x_init()
@ 2022-11-24  6:12 Yuan Can
  2023-01-19 15:03 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Yuan Can @ 2022-11-24  6:12 UTC (permalink / raw)
  To: gregkh, jirislaby, shc_work, arnd, linux-serial, linux-arm-kernel; +Cc: yuancan

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;
 }
 module_init(uart_clps711x_init);
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] serial: clps711x: Fix error handling in uart_clps711x_init()
  2022-11-24  6:12 [PATCH] serial: clps711x: Fix error handling in uart_clps711x_init() Yuan Can
@ 2023-01-19 15:03 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2023-01-19 15:03 UTC (permalink / raw)
  To: Yuan Can; +Cc: jirislaby, shc_work, arnd, linux-serial, linux-arm-kernel

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-01-19 15:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-24  6:12 [PATCH] serial: clps711x: Fix error handling in uart_clps711x_init() Yuan Can
2023-01-19 15:03 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).