From: Zbigniew Jędrzejewski-Szmek Date: Thu, 1 Apr 2021 08:19:07 +0000 (+0200) Subject: backlight: refactor get_max_brightness() to appease gcc X-Git-Tag: v249-rc1~486^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c03916164d08f5eb8e24daa21a9e29871bdfe2ac;p=thirdparty%2Fsystemd.git backlight: refactor get_max_brightness() to appease gcc The old code was just fine, but gcc doesn't understand that max_brightness is initialized. Let's rework it a bit to move some logic to the main function. Now get_max_brightness() just retrieves and parses the attribute, and the main function decides what to do with it. --- diff --git a/src/backlight/backlight.c b/src/backlight/backlight.c index 86927be62e9..7c0970a60c2 100644 --- a/src/backlight/backlight.c +++ b/src/backlight/backlight.c @@ -226,26 +226,20 @@ static int validate_device(sd_device *device) { } static int get_max_brightness(sd_device *device, unsigned *ret) { - const char *max_brightness_str; - unsigned max_brightness; + const char *s; int r; assert(device); assert(ret); - r = sd_device_get_sysattr_value(device, "max_brightness", &max_brightness_str); + r = sd_device_get_sysattr_value(device, "max_brightness", &s); if (r < 0) return log_device_warning_errno(device, r, "Failed to read 'max_brightness' attribute: %m"); - r = safe_atou(max_brightness_str, &max_brightness); + r = safe_atou(s, ret); if (r < 0) - return log_device_warning_errno(device, r, "Failed to parse 'max_brightness' \"%s\": %m", max_brightness_str); - - if (max_brightness <= 0) - return log_device_warning_errno(device, SYNTHETIC_ERRNO(EINVAL), "Maximum brightness is 0, ignoring device."); + return log_device_warning_errno(device, r, "Failed to parse 'max_brightness' \"%s\": %m", s); - log_device_debug(device, "Maximum brightness is %u", max_brightness); - *ret = max_brightness; return 0; } @@ -409,6 +403,13 @@ static int run(int argc, char *argv[]) { 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); + escaped_ss = cescape(ss); if (!escaped_ss) return log_oom();