Skip to contentSkip to conversation

leds: core: Refactor led_update_brightness()

PATCH In review Andy Shevchenko 1 participant 2 messages Aug 22, 2019 LED

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 leds: core: Refactor led_update_brightness()

There is neither need to have an additional assignment of ret, nor the non-so-standard conditional. Moreover, the resulting code better to read and less LOCs.

---
 drivers/leds/led-core.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/leds/led-core.c +5 -6
index f1f718dbe0f8..810053fbe0f6 100644
@@ -308,17 +308,16 @@ EXPORT_SYMBOL_GPL(led_set_brightness_sync);
 
 int led_update_brightness(struct led_classdev *led_cdev)
 {
-	int ret = 0;
+	int ret;
 
 	if (led_cdev->brightness_get) {
 		ret = led_cdev->brightness_get(led_cdev);
-		if (ret >= 0) {
-			led_cdev->brightness = ret;
-			return 0;
-		}
+		if (ret < 0)
+			return ret;
 	}
 
-	return ret;
+	led_cdev->brightness = ret;
+	return 0;
 }
 EXPORT_SYMBOL_GPL(led_update_brightness);
 
Signature · 1 line
2.23.0.rc1
#1 lore raw
Quoted 3 lines · Andy Shevchenko

There is neither need to have an additional assignment of ret, nor the non-so-standard conditional. Moreover, the resulting code better to read and less LOCs.

Please, ignore this, it's not correct in this form.

Signature · 2 lines
With Best Regards,
Andy Shevchenko