linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] serial: 8250_bcm7271: Fix clock handling
@ 2023-04-27 18:19 Doug Berger
  2023-04-27 18:19 ` [PATCH 1/2] serial: 8250_bcm7271: balance clk_enable calls Doug Berger
  2023-04-27 18:19 ` [PATCH 2/2] serial: 8250_bcm7271: fix leak in `brcmuart_probe` Doug Berger
  0 siblings, 2 replies; 7+ messages in thread
From: Doug Berger @ 2023-04-27 18:19 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Al Cooper, XuDong Liu, Dongliang Mu, Jiri Slaby, Florian Fainelli,
	Broadcom internal kernel review list, linux-serial, linux-kernel,
	Christophe JAILLET, Doug Berger

XuDong Liu offered a patch to correct some clock issues detected
in the probe function and Christophe JAILLET pointed out that
there was a similar issue in remove.

Since no V2 has appeared, I am providing this pair of commits to
address both cases. This set chooses to use a managed clock to
avoid the need to explicitly call clk_put from the driver.

Doug Berger (2):
  serial: 8250_bcm7271: balance clk_enable calls
  serial: 8250_bcm7271: fix leak in `brcmuart_probe`

 drivers/tty/serial/8250/8250_bcm7271.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

-- 
2.34.1


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

* [PATCH 1/2] serial: 8250_bcm7271: balance clk_enable calls
  2023-04-27 18:19 [PATCH 0/2] serial: 8250_bcm7271: Fix clock handling Doug Berger
@ 2023-04-27 18:19 ` Doug Berger
  2023-04-28 17:42   ` Florian Fainelli
  2023-04-27 18:19 ` [PATCH 2/2] serial: 8250_bcm7271: fix leak in `brcmuart_probe` Doug Berger
  1 sibling, 1 reply; 7+ messages in thread
From: Doug Berger @ 2023-04-27 18:19 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Al Cooper, XuDong Liu, Dongliang Mu, Jiri Slaby, Florian Fainelli,
	Broadcom internal kernel review list, linux-serial, linux-kernel,
	Christophe JAILLET, Doug Berger

The sw_baud clock must be disabled when the device driver is not
connected to the device. This now occurs when probe fails and
upon remove.

Fixes: 41a469482de2 ("serial: 8250: Add new 8250-core based Broadcom STB driver")
Reported-by: XuDong Liu <m202071377@hust.edu.cn>
Link: https://lore.kernel.org/lkml/20230424125100.4783-1-m202071377@hust.edu.cn/
Signed-off-by: Doug Berger <opendmb@gmail.com>
---
 drivers/tty/serial/8250/8250_bcm7271.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/8250/8250_bcm7271.c b/drivers/tty/serial/8250/8250_bcm7271.c
index f801b1f5b46c..90ee7bc12f77 100644
--- a/drivers/tty/serial/8250/8250_bcm7271.c
+++ b/drivers/tty/serial/8250/8250_bcm7271.c
@@ -1032,7 +1032,7 @@ static int brcmuart_probe(struct platform_device *pdev)
 	if (clk_rate == 0) {
 		dev_err(dev, "clock-frequency or clk not defined\n");
 		ret = -EINVAL;
-		goto release_dma;
+		goto err_clk_disable;
 	}
 
 	dev_dbg(dev, "DMA is %senabled\n", priv->dma_enabled ? "" : "not ");
@@ -1119,6 +1119,8 @@ static int brcmuart_probe(struct platform_device *pdev)
 	serial8250_unregister_port(priv->line);
 err:
 	brcmuart_free_bufs(dev, priv);
+err_clk_disable:
+	clk_disable_unprepare(baud_mux_clk);
 release_dma:
 	if (priv->dma_enabled)
 		brcmuart_arbitration(priv, 0);
@@ -1133,6 +1135,7 @@ static int brcmuart_remove(struct platform_device *pdev)
 	hrtimer_cancel(&priv->hrt);
 	serial8250_unregister_port(priv->line);
 	brcmuart_free_bufs(&pdev->dev, priv);
+	clk_disable_unprepare(priv->baud_mux_clk);
 	if (priv->dma_enabled)
 		brcmuart_arbitration(priv, 0);
 	return 0;
-- 
2.34.1


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

* [PATCH 2/2] serial: 8250_bcm7271: fix leak in `brcmuart_probe`
  2023-04-27 18:19 [PATCH 0/2] serial: 8250_bcm7271: Fix clock handling Doug Berger
  2023-04-27 18:19 ` [PATCH 1/2] serial: 8250_bcm7271: balance clk_enable calls Doug Berger
@ 2023-04-27 18:19 ` Doug Berger
  2023-04-27 20:29   ` Christophe JAILLET
  2023-04-28 17:42   ` Florian Fainelli
  1 sibling, 2 replies; 7+ messages in thread
From: Doug Berger @ 2023-04-27 18:19 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Al Cooper, XuDong Liu, Dongliang Mu, Jiri Slaby, Florian Fainelli,
	Broadcom internal kernel review list, linux-serial, linux-kernel,
	Christophe JAILLET, Doug Berger

Smatch reports:
drivers/tty/serial/8250/8250_bcm7271.c:1120 brcmuart_probe() warn:
'baud_mux_clk' from clk_prepare_enable() not released on lines: 1032.

The issue is fixed by using a managed clock.

Fixes: 41a469482de2 ("serial: 8250: Add new 8250-core based Broadcom STB driver")
Reported-by: XuDong Liu <m202071377@hust.edu.cn>
Link: https://lore.kernel.org/lkml/20230424125100.4783-1-m202071377@hust.edu.cn/
Signed-off-by: Doug Berger <opendmb@gmail.com>
---
 drivers/tty/serial/8250/8250_bcm7271.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/serial/8250/8250_bcm7271.c b/drivers/tty/serial/8250/8250_bcm7271.c
index 90ee7bc12f77..af0e1c070187 100644
--- a/drivers/tty/serial/8250/8250_bcm7271.c
+++ b/drivers/tty/serial/8250/8250_bcm7271.c
@@ -1012,7 +1012,7 @@ static int brcmuart_probe(struct platform_device *pdev)
 	of_property_read_u32(np, "clock-frequency", &clk_rate);
 
 	/* See if a Baud clock has been specified */
-	baud_mux_clk = of_clk_get_by_name(np, "sw_baud");
+	baud_mux_clk = devm_clk_get(dev, "sw_baud");
 	if (IS_ERR(baud_mux_clk)) {
 		if (PTR_ERR(baud_mux_clk) == -EPROBE_DEFER) {
 			ret = -EPROBE_DEFER;
-- 
2.34.1


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

* Re: [PATCH 2/2] serial: 8250_bcm7271: fix leak in `brcmuart_probe`
  2023-04-27 18:19 ` [PATCH 2/2] serial: 8250_bcm7271: fix leak in `brcmuart_probe` Doug Berger
@ 2023-04-27 20:29   ` Christophe JAILLET
  2023-04-27 23:29     ` Doug Berger
  2023-04-28 17:42   ` Florian Fainelli
  1 sibling, 1 reply; 7+ messages in thread
From: Christophe JAILLET @ 2023-04-27 20:29 UTC (permalink / raw)
  To: Doug Berger
  Cc: Al Cooper, XuDong Liu, Dongliang Mu, Jiri Slaby, Florian Fainelli,
	Broadcom internal kernel review list, linux-serial, linux-kernel,
	Greg Kroah-Hartman

Le 27/04/2023 à 20:19, Doug Berger a écrit :
> Smatch reports:
> drivers/tty/serial/8250/8250_bcm7271.c:1120 brcmuart_probe() warn:
> 'baud_mux_clk' from clk_prepare_enable() not released on lines: 1032.
> 
> The issue is fixed by using a managed clock.
> 
> Fixes: 41a469482de2 ("serial: 8250: Add new 8250-core based Broadcom STB driver")
> Reported-by: XuDong Liu <m202071377@hust.edu.cn>
> Link: https://lore.kernel.org/lkml/20230424125100.4783-1-m202071377@hust.edu.cn/
> Signed-off-by: Doug Berger <opendmb@gmail.com>
> ---
>   drivers/tty/serial/8250/8250_bcm7271.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_bcm7271.c b/drivers/tty/serial/8250/8250_bcm7271.c
> index 90ee7bc12f77..af0e1c070187 100644
> --- a/drivers/tty/serial/8250/8250_bcm7271.c
> +++ b/drivers/tty/serial/8250/8250_bcm7271.c
> @@ -1012,7 +1012,7 @@ static int brcmuart_probe(struct platform_device *pdev)
>   	of_property_read_u32(np, "clock-frequency", &clk_rate);
>   
>   	/* See if a Baud clock has been specified */
> -	baud_mux_clk = of_clk_get_by_name(np, "sw_baud");
> +	baud_mux_clk = devm_clk_get(dev, "sw_baud");

If switching to devm_clk_get(), maybe devm_clk_get_enabled() could also 
be an option to fix both issues and avoid adding some LoC.

The order of operation in the remove function would then be different. I 
don't know if it can be an issue.

Just my 2c.

CJ

>   	if (IS_ERR(baud_mux_clk)) {
>   		if (PTR_ERR(baud_mux_clk) == -EPROBE_DEFER) {
>   			ret = -EPROBE_DEFER;


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

* Re: [PATCH 2/2] serial: 8250_bcm7271: fix leak in `brcmuart_probe`
  2023-04-27 20:29   ` Christophe JAILLET
@ 2023-04-27 23:29     ` Doug Berger
  0 siblings, 0 replies; 7+ messages in thread
From: Doug Berger @ 2023-04-27 23:29 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Al Cooper, XuDong Liu, Dongliang Mu, Jiri Slaby, Florian Fainelli,
	Broadcom internal kernel review list, linux-serial, linux-kernel,
	Greg Kroah-Hartman

On 4/27/2023 1:29 PM, Christophe JAILLET wrote:
> Le 27/04/2023 à 20:19, Doug Berger a écrit :
>> Smatch reports:
>> drivers/tty/serial/8250/8250_bcm7271.c:1120 brcmuart_probe() warn:
>> 'baud_mux_clk' from clk_prepare_enable() not released on lines: 1032.
>>
>> The issue is fixed by using a managed clock.
>>
>> Fixes: 41a469482de2 ("serial: 8250: Add new 8250-core based Broadcom 
>> STB driver")
>> Reported-by: XuDong Liu <m202071377@hust.edu.cn>
>> Link: 
>> https://lore.kernel.org/lkml/20230424125100.4783-1-m202071377@hust.edu.cn/
>> Signed-off-by: Doug Berger <opendmb@gmail.com>
>> ---
>>   drivers/tty/serial/8250/8250_bcm7271.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/tty/serial/8250/8250_bcm7271.c 
>> b/drivers/tty/serial/8250/8250_bcm7271.c
>> index 90ee7bc12f77..af0e1c070187 100644
>> --- a/drivers/tty/serial/8250/8250_bcm7271.c
>> +++ b/drivers/tty/serial/8250/8250_bcm7271.c
>> @@ -1012,7 +1012,7 @@ static int brcmuart_probe(struct platform_device 
>> *pdev)
>>       of_property_read_u32(np, "clock-frequency", &clk_rate);
>>       /* See if a Baud clock has been specified */
>> -    baud_mux_clk = of_clk_get_by_name(np, "sw_baud");
>> +    baud_mux_clk = devm_clk_get(dev, "sw_baud");
> 
> If switching to devm_clk_get(), maybe devm_clk_get_enabled() could also 
> be an option to fix both issues and avoid adding some LoC.
> 
> The order of operation in the remove function would then be different. I 
> don't know if it can be an issue.
I like the idea, but it doesn't backport to the source of the error.
I'll try to remember to submit something after the merge closes.

> 
> Just my 2c.
> 
> CJ
Thanks!
     Doug


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

* Re: [PATCH 1/2] serial: 8250_bcm7271: balance clk_enable calls
  2023-04-27 18:19 ` [PATCH 1/2] serial: 8250_bcm7271: balance clk_enable calls Doug Berger
@ 2023-04-28 17:42   ` Florian Fainelli
  0 siblings, 0 replies; 7+ messages in thread
From: Florian Fainelli @ 2023-04-28 17:42 UTC (permalink / raw)
  To: Doug Berger, Greg Kroah-Hartman
  Cc: Al Cooper, XuDong Liu, Dongliang Mu, Jiri Slaby, Florian Fainelli,
	Broadcom internal kernel review list, linux-serial, linux-kernel,
	Christophe JAILLET

On 4/27/23 11:19, Doug Berger wrote:
> The sw_baud clock must be disabled when the device driver is not
> connected to the device. This now occurs when probe fails and
> upon remove.
> 
> Fixes: 41a469482de2 ("serial: 8250: Add new 8250-core based Broadcom STB driver")
> Reported-by: XuDong Liu <m202071377@hust.edu.cn>
> Link: https://lore.kernel.org/lkml/20230424125100.4783-1-m202071377@hust.edu.cn/
> Signed-off-by: Doug Berger <opendmb@gmail.com>

Acked-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian


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

* Re: [PATCH 2/2] serial: 8250_bcm7271: fix leak in `brcmuart_probe`
  2023-04-27 18:19 ` [PATCH 2/2] serial: 8250_bcm7271: fix leak in `brcmuart_probe` Doug Berger
  2023-04-27 20:29   ` Christophe JAILLET
@ 2023-04-28 17:42   ` Florian Fainelli
  1 sibling, 0 replies; 7+ messages in thread
From: Florian Fainelli @ 2023-04-28 17:42 UTC (permalink / raw)
  To: Doug Berger, Greg Kroah-Hartman
  Cc: Al Cooper, XuDong Liu, Dongliang Mu, Jiri Slaby, Florian Fainelli,
	Broadcom internal kernel review list, linux-serial, linux-kernel,
	Christophe JAILLET

On 4/27/23 11:19, Doug Berger wrote:
> Smatch reports:
> drivers/tty/serial/8250/8250_bcm7271.c:1120 brcmuart_probe() warn:
> 'baud_mux_clk' from clk_prepare_enable() not released on lines: 1032.
> 
> The issue is fixed by using a managed clock.
> 
> Fixes: 41a469482de2 ("serial: 8250: Add new 8250-core based Broadcom STB driver")
> Reported-by: XuDong Liu <m202071377@hust.edu.cn>
> Link: https://lore.kernel.org/lkml/20230424125100.4783-1-m202071377@hust.edu.cn/
> Signed-off-by: Doug Berger <opendmb@gmail.com>

Acked-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian


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

end of thread, other threads:[~2023-04-28 17:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-27 18:19 [PATCH 0/2] serial: 8250_bcm7271: Fix clock handling Doug Berger
2023-04-27 18:19 ` [PATCH 1/2] serial: 8250_bcm7271: balance clk_enable calls Doug Berger
2023-04-28 17:42   ` Florian Fainelli
2023-04-27 18:19 ` [PATCH 2/2] serial: 8250_bcm7271: fix leak in `brcmuart_probe` Doug Berger
2023-04-27 20:29   ` Christophe JAILLET
2023-04-27 23:29     ` Doug Berger
2023-04-28 17:42   ` Florian Fainelli

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