]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: wiphy: use ERRNO_IS_DEVICE_ABSENT()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 28 Jul 2022 07:39:11 +0000 (16:39 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 5 Aug 2022 12:49:27 +0000 (21:49 +0900)
src/network/networkd-wiphy.c

index bc93252cb06cfec4b77c918933efde4966f31f7d..63874cdf98ec3c38ea1fe7a9cc14280c3e51fbe3 100644 (file)
@@ -116,7 +116,7 @@ static int link_get_wiphy(Link *link, Wiphy **ret) {
                 return -EOPNOTSUPP;
 
         if (!link->dev)
-                return -EOPNOTSUPP;
+                return -ENODEV;
 
         r = sd_device_get_devtype(link->dev, &s);
         if (r < 0)
@@ -214,10 +214,11 @@ int link_rfkilled(Link *link) {
         assert(link);
 
         r = link_get_wiphy(link, &w);
-        if (IN_SET(r, -EOPNOTSUPP, -ENODEV))
-                return false; /* Typically, non-wifi interface or running in container */
-        if (r < 0)
+        if (r < 0) {
+                if (ERRNO_IS_NOT_SUPPORTED(r) || ERRNO_IS_DEVICE_ABSENT(r))
+                        return false; /* Typically, non-wifi interface or running in container */
                 return log_link_debug_errno(link, r, "Could not get phy: %m");
+        }
 
         return wiphy_rfkilled(w);
 }
@@ -267,11 +268,8 @@ static int wiphy_update_device(Wiphy *w) {
         w->dev = sd_device_unref(w->dev);
 
         r = sd_device_new_from_subsystem_sysname(&dev, "ieee80211", w->name);
-        if (r < 0) {
-                /* The corresponding syspath may not exist yet, and may appear later. */
-                log_wiphy_debug_errno(w, r, "Failed to get wiphy device, ignoring: %m");
-                return 0;
-        }
+        if (r < 0)
+                return r;
 
         if (DEBUG_LOGGING) {
                 const char *s = NULL;
@@ -316,14 +314,12 @@ static int wiphy_update_rfkill(Wiphy *w) {
                 return r;
 
         rfkill = sd_device_enumerator_get_device_first(e);
-        if (!rfkill) {
+        if (!rfkill)
                 /* rfkill device may not detected by the kernel yet, and may appear later. */
-                log_wiphy_debug_errno(w, SYNTHETIC_ERRNO(ENODEV), "No rfkill device found, ignoring.");
-                return 0;
-        }
+                return -ENODEV;
 
         if (sd_device_enumerator_get_device_next(e))
-                return log_wiphy_debug_errno(w, SYNTHETIC_ERRNO(EEXIST), "Multiple rfkill devices found.");
+                return -ENXIO; /* multiple devices found */
 
         w->rfkill = sd_device_ref(rfkill);
 
@@ -343,12 +339,20 @@ static int wiphy_update(Wiphy *w) {
         assert(w);
 
         r = wiphy_update_device(w);
-        if (r < 0)
-                return log_wiphy_debug_errno(w, r, "Failed to update wiphy device: %m");
+        if (r < 0) {
+                if (ERRNO_IS_DEVICE_ABSENT(r))
+                        log_wiphy_debug_errno(w, r, "Failed to update wiphy device, ignoring: %m");
+                else
+                        return log_wiphy_warning_errno(w, r, "Failed to update wiphy device: %m");
+        }
 
         r = wiphy_update_rfkill(w);
-        if (r < 0)
-                return log_wiphy_debug_errno(w, r, "Failed to update rfkill device: %m");
+        if (r < 0) {
+                if (ERRNO_IS_DEVICE_ABSENT(r))
+                        log_wiphy_debug_errno(w, r, "Failed to update rfkill device, ignoring: %m");
+                else
+                        return log_wiphy_warning_errno(w, r, "Failed to update rfkill device: %m");
+        }
 
         return 0;
 }