Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Denis Osterland-Heim <denis.osterland@diehl.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20231016153051.1409074-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Lee Jones <lee@kernel.org>

authored by

Andy Shevchenko and committed by
Lee Jones
49e50aad 78cbcfd8

+6 -6
+6 -6
drivers/leds/led-core.c
··· 364 364 365 365 int led_update_brightness(struct led_classdev *led_cdev) 366 366 { 367 - int ret = 0; 367 + int ret; 368 368 369 369 if (led_cdev->brightness_get) { 370 370 ret = led_cdev->brightness_get(led_cdev); 371 - if (ret >= 0) { 372 - led_cdev->brightness = ret; 373 - return 0; 374 - } 371 + if (ret < 0) 372 + return ret; 373 + 374 + led_cdev->brightness = ret; 375 375 } 376 376 377 - return ret; 377 + return 0; 378 378 } 379 379 EXPORT_SYMBOL_GPL(led_update_brightness); 380 380