[PATCH] serial: clps711x: Fix error handling in uart_clps711x_init()
Greg KH
gregkh at linuxfoundation.org
Thu Jan 19 07:03:20 PST 2023
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 at 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
More information about the linux-arm-kernel
mailing list