From c03916164d08f5eb8e24daa21a9e29871bdfe2ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 1 Apr 2021 10:19:07 +0200 Subject: 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. --- src/backlight/backlight.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/backlight') diff --git a/src/backlight/backlight.c b/src/backlight/backlight.c index 86927be62e..7c0970a60c 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(); -- cgit v1.2.1