backlight: ignore error if the backlight device is already removed
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 5 Jan 2022 09:26:46 +0000 (18:26 +0900)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 13 Jan 2022 10:12:22 +0000 (11:12 +0100)
Fixes #21997.

(cherry picked from commit f0f65087834198d4dabf8b389ddc34223400aab7)
(cherry picked from commit b4c57e1b1c249f28f13a86637d8854c920bcf26d)
(cherry picked from commit a69c240157e2ca066130c12bb061e0065f2c2425)

src/backlight/backlight.c

index 86927be62e98cd61eb541446f86f8e5a435863cb..e37473cc55c41e8b5d838779ffc62b0f3298a97e 100644 (file)
@@ -401,8 +401,16 @@ static int run(int argc, char *argv[]) {
                 return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Not a backlight or LED device: '%s:%s'", ss, sysname);
 
         r = sd_device_new_from_subsystem_sysname(&device, ss, sysname);
-        if (r < 0)
-                return log_error_errno(r, "Failed to get backlight or LED device '%s:%s': %m", ss, sysname);
+        if (r < 0) {
+                bool ignore = r == -ENODEV;
+
+                /* Some drivers, e.g. for AMD GPU, removes acpi backlight device soon after it is added.
+                 * See issue #21997. */
+                log_full_errno(ignore ? LOG_DEBUG : LOG_ERR, r,
+                               "Failed to get backlight or LED device '%s:%s'%s: %m",
+                               ss, sysname, ignore ? ", ignoring" : "");
+                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. */