diff mbox series

[2/2] serial: sh-sci: fix missing uart_unregister_driver() in sci_probe_single()

Message ID 20220630140919.3857698-2-yangyingliang@huawei.com
State New
Headers show
Series [1/2] serial: sh-sci: fix missing sci_cleanup_single() in sci_probe_single() | expand

Commit Message

Yang Yingliang June 30, 2022, 2:09 p.m. UTC
Add missing uart_unregister_driver() in error case in sci_probe_single().

Fixes: 352b92664549 ("serial: sh-sci: Move uart_register_driver call to device probe")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/tty/serial/sh-sci.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Greg Kroah-Hartman June 30, 2022, 3:13 p.m. UTC | #1
On Thu, Jun 30, 2022 at 10:09:19PM +0800, Yang Yingliang wrote:
> Add missing uart_unregister_driver() in error case in sci_probe_single().
> 
> Fixes: 352b92664549 ("serial: sh-sci: Move uart_register_driver call to device probe")
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
>  drivers/tty/serial/sh-sci.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
> index ca5a58f01aff..08a249eaaa8c 100644
> --- a/drivers/tty/serial/sh-sci.c
> +++ b/drivers/tty/serial/sh-sci.c
> @@ -3280,7 +3280,7 @@ static int sci_probe_single(struct platform_device *dev,
>  
>  	ret = sci_init_single(dev, sciport, index, p, false);
>  	if (ret)
> -		return ret;
> +		goto err_unregister;
>  
>  	sciport->gpios = mctrl_gpio_init(&sciport->port, 0);
>  	if (IS_ERR(sciport->gpios)) {
> @@ -3306,6 +3306,10 @@ static int sci_probe_single(struct platform_device *dev,
>  
>  err_cleanup_single:
>  	sci_cleanup_single(sciport);
> +err_unregister:
> +	mutex_lock(&sci_uart_registration_lock);
> +	uart_unregister_driver(&sci_uart_driver);
> +	mutex_unlock(&sci_uart_registration_lock);

Did you test this?

I think you just broke all other devices attached to this driver.

Please always test your code before submitting it, especially for stuff
like this.

thanks,

greg k-h
Yang Yingliang July 1, 2022, 2:34 a.m. UTC | #2
Hi,

On 2022/6/30 23:13, Greg KH wrote:
> On Thu, Jun 30, 2022 at 10:09:19PM +0800, Yang Yingliang wrote:
>> Add missing uart_unregister_driver() in error case in sci_probe_single().
>>
>> Fixes: 352b92664549 ("serial: sh-sci: Move uart_register_driver call to device probe")
>> Reported-by: Hulk Robot <hulkci@huawei.com>
>> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
>> ---
>>   drivers/tty/serial/sh-sci.c | 6 +++++-
>>   1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
>> index ca5a58f01aff..08a249eaaa8c 100644
>> --- a/drivers/tty/serial/sh-sci.c
>> +++ b/drivers/tty/serial/sh-sci.c
>> @@ -3280,7 +3280,7 @@ static int sci_probe_single(struct platform_device *dev,
>>   
>>   	ret = sci_init_single(dev, sciport, index, p, false);
>>   	if (ret)
>> -		return ret;
>> +		goto err_unregister;
>>   
>>   	sciport->gpios = mctrl_gpio_init(&sciport->port, 0);
>>   	if (IS_ERR(sciport->gpios)) {
>> @@ -3306,6 +3306,10 @@ static int sci_probe_single(struct platform_device *dev,
>>   
>>   err_cleanup_single:
>>   	sci_cleanup_single(sciport);
>> +err_unregister:
>> +	mutex_lock(&sci_uart_registration_lock);
>> +	uart_unregister_driver(&sci_uart_driver);
>> +	mutex_unlock(&sci_uart_registration_lock);
> Did you test this?
>
> I think you just broke all other devices attached to this driver.
>
> Please always test your code before submitting it, especially for stuff
> like this.
I made a mistake here, the register is for the driver not for single 
port, this breaks
other ports, I will be more careful about this case next time.

Thanks,
Yang
>
> thanks,
>
> greg k-h
> .
diff mbox series

Patch

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index ca5a58f01aff..08a249eaaa8c 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -3280,7 +3280,7 @@  static int sci_probe_single(struct platform_device *dev,
 
 	ret = sci_init_single(dev, sciport, index, p, false);
 	if (ret)
-		return ret;
+		goto err_unregister;
 
 	sciport->gpios = mctrl_gpio_init(&sciport->port, 0);
 	if (IS_ERR(sciport->gpios)) {
@@ -3306,6 +3306,10 @@  static int sci_probe_single(struct platform_device *dev,
 
 err_cleanup_single:
 	sci_cleanup_single(sciport);
+err_unregister:
+	mutex_lock(&sci_uart_registration_lock);
+	uart_unregister_driver(&sci_uart_driver);
+	mutex_unlock(&sci_uart_registration_lock);
 
 	return ret;
 }