linux-samsung-soc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] serial: samsung: Checks the return value of function
       [not found] <CGME20210706061710epcas5p2c11d1bf5afb14774c4d4db93f2b83b33@epcas5p2.samsung.com>
@ 2021-07-06  6:19 ` Tamseel Shams
  2021-07-07  8:14   ` Jiri Slaby
  2021-07-07 15:55   ` Johan Hovold
  0 siblings, 2 replies; 3+ messages in thread
From: Tamseel Shams @ 2021-07-06  6:19 UTC (permalink / raw)
  To: krzysztof.kozlowski, gregkh, jirislaby
  Cc: linux-arm-kernel, linux-samsung-soc, linux-serial, linux-kernel,
	alim.akhtar, Tamseel Shams

"uart_add_one_port" function call may fail and return
some error code, so adding a check for return value.
If it is returning some error code, then displaying the
result, unregistering the driver and then returning from
probe function with error code.

Signed-off-by: Tamseel Shams <m.shams@samsung.com>
---
Changes since v1:
1. Added support to unregister driver on failure of "uart_add_one_port"
function call.
2. Commit message updated.

Changes since v2:
1. Added support to unwind clocks on failure of "uart_add_one_port"
function call.

 drivers/tty/serial/samsung_tty.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/samsung_tty.c b/drivers/tty/serial/samsung_tty.c
index 9fbc61151c2e..a3f3a17fb54b 100644
--- a/drivers/tty/serial/samsung_tty.c
+++ b/drivers/tty/serial/samsung_tty.c
@@ -2253,7 +2253,11 @@ static int s3c24xx_serial_probe(struct platform_device *pdev)
 	}
 
 	dev_dbg(&pdev->dev, "%s: adding port\n", __func__);
-	uart_add_one_port(&s3c24xx_uart_drv, &ourport->port);
+	ret = uart_add_one_port(&s3c24xx_uart_drv, &ourport->port);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Failed to add uart port, err %d\n", ret);
+		goto add_port_error;
+	}
 	platform_set_drvdata(pdev, &ourport->port);
 
 	/*
@@ -2272,6 +2276,17 @@ static int s3c24xx_serial_probe(struct platform_device *pdev)
 	probe_index++;
 
 	return 0;
+
+add_port_error:
+	ourport->port.mapbase = 0;
+	clk_disable_unprepare(ourport->clk);
+	clk_put(ourport->clk);
+	if (!IS_ERR(ourport->baudclk)) {
+		clk_disable_unprepare(ourport->baudclk);
+		clk_put(ourport->baudclk);
+	}
+	uart_unregister_driver(&s3c24xx_uart_drv);
+	return ret;
 }
 
 static int s3c24xx_serial_remove(struct platform_device *dev)
-- 
2.17.1


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

* Re: [PATCH v3] serial: samsung: Checks the return value of function
  2021-07-06  6:19 ` [PATCH v3] serial: samsung: Checks the return value of function Tamseel Shams
@ 2021-07-07  8:14   ` Jiri Slaby
  2021-07-07 15:55   ` Johan Hovold
  1 sibling, 0 replies; 3+ messages in thread
From: Jiri Slaby @ 2021-07-07  8:14 UTC (permalink / raw)
  To: Tamseel Shams, krzysztof.kozlowski, gregkh
  Cc: linux-arm-kernel, linux-samsung-soc, linux-serial, linux-kernel,
	alim.akhtar

On 06. 07. 21, 8:19, Tamseel Shams wrote:
> "uart_add_one_port" function call may fail and return
> some error code, so adding a check for return value.
> If it is returning some error code, then displaying the
> result, unregistering the driver and then returning from
> probe function with error code.
> 
> Signed-off-by: Tamseel Shams <m.shams@samsung.com>
> ---
> Changes since v1:
> 1. Added support to unregister driver on failure of "uart_add_one_port"
> function call.
> 2. Commit message updated.
> 
> Changes since v2:
> 1. Added support to unwind clocks on failure of "uart_add_one_port"
> function call.
> 
>   drivers/tty/serial/samsung_tty.c | 17 ++++++++++++++++-
>   1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/serial/samsung_tty.c b/drivers/tty/serial/samsung_tty.c
> index 9fbc61151c2e..a3f3a17fb54b 100644
> --- a/drivers/tty/serial/samsung_tty.c
> +++ b/drivers/tty/serial/samsung_tty.c
> @@ -2253,7 +2253,11 @@ static int s3c24xx_serial_probe(struct platform_device *pdev)
>   	}
>   
>   	dev_dbg(&pdev->dev, "%s: adding port\n", __func__);
> -	uart_add_one_port(&s3c24xx_uart_drv, &ourport->port);
> +	ret = uart_add_one_port(&s3c24xx_uart_drv, &ourport->port);
> +	if (ret < 0) {
> +		dev_err(&pdev->dev, "Failed to add uart port, err %d\n", ret);
> +		goto add_port_error;
> +	}
>   	platform_set_drvdata(pdev, &ourport->port);
>   
>   	/*
> @@ -2272,6 +2276,17 @@ static int s3c24xx_serial_probe(struct platform_device *pdev)
>   	probe_index++;
>   
>   	return 0;
> +
> +add_port_error:
> +	ourport->port.mapbase = 0;
> +	clk_disable_unprepare(ourport->clk);
> +	clk_put(ourport->clk);
> +	if (!IS_ERR(ourport->baudclk)) {
> +		clk_disable_unprepare(ourport->baudclk);
> +		clk_put(ourport->baudclk);
> +	}


LGTM, now I only wonder why s3c24xx_serial_remove() does not put clocks?

> +	uart_unregister_driver(&s3c24xx_uart_drv);
> +	return ret;
>   }
>   
>   static int s3c24xx_serial_remove(struct platform_device *dev)
> 


-- 
js
suse labs

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

* Re: [PATCH v3] serial: samsung: Checks the return value of function
  2021-07-06  6:19 ` [PATCH v3] serial: samsung: Checks the return value of function Tamseel Shams
  2021-07-07  8:14   ` Jiri Slaby
@ 2021-07-07 15:55   ` Johan Hovold
  1 sibling, 0 replies; 3+ messages in thread
From: Johan Hovold @ 2021-07-07 15:55 UTC (permalink / raw)
  To: Tamseel Shams
  Cc: krzysztof.kozlowski, gregkh, jirislaby, linux-arm-kernel,
	linux-samsung-soc, linux-serial, linux-kernel, alim.akhtar

On Tue, Jul 06, 2021 at 11:49:09AM +0530, Tamseel Shams wrote:

Please provide a better commit summary; "Checks the return value of
function" is too vague.

> "uart_add_one_port" function call may fail and return
> some error code, so adding a check for return value.
> If it is returning some error code, then displaying the
> result, unregistering the driver and then returning from
> probe function with error code.
> 
> Signed-off-by: Tamseel Shams <m.shams@samsung.com>
> ---
> Changes since v1:
> 1. Added support to unregister driver on failure of "uart_add_one_port"
> function call.
> 2. Commit message updated.
> 
> Changes since v2:
> 1. Added support to unwind clocks on failure of "uart_add_one_port"
> function call.
> 
>  drivers/tty/serial/samsung_tty.c | 17 ++++++++++++++++-
>  1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/serial/samsung_tty.c b/drivers/tty/serial/samsung_tty.c
> index 9fbc61151c2e..a3f3a17fb54b 100644
> --- a/drivers/tty/serial/samsung_tty.c
> +++ b/drivers/tty/serial/samsung_tty.c
> @@ -2253,7 +2253,11 @@ static int s3c24xx_serial_probe(struct platform_device *pdev)
>  	}
>  
>  	dev_dbg(&pdev->dev, "%s: adding port\n", __func__);
> -	uart_add_one_port(&s3c24xx_uart_drv, &ourport->port);
> +	ret = uart_add_one_port(&s3c24xx_uart_drv, &ourport->port);
> +	if (ret < 0) {
> +		dev_err(&pdev->dev, "Failed to add uart port, err %d\n", ret);
> +		goto add_port_error;
> +	}
>  	platform_set_drvdata(pdev, &ourport->port);
>  
>  	/*
> @@ -2272,6 +2276,17 @@ static int s3c24xx_serial_probe(struct platform_device *pdev)
>  	probe_index++;
>  
>  	return 0;
> +
> +add_port_error:

Name error labels after what they do, not where jump from (e.g.
"err_disable_clk").

> +	ourport->port.mapbase = 0;
> +	clk_disable_unprepare(ourport->clk);
> +	clk_put(ourport->clk);
> +	if (!IS_ERR(ourport->baudclk)) {
> +		clk_disable_unprepare(ourport->baudclk);
> +		clk_put(ourport->baudclk);
> +	}
> +	uart_unregister_driver(&s3c24xx_uart_drv);

You can't just deregister the serial driver if probe of a single port
fails. What if there are more than one port?

Looks like the driver has the same bug in remove(). What a mess... Added
by 6f134c3c7703 ("serial: samsung: Move uart_register_driver call to
device probe") in 2014.

And the clocks are never disabled and released in case
uart_register_driver() fails above either.

> +	return ret;
>  }
>  
>  static int s3c24xx_serial_remove(struct platform_device *dev)

Johan

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

end of thread, other threads:[~2021-07-07 15:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20210706061710epcas5p2c11d1bf5afb14774c4d4db93f2b83b33@epcas5p2.samsung.com>
2021-07-06  6:19 ` [PATCH v3] serial: samsung: Checks the return value of function Tamseel Shams
2021-07-07  8:14   ` Jiri Slaby
2021-07-07 15:55   ` Johan Hovold

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).