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;
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");
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;
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);
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;
}