* [PATCH 1/2] serial: sh-sci: fix missing sci_cleanup_single() in sci_probe_single()
@ 2022-06-30 14:09 Yang Yingliang
2022-06-30 14:09 ` [PATCH 2/2] serial: sh-sci: fix missing uart_unregister_driver() " Yang Yingliang
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Yang Yingliang @ 2022-06-30 14:09 UTC (permalink / raw)
To: linux-kernel, linux-serial; +Cc: gregkh, geert+renesas, peter, sjoerd.simons
Add missing sci_cleanup_single() in error case in sci_probe_single()
Fixes: f907c9ea8835 ("serial: sh-sci: Add support for GPIO-controlled modem lines")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
drivers/tty/serial/sh-sci.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 0075a1420005..ca5a58f01aff 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -3283,25 +3283,31 @@ static int sci_probe_single(struct platform_device *dev,
return ret;
sciport->gpios = mctrl_gpio_init(&sciport->port, 0);
- if (IS_ERR(sciport->gpios))
- return PTR_ERR(sciport->gpios);
+ if (IS_ERR(sciport->gpios)) {
+ ret = PTR_ERR(sciport->gpios);
+ goto err_cleanup_single;
+ }
if (sciport->has_rtscts) {
if (mctrl_gpio_to_gpiod(sciport->gpios, UART_GPIO_CTS) ||
mctrl_gpio_to_gpiod(sciport->gpios, UART_GPIO_RTS)) {
dev_err(&dev->dev, "Conflicting RTS/CTS config\n");
- return -EINVAL;
+ ret = -EINVAL;
+ goto err_cleanup_single;
}
sciport->port.flags |= UPF_HARD_FLOW;
}
ret = uart_add_one_port(&sci_uart_driver, &sciport->port);
- if (ret) {
- sci_cleanup_single(sciport);
- return ret;
- }
+ if (ret)
+ goto err_cleanup_single;
return 0;
+
+err_cleanup_single:
+ sci_cleanup_single(sciport);
+
+ return ret;
}
static int sci_probe(struct platform_device *dev)
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] serial: sh-sci: fix missing uart_unregister_driver() in sci_probe_single()
2022-06-30 14:09 [PATCH 1/2] serial: sh-sci: fix missing sci_cleanup_single() in sci_probe_single() Yang Yingliang
@ 2022-06-30 14:09 ` Yang Yingliang
2022-06-30 15:13 ` Greg KH
2022-06-30 15:13 ` [PATCH 1/2] serial: sh-sci: fix missing sci_cleanup_single() " Greg KH
2022-07-07 8:47 ` Geert Uytterhoeven
2 siblings, 1 reply; 7+ messages in thread
From: Yang Yingliang @ 2022-06-30 14:09 UTC (permalink / raw)
To: linux-kernel, linux-serial; +Cc: gregkh, geert+renesas, peter, sjoerd.simons
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);
return ret;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] serial: sh-sci: fix missing uart_unregister_driver() in sci_probe_single()
2022-06-30 14:09 ` [PATCH 2/2] serial: sh-sci: fix missing uart_unregister_driver() " Yang Yingliang
@ 2022-06-30 15:13 ` Greg KH
2022-07-01 2:34 ` Yang Yingliang
0 siblings, 1 reply; 7+ messages in thread
From: Greg KH @ 2022-06-30 15:13 UTC (permalink / raw)
To: Yang Yingliang
Cc: linux-kernel, linux-serial, geert+renesas, peter, sjoerd.simons
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] serial: sh-sci: fix missing sci_cleanup_single() in sci_probe_single()
2022-06-30 14:09 [PATCH 1/2] serial: sh-sci: fix missing sci_cleanup_single() in sci_probe_single() Yang Yingliang
2022-06-30 14:09 ` [PATCH 2/2] serial: sh-sci: fix missing uart_unregister_driver() " Yang Yingliang
@ 2022-06-30 15:13 ` Greg KH
2022-07-01 4:25 ` Yang Yingliang
2022-07-07 8:47 ` Geert Uytterhoeven
2 siblings, 1 reply; 7+ messages in thread
From: Greg KH @ 2022-06-30 15:13 UTC (permalink / raw)
To: Yang Yingliang
Cc: linux-kernel, linux-serial, geert+renesas, peter, sjoerd.simons
On Thu, Jun 30, 2022 at 10:09:18PM +0800, Yang Yingliang wrote:
> Add missing sci_cleanup_single() in error case in sci_probe_single()
>
> Fixes: f907c9ea8835 ("serial: sh-sci: Add support for GPIO-controlled modem lines")
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
> drivers/tty/serial/sh-sci.c | 20 +++++++++++++-------
> 1 file changed, 13 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
> index 0075a1420005..ca5a58f01aff 100644
> --- a/drivers/tty/serial/sh-sci.c
> +++ b/drivers/tty/serial/sh-sci.c
> @@ -3283,25 +3283,31 @@ static int sci_probe_single(struct platform_device *dev,
> return ret;
>
> sciport->gpios = mctrl_gpio_init(&sciport->port, 0);
> - if (IS_ERR(sciport->gpios))
> - return PTR_ERR(sciport->gpios);
> + if (IS_ERR(sciport->gpios)) {
> + ret = PTR_ERR(sciport->gpios);
> + goto err_cleanup_single;
> + }
>
> if (sciport->has_rtscts) {
> if (mctrl_gpio_to_gpiod(sciport->gpios, UART_GPIO_CTS) ||
> mctrl_gpio_to_gpiod(sciport->gpios, UART_GPIO_RTS)) {
> dev_err(&dev->dev, "Conflicting RTS/CTS config\n");
> - return -EINVAL;
> + ret = -EINVAL;
> + goto err_cleanup_single;
> }
> sciport->port.flags |= UPF_HARD_FLOW;
> }
>
> ret = uart_add_one_port(&sci_uart_driver, &sciport->port);
> - if (ret) {
> - sci_cleanup_single(sciport);
> - return ret;
> - }
> + if (ret)
> + goto err_cleanup_single;
>
> return 0;
> +
> +err_cleanup_single:
> + sci_cleanup_single(sciport);
> +
> + return ret;
> }
>
> static int sci_probe(struct platform_device *dev)
> --
> 2.25.1
>
How was this tested?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] serial: sh-sci: fix missing uart_unregister_driver() in sci_probe_single()
2022-06-30 15:13 ` Greg KH
@ 2022-07-01 2:34 ` Yang Yingliang
0 siblings, 0 replies; 7+ messages in thread
From: Yang Yingliang @ 2022-07-01 2:34 UTC (permalink / raw)
To: Greg KH; +Cc: linux-kernel, linux-serial, geert+renesas, peter, sjoerd.simons
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
> .
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] serial: sh-sci: fix missing sci_cleanup_single() in sci_probe_single()
2022-06-30 15:13 ` [PATCH 1/2] serial: sh-sci: fix missing sci_cleanup_single() " Greg KH
@ 2022-07-01 4:25 ` Yang Yingliang
0 siblings, 0 replies; 7+ messages in thread
From: Yang Yingliang @ 2022-07-01 4:25 UTC (permalink / raw)
To: Greg KH; +Cc: linux-kernel, linux-serial, geert+renesas, peter, sjoerd.simons
On 2022/6/30 23:13, Greg KH wrote:
> On Thu, Jun 30, 2022 at 10:09:18PM +0800, Yang Yingliang wrote:
>> Add missing sci_cleanup_single() in error case in sci_probe_single()
>>
>> Fixes: f907c9ea8835 ("serial: sh-sci: Add support for GPIO-controlled modem lines")
>> Reported-by: Hulk Robot <hulkci@huawei.com>
>> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
>> ---
>> drivers/tty/serial/sh-sci.c | 20 +++++++++++++-------
>> 1 file changed, 13 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
>> index 0075a1420005..ca5a58f01aff 100644
>> --- a/drivers/tty/serial/sh-sci.c
>> +++ b/drivers/tty/serial/sh-sci.c
>> @@ -3283,25 +3283,31 @@ static int sci_probe_single(struct platform_device *dev,
>> return ret;
>>
>> sciport->gpios = mctrl_gpio_init(&sciport->port, 0);
>> - if (IS_ERR(sciport->gpios))
>> - return PTR_ERR(sciport->gpios);
>> + if (IS_ERR(sciport->gpios)) {
>> + ret = PTR_ERR(sciport->gpios);
>> + goto err_cleanup_single;
>> + }
>>
>> if (sciport->has_rtscts) {
>> if (mctrl_gpio_to_gpiod(sciport->gpios, UART_GPIO_CTS) ||
>> mctrl_gpio_to_gpiod(sciport->gpios, UART_GPIO_RTS)) {
>> dev_err(&dev->dev, "Conflicting RTS/CTS config\n");
>> - return -EINVAL;
>> + ret = -EINVAL;
>> + goto err_cleanup_single;
>> }
>> sciport->port.flags |= UPF_HARD_FLOW;
>> }
>>
>> ret = uart_add_one_port(&sci_uart_driver, &sciport->port);
>> - if (ret) {
>> - sci_cleanup_single(sciport);
>> - return ret;
>> - }
>> + if (ret)
>> + goto err_cleanup_single;
>>
>> return 0;
>> +
>> +err_cleanup_single:
>> + sci_cleanup_single(sciport);
>> +
>> + return ret;
>> }
>>
>> static int sci_probe(struct platform_device *dev)
>> --
>> 2.25.1
>>
> How was this tested?
I found this by read the code, pm_runtime_enable() is called in
sci_init_single(), but
pm_runtime_disable() is only called when uart_add_one_port() fails, so I
add the
pm_runtime_disable() in other error case. Please correct me if I am wrong.
Thanks,
Yang
>
> thanks,
>
> greg k-h
> .
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] serial: sh-sci: fix missing sci_cleanup_single() in sci_probe_single()
2022-06-30 14:09 [PATCH 1/2] serial: sh-sci: fix missing sci_cleanup_single() in sci_probe_single() Yang Yingliang
2022-06-30 14:09 ` [PATCH 2/2] serial: sh-sci: fix missing uart_unregister_driver() " Yang Yingliang
2022-06-30 15:13 ` [PATCH 1/2] serial: sh-sci: fix missing sci_cleanup_single() " Greg KH
@ 2022-07-07 8:47 ` Geert Uytterhoeven
2 siblings, 0 replies; 7+ messages in thread
From: Geert Uytterhoeven @ 2022-07-07 8:47 UTC (permalink / raw)
To: Yang Yingliang
Cc: Linux Kernel Mailing List, open list:SERIAL DRIVERS, Greg KH,
Peter Hurley, Sjoerd Simons
On Thu, Jun 30, 2022 at 3:59 PM Yang Yingliang <yangyingliang@huawei.com> wrote:
> Add missing sci_cleanup_single() in error case in sci_probe_single()
>
> Fixes: f907c9ea8835 ("serial: sh-sci: Add support for GPIO-controlled modem lines")
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-07-07 8:48 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-30 14:09 [PATCH 1/2] serial: sh-sci: fix missing sci_cleanup_single() in sci_probe_single() Yang Yingliang
2022-06-30 14:09 ` [PATCH 2/2] serial: sh-sci: fix missing uart_unregister_driver() " Yang Yingliang
2022-06-30 15:13 ` Greg KH
2022-07-01 2:34 ` Yang Yingliang
2022-06-30 15:13 ` [PATCH 1/2] serial: sh-sci: fix missing sci_cleanup_single() " Greg KH
2022-07-01 4:25 ` Yang Yingliang
2022-07-07 8:47 ` Geert Uytterhoeven
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).