Skip to contentSkip to conversation

pwm: sifive: simplify if-if to if-else

PATCH Applied Wan Jiabing 3 participants 3 messages Apr 8, 2022 – May 20, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pwm: sifive: simplify if-if to if-else

use if and else instead of if(A) and if (!A).

---
 drivers/pwm/pwm-sifive.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/pwm/pwm-sifive.c +2 -3
index 253c4a17d255..e6d05a329002 100644
@@ -138,10 +138,9 @@ static int pwm_sifive_enable(struct pwm_chip *chip, bool enable)
 			dev_err(ddata->chip.dev, "Enable clk failed\n");
 			return ret;
 		}
-	}
-
-	if (!enable)
+	} else {
 		clk_disable(ddata->clk);
+	}
 
 	return 0;
 }
Signature · 1 line
2.35.1
#1 lore raw
Quoted 14 lines · Wan Jiabing

use if and else instead of if(A) and if (!A).

---
 drivers/pwm/pwm-sifive.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/pwm/pwm-sifive.c +0 -0
index 253c4a17d255..e6d05a329002 100644
@@ -138,10 +138,9 @@ static int pwm_sifive_enable(struct pwm_chip *chip, bool enable)
 			dev_err(ddata->chip.dev, "Enable clk failed\n");
 			return ret;

drivers/pwm/pwm-sifive.c static int pwm_sifive_enable(struct pwm_chip *chip, bool enable) · line 146

Quoted 10 lines
drivers/pwm/pwm-sifive.c +2 -3
 		}
-	}
-
-	if (!enable)
+	} else {
 		clk_disable(ddata->clk);
+	}
 
 	return 0;
 }

The patch looks fine. I wonder if it would be sensible to clean up even
more: pwm_sifive_apply() is only a single caller of pwm_sifive_enable(). If this is optimized to skip the duty_cycle and period calculation for the state->enabled = false case and just disables the clock this should still work.

Also I wonder if there is a clk mismatch issue in this driver: .probe enables the clk and if the PWM is off (i.e. .get_state diagnoses that) the clock will never be disabled while the driver is bound, will it?

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |