Skip to contentSkip to conversation

leds: core: Refactor led_update_brightness() to use standard pattern

PATCH Applied Andy Shevchenko 3 participants 3 messages Oct 16, 2023 – Oct 19, 2023 LED

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 leds: core: Refactor led_update_brightness() to use standard pattern

The standard conditional pattern is to check for errors first and bail out if any. Refactor led_update_brightness() accordingly.

While at it, drop unneeded assignment and return 0 unconditionally on success.

---
v2: added tag (Denis), Cc'ed to the updated list of LED maintainers

 drivers/leds/led-core.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/leds/led-core.c +6 -6
index 2230239283d0..89c9806cc97f 100644
@@ -364,17 +364,17 @@ 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;
+
+		led_cdev->brightness = ret;
 	}
 
-	return ret;
+	return 0;
 }
 EXPORT_SYMBOL_GPL(led_update_brightness);
 
Signature · 1 line
2.40.0.1.gaa8946217a0b
Reviewed-by on v2 1/1
#1 lore raw

Hi,

Quoted 8 lines · Andy Shevchenko

The standard conditional pattern is to check for errors first and bail out if any. Refactor led_update_brightness() accordingly.

While at it, drop unneeded assignment and return 0 unconditionally on success.

Thanks, patch looks good to me:

Regards,

Hans

Quoted 33 lines

---
v2: added tag (Denis), Cc'ed to the updated list of LED maintainers

 drivers/leds/led-core.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/leds/led-core.c +6 -6
index 2230239283d0..89c9806cc97f 100644
@@ -364,17 +364,17 @@ 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;
+
+		led_cdev->brightness = ret;
 	}
 
-	return ret;
+	return 0;
 }
 EXPORT_SYMBOL_GPL(led_update_brightness);
 
maintainer Applied
#2 lore raw

Re: (subset) [PATCH v2 1/1] leds: core: Refactor led_update_brightness() to use standard pattern

In reply to Andy Shevchenko
Quoted 8 lines · Andy Shevchenko

The standard conditional pattern is to check for errors first and bail out if any. Refactor led_update_brightness() accordingly.

While at it, drop unneeded assignment and return 0 unconditionally on success.

[...]

Applied, thanks!

[1/1] leds: core: Refactor led_update_brightness() to use standard pattern

      commit: 0e5bb700df6a6fe36d9487a4e0a82a4c7b1f7b4e

--
Lee Jones [李琼斯]