From 17761fb3bfa494c565683222a707cfa28d14b560 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Sun, 17 Apr 2022 14:59:06 +0900
Subject: [PATCH] sd-device: use ERRNO_IS_DEVICE_ABSENT() at one more place

Conflict:NA
Reference:https://github.com/systemd/systemd/commit/17761fb3bfa494c565683222a707cfa28d14b560

---
 src/libsystemd/sd-device/device-private.c |  7 +++----
 src/libsystemd/sd-device/sd-device.c      | 11 +++++++----
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/libsystemd/sd-device/device-private.c b/src/libsystemd/sd-device/device-private.c
index 6ad49c05a0..47b62e7421 100644
--- a/src/libsystemd/sd-device/device-private.c
+++ b/src/libsystemd/sd-device/device-private.c
@@ -835,10 +835,9 @@ int device_shallow_clone(sd_device *old_device, sd_device **new_device) {
                         return r;
         }
 
-        /* And then read uevent file, but ignore errors, as some devices seem to return a spurious
-         * error on read, e.g. -ENODEV, and even if ifindex or devnum is set in the above,
-         * sd_device_get_ifindex() or sd_device_get_devnum() fails. See. #19788. */
-        (void) device_read_uevent_file(ret);
+        r = device_read_uevent_file(ret);
+        if (r < 0)
+                return r;
 
         *new_device = TAKE_PTR(ret);
         return 0;
diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c
index 6c2d1243ac..0c5b2a67e3 100644
--- a/src/libsystemd/sd-device/sd-device.c
+++ b/src/libsystemd/sd-device/sd-device.c
@@ -724,11 +724,14 @@ int device_read_uevent_file(sd_device *device) {
         path = strjoina(syspath, "/uevent");
 
         r = read_full_virtual_file(path, &uevent, &uevent_len);
-        if (IN_SET(r, -EACCES, -ENOENT))
-                /* The uevent files may be write-only, or the device may not have uevent file. */
-                return 0;
-        if (r < 0)
+        if (r < 0) {
+                /* The uevent files may be write-only, the device may be already removed, or the device
+                 * may not have the uevent file. */
+                if (r == -EACCES || ERRNO_IS_DEVICE_ABSENT(r))
+                        return 0;
+
                 return log_device_debug_errno(device, r, "sd-device: Failed to read uevent file '%s': %m", path);
+        }
 
         for (size_t i = 0; i < uevent_len; i++)
                 switch (state) {
-- 
2.39.1

