Skip to contentSkip to conversation

pwm: spear: fix check on pwmchip_add() return value

PATCH In review Beniamino Galvani 3 participants 6 messages May 5, 2014 – May 7, 2014 PWM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pwm: spear: fix check on pwmchip_add() return value

pwmchip_add() returns zero on success and a negative value on error, so the condition of the check must be inverted.

---
 drivers/pwm/pwm-spear.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pwm/pwm-spear.c +1 -1
index cb2d4f0..945556d 100644
@@ -222,7 +222,7 @@ static int spear_pwm_probe(struct platform_device *pdev)
 	}
 
 	ret = pwmchip_add(&pc->chip);
-	if (!ret) {
+	if (ret < 0) {
 		clk_unprepare(pc->clk);
 		dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret);
 	}
Signature · 1 line
1.7.10.4
Acked-by on v1 1/1
#1 lore raw
Quoted 13 lines · Beniamino Galvani

pwmchip_add() returns zero on success and a negative value on error, so the condition of the check must be inverted.

---
 drivers/pwm/pwm-spear.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pwm/pwm-spear.c +0 -0
index cb2d4f0..945556d 100644

drivers/pwm/pwm-spear.c static int spear_pwm_probe(struct platform_device *pdev) · line 228

Quoted 8 lines
drivers/pwm/pwm-spear.c +1 -1
@@ -222,7 +222,7 @@ static int spear_pwm_probe(struct platform_device *pdev)
        }
 
        ret = pwmchip_add(&pc->chip);
-       if (!ret) {
+       if (ret < 0) {
                clk_unprepare(pc->clk);
                dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret);
        }
#2 lore raw
Quoted 16 lines · Viresh Kumar
Quoted 15 lines · Beniamino Galvani

pwmchip_add() returns zero on success and a negative value on error, so the condition of the check must be inverted.

---
 drivers/pwm/pwm-spear.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pwm/pwm-spear.c +0 -0
index cb2d4f0..945556d 100644
@@ -222,7 +222,7 @@ static int spear_pwm_probe(struct platform_device *pdev)
        }
 
Quoted 6 lines

drivers/pwm/pwm-spear.c static int spear_pwm_probe(struct platform_device *pdev) · line 228

Quoted 6 lines
drivers/pwm/pwm-spear.c +1 -1
        ret = pwmchip_add(&pc->chip);
-       if (!ret) {
+       if (ret < 0) {
                clk_unprepare(pc->clk);
                dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret);
        }

So the current code would run clk_unprepare() on success, but not on failure. Does that cause any harm? Is the device still usable after this? I'm asking because I'm not sure if this is linux-next material or should be a fix for 3.15 (and possibly backported to stable).

Thierry

#3 lore raw
Quoted 2 lines · Thierry Reding

So the current code would run clk_unprepare() on success, but not on failure. Does that cause any harm?

Yeah, that would make the device unusable as clk_enable will always fail.

Quoted 1 line

Is the device still usable after this?

Yes, this will fix the bug.

Quoted 2 lines

I'm asking because I'm not sure if this is linux-next material or should be a fix for 3.15 (and possibly backported to stable).

IMO, it should be sent for stable: v3.8+

#4 lore raw
Quoted 5 lines · Viresh Kumar
Quoted 2 lines · Thierry Reding

So the current code would run clk_unprepare() on success, but not on failure. Does that cause any harm?

Yeah, that would make the device unusable as clk_enable will always fail.

Hmm... so ever since this driver was merged in 3.8 it was completely broken and nobody noticed? Interesting.

Quoted 8 lines
Quoted 1 line

Is the device still usable after this?

Yes, this will fix the bug.

Quoted 2 lines

I'm asking because I'm not sure if this is linux-next material or should be a fix for 3.15 (and possibly backported to stable).

IMO, it should be sent for stable: v3.8+

Since this was obviously broken since 3.8 and nobody noticed I wonder if there's really an urgent need for this in stable.

Thierry

#5 lore raw
Quoted 2 lines · Thierry Reding

Since this was obviously broken since 3.8 and nobody noticed I wonder if there's really an urgent need for this in stable.

I don't think there is any urgent need of this, in case somebody wants we can add it later. :)