Skip to contentSkip to conversation

serial: sh-sci: fix missing sci_cleanup_single() in sci_probe_single()

PATCH In review Yang Yingliang 3 participants 7 messages Jun 30, 2022 – Jul 7, 2022 TTY layer and serial drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 serial: sh-sci: fix missing sci_cleanup_single() in sci_probe_single()

Add missing sci_cleanup_single() in error case in sci_probe_single()

Fixes f907c9ea8835 ("serial: sh-sci: Add support for GPIO-controlled modem lines")
---
 drivers/tty/serial/sh-sci.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
drivers/tty/serial/sh-sci.c +13 -7
index 0075a1420005..ca5a58f01aff 100644
@@ -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)
Signature · 1 line
2.25.1
#1 lore raw

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

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")
---
 drivers/tty/serial/sh-sci.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/tty/serial/sh-sci.c +5 -1
index ca5a58f01aff..08a249eaaa8c 100644
@@ -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;
 }
Signature · 1 line
2.25.1
maintainer
#2 lore raw

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

Quoted 23 lines · Yang Yingliang

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")
---
 drivers/tty/serial/sh-sci.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/tty/serial/sh-sci.c +1 -1
index ca5a58f01aff..08a249eaaa8c 100644
@@ -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)) {

drivers/tty/serial/sh-sci.c static int sci_probe_single(struct platform_device *dev, · line 3312

Quoted 7 lines
drivers/tty/serial/sh-sci.c +4 -0
@@ -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

#3 lore raw

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

Hi,

Quoted 33 lines · Greg KH
Quoted 23 lines · Yang Yingliang

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")
---
  drivers/tty/serial/sh-sci.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
drivers/tty/serial/sh-sci.c +1 -1
index ca5a58f01aff..08a249eaaa8c 100644
@@ -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)) {

drivers/tty/serial/sh-sci.c static int sci_probe_single(struct platform_device *dev, · line 3312

Quoted 7 lines
drivers/tty/serial/sh-sci.c +4 -0
@@ -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?

Quoted 4 lines

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

Quoted 5 lines

thanks,

greg k-h
.

maintainer
#4 lore raw
In reply to Yang Yingliang
Quoted 55 lines · Yang Yingliang

Add missing sci_cleanup_single() in error case in sci_probe_single()

Fixes f907c9ea8835 ("serial: sh-sci: Add support for GPIO-controlled modem lines")
---
 drivers/tty/serial/sh-sci.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
drivers/tty/serial/sh-sci.c +13 -7
index 0075a1420005..ca5a58f01aff 100644
@@ -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)
Signature · 1 line
2.25.1

How was this tested?

thanks,

greg k-h

#5 lore raw
Quoted 52 lines · Greg KH
Quoted 51 lines · Yang Yingliang

Add missing sci_cleanup_single() in error case in sci_probe_single()

Fixes f907c9ea8835 ("serial: sh-sci: Add support for GPIO-controlled modem lines")
---
  drivers/tty/serial/sh-sci.c | 20 +++++++++++++-------
  1 file changed, 13 insertions(+), 7 deletions(-)
drivers/tty/serial/sh-sci.c +13 -7
index 0075a1420005..ca5a58f01aff 100644
@@ -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;
  }
 
Quoted 5 lines
Quoted 4 lines
drivers/tty/serial/sh-sci.c +0 -0
  static int sci_probe(struct platform_device *dev)
Signature · 1 line
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

Quoted 5 lines

thanks,

greg k-h
.

Reviewed-by on v1 1/2
#6 lore raw
In reply to Yang Yingliang
Quoted 5 lines · Yang Yingliang

Add missing sci_cleanup_single() in error case in sci_probe_single()

Fixes f907c9ea8835 ("serial: sh-sci: Add support for GPIO-controlled modem lines")

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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