]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/network/networkd-wiphy.c
hwdb: add scancodes for AYANEO devices (#33378)
[thirdparty/systemd.git] / src / network / networkd-wiphy.c
index 38d1ceeba1eae016cd7ceb2f5cf0758d5c679471..441713fa0c876700e36a68b61b10cb704b5bd6c5 100644 (file)
@@ -116,21 +116,12 @@ static int link_get_wiphy(Link *link, Wiphy **ret) {
                 return -EOPNOTSUPP;
 
         if (!link->dev)
-                return -EOPNOTSUPP;
-
-        r = sd_device_get_devtype(link->dev, &s);
-        if (r < 0)
-                return r;
+                return -ENODEV;
 
-        if (!streq_ptr(s, "wlan"))
+        if (!device_is_devtype(link->dev, "wlan"))
                 return -EOPNOTSUPP;
 
-        r = sd_device_get_syspath(link->dev, &s);
-        if (r < 0)
-                return r;
-
-        s = strjoina(s, "/phy80211");
-        r = sd_device_new_from_syspath(&phy, s);
+        r = sd_device_new_child(&phy, link->dev, "phy80211");
         if (r < 0)
                 return r;
 
@@ -219,7 +210,7 @@ int link_rfkilled(Link *link) {
         assert(link);
 
         r = link_get_wiphy(link, &w);
-        if (IN_SET(r, -EOPNOTSUPP, -ENODEV))
+        if (ERRNO_IS_NEG_NOT_SUPPORTED(r) || ERRNO_IS_NEG_DEVICE_ABSENT(r))
                 return false; /* Typically, non-wifi interface or running in container */
         if (r < 0)
                 return log_link_debug_errno(link, r, "Could not get phy: %m");
@@ -272,11 +263,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;
@@ -321,14 +309,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);
 
@@ -348,12 +334,16 @@ 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 (ERRNO_IS_NEG_DEVICE_ABSENT(r))
+                log_wiphy_debug_errno(w, r, "Failed to update wiphy device, ignoring: %m");
+        else if (r < 0)
+                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 (ERRNO_IS_NEG_DEVICE_ABSENT(r))
+                log_wiphy_debug_errno(w, r, "Failed to update rfkill device, ignoring: %m");
+        else if (r < 0)
+                return log_wiphy_warning_errno(w, r, "Failed to update rfkill device: %m");
 
         return 0;
 }