From: Yu Watanabe Date: Thu, 21 Dec 2023 19:17:06 +0000 (+0900) Subject: backlight: move validity check of max_brightness to get_max_brightness() X-Git-Tag: v256-rc1~1414^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0e1564a261f4af1f17f01806769291656e15e759;p=thirdparty%2Fsystemd.git backlight: move validity check of max_brightness to get_max_brightness() Also rename get_max_brightness() -> read_max_brightness() for consistency with read_brightness(). --- diff --git a/src/backlight/backlight.c b/src/backlight/backlight.c index 5ac9f904a92..363ed380052 100644 --- a/src/backlight/backlight.c +++ b/src/backlight/backlight.c @@ -309,7 +309,8 @@ static int validate_device(sd_device *device) { return true; } -static int get_max_brightness(sd_device *device, unsigned *ret) { +static int read_max_brightness(sd_device *device, unsigned *ret) { + unsigned max_brightness; const char *s; int r; @@ -320,11 +321,22 @@ static int get_max_brightness(sd_device *device, unsigned *ret) { if (r < 0) return log_device_warning_errno(device, r, "Failed to read 'max_brightness' attribute: %m"); - r = safe_atou(s, ret); + r = safe_atou(s, &max_brightness); if (r < 0) return log_device_warning_errno(device, r, "Failed to parse 'max_brightness' \"%s\": %m", s); - return 0; + /* If max_brightness is 0, then there is no actual backlight device. This happens on desktops + * with Asus mainboards that load the eeepc-wmi module. */ + if (max_brightness == 0) { + log_device_warning(device, "Maximum brightness is 0, ignoring device."); + *ret = 0; + return 0; + } + + log_device_debug(device, "Maximum brightness is %u", max_brightness); + + *ret = max_brightness; + return 1; /* valid max brightness */ } static int clamp_brightness( @@ -506,17 +518,9 @@ static int run(int argc, char *argv[]) { return ignore ? 0 : r; } - /* If max_brightness is 0, then there is no actual backlight device. This happens on desktops - * with Asus mainboards that load the eeepc-wmi module. */ - if (get_max_brightness(device, &max_brightness) < 0) - return 0; - - if (max_brightness == 0) { - log_device_warning(device, "Maximum brightness is 0, ignoring device."); - return 0; - } - - log_device_debug(device, "Maximum brightness is %u", max_brightness); + r = read_max_brightness(device, &max_brightness); + if (r <= 0) + return r; escaped_ss = cescape(ss); if (!escaped_ss)