Skip to contentSkip to conversation

drivers/tty/serial: Add missing clk_disable_unprepare()

PATCH In review Guo Mengqi 3 participants 7 messages Jun 17, 2022 – Jul 15, 2022

Subsystems (3)
lore
Share & tools
lore

Guo Mengqi

author
#0 lore raw

PATCH 1/1 drivers/tty/serial: Add missing clk_disable_unprepare()

Add missing clk_disable_unprepare() when get clk rate fails.

---
 drivers/tty/serial/8250/8250_bcm2835aux.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/tty/serial/8250/8250_bcm2835aux.c +4 -2
index 2a1226a78a0c..21939bb44613 100644
@@ -166,8 +166,10 @@ static int bcm2835aux_serial_probe(struct platform_device *pdev)
 	uartclk = clk_get_rate(data->clk);
 	if (!uartclk) {
 		ret = device_property_read_u32(&pdev->dev, "clock-frequency", &uartclk);
-		if (ret)
-			return dev_err_probe(&pdev->dev, ret, "could not get clk rate\n");
+		if (ret) {
+			dev_err_probe(&pdev->dev, ret, "could not get clk rate\n");
+			goto dis_clk;
+		}
 	}
 
 	/* the HW-clock divider for bcm2835aux is 8,
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 3 lines · Guo Mengqi

Add missing clk_disable_unprepare() when get clk rate fails.

How did the robot report it?

How was this tested?

You have read the documentation for how to correctly report problems found and fixed by automated tools, right? Please update the changelog to include all of that information.

thanks,

greg k-h

author
#2 lore raw

PATCH v2 1/1 serial: 8250_bcm2835aux: Add missing clk_disable_unprepare()

In reply to Guo Mengqi

The error path when get clock frequency fails in bcm2835aux_serial driver does not correctly disable the clock.

This flaw was found using a static analysis tool "Hulk Robot", which reported the following warning when analyzing linux-next/master:

    drivers/tty/serial/8250/8250_bcm2835aux.c:
    warning: clk_disable_unprepare_missing.cocci

The cocci script checks for the existence of clk_disable_unprepare() paired with clk_prepare_enable().

Add the missing clk_disable_unprepare() to the error path.

---
v2:
- Change title to more standard format
- Add details about how Hulk Robot report this issue.

---
 drivers/tty/serial/8250/8250_bcm2835aux.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/tty/serial/8250/8250_bcm2835aux.c +4 -2
index d9f1e618cfbd..f5718ff0cd8a 100644
@@ -167,8 +167,10 @@ static int bcm2835aux_serial_probe(struct platform_device *pdev)
 	uartclk = clk_get_rate(data->clk);
 	if (!uartclk) {
 		ret = device_property_read_u32(&pdev->dev, "clock-frequency", &uartclk);
-		if (ret)
-			return dev_err_probe(&pdev->dev, ret, "could not get clk rate\n");
+		if (ret) {
+			dev_err_probe(&pdev->dev, ret, "could not get clk rate\n");
+			goto dis_clk;
+		}
 	}
 
 	/* the HW-clock divider for bcm2835aux is 8,
Signature · 1 line
2.17.1
#3 lore raw
In reply to Guo Mengqi
Quoted 4 lines · Guo Mengqi' via BCM-KERNEL-FEEDBACK-LIST,PDL

Add missing clk_disable_unprepare() when get clk rate fails.

Looks about right, can we use the same prefix as the majority of other changes:

serial: 8250_bcm2835aux: Add missing clk_disable_unprepare()

and slap a:

Fixes fcc446c8aa63 ("serial: 8250_bcm2835aux: Add ACPI support")

Thanks!

Quoted 21 lines
---
  drivers/tty/serial/8250/8250_bcm2835aux.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/tty/serial/8250/8250_bcm2835aux.c +4 -2
index 2a1226a78a0c..21939bb44613 100644
@@ -166,8 +166,10 @@ static int bcm2835aux_serial_probe(struct platform_device *pdev)
  	uartclk = clk_get_rate(data->clk);
  	if (!uartclk) {
  		ret = device_property_read_u32(&pdev->dev, "clock-frequency", &uartclk);
-		if (ret)
-			return dev_err_probe(&pdev->dev, ret, "could not get clk rate\n");
+		if (ret) {
+			dev_err_probe(&pdev->dev, ret, "could not get clk rate\n");
+			goto dis_clk;
+		}
  	}
 
  	/* the HW-clock divider for bcm2835aux is 8,
Signature · 1 line
Florian
#4 lore raw

Hi Florian,

Yes I found it's better to use title of same style. I did not pay attention to this.

I will send a new version of this patch.

Thank you!

Quoted 41 lines · Florian Fainelli
Quoted 4 lines · Guo Mengqi' via BCM-KERNEL-FEEDBACK-LIST,PDL

Add missing clk_disable_unprepare() when get clk rate fails.

Looks about right, can we use the same prefix as the majority of other changes:

serial: 8250_bcm2835aux: Add missing clk_disable_unprepare()

and slap a:

Fixes fcc446c8aa63 ("serial: 8250_bcm2835aux: Add ACPI support")

Thanks!

Quoted 22 lines

---
  drivers/tty/serial/8250/8250_bcm2835aux.c | 6 ++++--

  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/tty/serial/8250/8250_bcm2835aux.c +4 -2
index 2a1226a78a0c..21939bb44613 100644
@@ -166,8 +166,10 @@ static int bcm2835aux_serial_probe(struct 
 platform_device *pdev)
       uartclk = clk_get_rate(data->clk);
       if (!uartclk) {
           ret = device_property_read_u32(&pdev->dev, "clock-frequency", &uartclk);
-        if (ret)
-            return dev_err_probe(&pdev->dev, ret, "could not get clk 
 rate\n");
+        if (ret) {
+            dev_err_probe(&pdev->dev, ret, "could not get clk rate\n");
+            goto dis_clk;
+        }
       }

        /* the HW-clock divider for bcm2835aux is 8,

author
#5 lore raw

PATCH v3 1/1 serial: 8250_bcm2835aux: Add missing clk_disable_unprepare()

The error path when get clock frequency fails in bcm2835aux_serial driver does not correctly disable the clock.

This flaw was found using a static analysis tool "Hulk Robot", which reported the following warning when analyzing linux-next/master:

    drivers/tty/serial/8250/8250_bcm2835aux.c:
    warning: clk_disable_unprepare_missing.cocci

The cocci script checks for the existence of clk_disable_unprepare() paired with clk_prepare_enable().

Add the missing clk_disable_unprepare() to the error path.

Fixes fcc446c8aa63 ("serial: 8250_bcm2835aux: Add ACPI support")

---
v2:
- Change title to more standard format
- Add details about how Hulk Robot report this issue. v3:
- add which commit this patch fixes

---
 drivers/tty/serial/8250/8250_bcm2835aux.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/tty/serial/8250/8250_bcm2835aux.c +4 -2
index 047e14ccb165..15a2387a5b25 100644
@@ -167,8 +167,10 @@ static int bcm2835aux_serial_probe(struct platform_device *pdev)
 	uartclk = clk_get_rate(data->clk);
 	if (!uartclk) {
 		ret = device_property_read_u32(&pdev->dev, "clock-frequency", &uartclk);
-		if (ret)
-			return dev_err_probe(&pdev->dev, ret, "could not get clk rate\n");
+		if (ret) {
+			dev_err_probe(&pdev->dev, ret, "could not get clk rate\n");
+			goto dis_clk;
+		}
 	}
 
 	/* the HW-clock divider for bcm2835aux is 8,
Signature · 1 line
2.17.1
Reviewed-by on v3 1/1
#6 lore raw

Re: [PATCH -next v3] serial: 8250_bcm2835aux: Add missing clk_disable_unprepare()

Quoted 9 lines · Guo Mengqi

The error path when get clock frequency fails in bcm2835aux_serial driver does not correctly disable the clock.

This flaw was found using a static analysis tool "Hulk Robot", which reported the following warning when analyzing linux-next/master:

     drivers/tty/serial/8250/8250_bcm2835aux.c:
     warning: clk_disable_unprepare_missing.cocci
Quoted 8 lines

The cocci script checks for the existence of clk_disable_unprepare() paired with clk_prepare_enable().

Add the missing clk_disable_unprepare() to the error path.

Fixes fcc446c8aa63 ("serial: 8250_bcm2835aux: Add ACPI support")
Signature · 1 line
Florian