Skip to contentSkip to conversation

pwm: lpss: Use positive condition in pwm_lpss_prepare()

PATCH In review Andy Shevchenko 2 participants 4 messages Jan 15, 2020 – Sep 16, 2020

Subsystems (2)
lore
Share & tools
lore

Andy Shevchenko

author reviewer
#0 lore raw

PATCH 1/1 pwm: lpss: Use positive condition in pwm_lpss_prepare()

For better readability and maintenance use positive condition in pwm_lpss_prepare(). No functional change intended.

---
 drivers/pwm/pwm-lpss.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/pwm/pwm-lpss.c +5 -4
index 75bbfe5f3bc2..6930a1d99860 100644
@@ -109,10 +109,11 @@ static void pwm_lpss_prepare(struct pwm_lpss_chip *lpwm, struct pwm_device *pwm,
 	ctrl |= (u32) base_unit << PWM_BASE_UNIT_SHIFT;
 	ctrl |= on_time_div;
 
-	if (orig_ctrl != ctrl) {
-		pwm_lpss_write(pwm, ctrl);
-		pwm_lpss_write(pwm, ctrl | PWM_SW_UPDATE);
-	}
+	if (orig_ctrl == ctrl)
+		return;
+
+	pwm_lpss_write(pwm, ctrl);
+	pwm_lpss_write(pwm, ctrl | PWM_SW_UPDATE);
 }
 
 static inline void pwm_lpss_cond_enable(struct pwm_device *pwm, bool cond)
Signature · 1 line
2.24.1
#1 lore raw
Quoted 15 lines · Andy Shevchenko

For better readability and maintenance use positive condition in pwm_lpss_prepare(). No functional change intended.

---
 drivers/pwm/pwm-lpss.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/pwm/pwm-lpss.c +0 -0
index 75bbfe5f3bc2..6930a1d99860 100644
@@ -109,10 +109,11 @@ static void pwm_lpss_prepare(struct pwm_lpss_chip *lpwm, struct pwm_device *pwm,
 	ctrl |= (u32) base_unit << PWM_BASE_UNIT_SHIFT;
 	ctrl |= on_time_div;

drivers/pwm/pwm-lpss.c static void pwm_lpss_prepare(struct pwm_lpss_chip *lpwm, struct pwm_device *pwm, · line 116

Quoted 10 lines
drivers/pwm/pwm-lpss.c +5 -4
 
-	if (orig_ctrl != ctrl) {
-		pwm_lpss_write(pwm, ctrl);
-		pwm_lpss_write(pwm, ctrl | PWM_SW_UPDATE);
-	}
+	if (orig_ctrl == ctrl)
+		return;
+
+	pwm_lpss_write(pwm, ctrl);
+	pwm_lpss_write(pwm, ctrl | PWM_SW_UPDATE);

I personally don't think that readability improved much and think that the old code is more intuitive. ("If the wanted register value doesn't match the actual value, write the value out.")

But I agree that the patch doesn't introduce a semantic difference.

What made you create that patch? Is it really that you read through the driver and thought "Huh, this is more complicated than necessary."?

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |
author reviewer
#2 lore raw
Quoted 1 line · Uwe Kleine-König

On Wed, Jan 15, 2020 at 05:08:49PM +0200, Andy Shevchenko wrote:

...

Quoted 14 lines

drivers/pwm/pwm-lpss.c static void pwm_lpss_prepare(struct pwm_lpss_chip *lpwm, struct pwm_device *pwm, · line 116

Quoted 9 lines
drivers/pwm/pwm-lpss.c +5 -4
-	if (orig_ctrl != ctrl) {
-		pwm_lpss_write(pwm, ctrl);
-		pwm_lpss_write(pwm, ctrl | PWM_SW_UPDATE);
-	}
+	if (orig_ctrl == ctrl)
+		return;
+
+	pwm_lpss_write(pwm, ctrl);
+	pwm_lpss_write(pwm, ctrl | PWM_SW_UPDATE);

I personally don't think that readability improved much and think that the old code is more intuitive. ("If the wanted register value doesn't match the actual value, write the value out.")

Quoted 4 lines

But I agree that the patch doesn't introduce a semantic difference.

What made you create that patch? Is it really that you read through the driver and thought "Huh, this is more complicated than necessary."?

My personal preferable style. So, I can survive with the current code. Thanks for review!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author reviewer
#3 lore raw
In reply to Uwe Kleine-König
Quoted 3 lines · Uwe Kleine-König
Quoted 2 lines · Andy Shevchenko

For better readability and maintenance use positive condition in pwm_lpss_prepare(). No functional change intended.

...

Quoted 18 lines

drivers/pwm/pwm-lpss.c static void pwm_lpss_prepare(struct pwm_lpss_chip *lpwm, struct pwm_device *pwm, · line 116

Quoted 13 lines
drivers/pwm/pwm-lpss.c +5 -4
@@ -109,10 +109,11 @@ static void pwm_lpss_prepare(struct pwm_lpss_chip *lpwm, struct pwm_device *pwm,
 	ctrl |= (u32) base_unit << PWM_BASE_UNIT_SHIFT;
 	ctrl |= on_time_div;
 
-	if (orig_ctrl != ctrl) {
-		pwm_lpss_write(pwm, ctrl);
-		pwm_lpss_write(pwm, ctrl | PWM_SW_UPDATE);
-	}
+	if (orig_ctrl == ctrl)
+		return;
+
+	pwm_lpss_write(pwm, ctrl);
+	pwm_lpss_write(pwm, ctrl | PWM_SW_UPDATE);

I personally don't think that readability improved much and think that the old code is more intuitive. ("If the wanted register value doesn't match the actual value, write the value out.")

Quoted 4 lines

But I agree that the patch doesn't introduce a semantic difference.

What made you create that patch? Is it really that you read through the driver and thought "Huh, this is more complicated than necessary."?

Fun fact that d6d54bacb1dd could be slightly better with this applied, but we have what we have :-)

Signature · 2 lines
With Best Regards,
Andy Shevchenko