[2/2] serial: 8250_bcm7271: fix leak in `brcmuart_probe`

Message ID 20230427181916.2983697-3-opendmb@gmail.com
State New
Headers
Series serial: 8250_bcm7271: Fix clock handling |

Commit Message

Doug Berger April 27, 2023, 6:19 p.m. UTC
  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(-)
  

Comments

Christophe JAILLET April 27, 2023, 8:29 p.m. UTC | #1
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;
  
Doug Berger April 27, 2023, 11:29 p.m. UTC | #2
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
  
Florian Fainelli April 28, 2023, 5:42 p.m. UTC | #3
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>
  

Patch

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;