]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev-builtin-net_id: make dev_devicetree_onboard() self-contained
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 27 Sep 2022 07:05:34 +0000 (16:05 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 29 Jul 2023 13:14:24 +0000 (22:14 +0900)
and rename it to names_devicetree().

No functional changes, just refactoring.

src/udev/udev-builtin-net_id.c

index 194723545ec0f3e4a56fc74e3aa6426f82c27b31..ea8fa439e3b6e5b1974fbfffc0b3ef82f6ef931f 100644 (file)
@@ -53,7 +53,6 @@ typedef enum NetNameType {
         NET_XENVIF,
         NET_PLATFORM,
         NET_NETDEVSIM,
-        NET_DEVICETREE,
 } NetNameType;
 
 typedef struct NetNames {
@@ -72,7 +71,6 @@ typedef struct NetNames {
         char xen_slot[ALTIFNAMSIZ];
         char platform_path[ALTIFNAMSIZ];
         char netdevsim_path[ALTIFNAMSIZ];
-        char devicetree_onboard[ALTIFNAMSIZ];
 } NetNames;
 
 typedef struct LinkInfo {
@@ -613,15 +611,22 @@ static int names_platform(sd_device *dev, NetNames *names, bool test) {
         return 0;
 }
 
-static int dev_devicetree_onboard(sd_device *dev, NetNames *names) {
+static int names_devicetree(sd_device *dev, const char *prefix, bool test) {
         _cleanup_(sd_device_unrefp) sd_device *aliases_dev = NULL, *ofnode_dev = NULL, *devicetree_dev = NULL;
         const char *ofnode_path, *ofnode_syspath, *devicetree_syspath;
         sd_device *parent;
         int r;
 
+        assert(dev);
+        assert(prefix);
+
         if (!naming_scheme_has(NAMING_DEVICETREE_ALIASES))
                 return 0;
 
+        /* only ethernet supported for now */
+        if (!streq(prefix, "en"))
+                return -EOPNOTSUPP;
+
         /* check if our direct parent has an of_node */
         r = sd_device_get_parent(dev, &parent);
         if (r < 0)
@@ -693,8 +698,11 @@ static int dev_devicetree_onboard(sd_device *dev, NetNames *names) {
                         return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EEXIST),
                                         "Ethernet alias conflict: ethernet and ethernet0 both exist");
 
-                xsprintf(names->devicetree_onboard, "d%u", i);
-                names->type = NET_DEVICETREE;
+                char str[ALTIFNAMSIZ];
+                if (snprintf_ok(str, sizeof str, "%sd%u", prefix, i))
+                        udev_builtin_add_property(dev, test, "ID_NET_NAME_ONBOARD", str);
+                log_device_debug(dev, "devicetree identifier: alias_index=%u %s \"%s\"",
+                                 i, special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), str + strlen(prefix));
                 return 0;
         }
 
@@ -1183,15 +1191,7 @@ static int builtin_net_id(UdevEvent *event, int argc, char *argv[], bool test) {
         udev_builtin_add_property(dev, test, "ID_NET_NAMING_SCHEME", naming_scheme()->name);
 
         (void) names_mac(dev, prefix, test);
-
-        /* get devicetree aliases; only ethernet supported for now  */
-        if (streq(prefix, "en") && dev_devicetree_onboard(dev, &names) >= 0 &&
-            names.type == NET_DEVICETREE) {
-                char str[ALTIFNAMSIZ];
-
-                if (snprintf_ok(str, sizeof str, "%s%s", prefix, names.devicetree_onboard))
-                        udev_builtin_add_property(dev, test, "ID_NET_NAME_ONBOARD", str);
-        }
+        (void) names_devicetree(dev, prefix, test);
 
         /* get path names for Linux on System z network devices */
         if (names_ccw(dev, &names) >= 0 && names.type == NET_CCW) {