]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev-builtin-net_id: make names_platform() self-contained
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 27 Sep 2022 07:44:29 +0000 (16:44 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 29 Jul 2023 13:14:24 +0000 (22:14 +0900)
It is not necessary to store its partial result into NetNames.

No functional changes, just refactoring.

src/udev/udev-builtin-net_id.c

index dbeabf8f0d75e57282278efb77c8ed14c94ca845..37014cd73b5ffd0372c4abe2237f6896a0ad90fa 100644 (file)
@@ -49,7 +49,6 @@ typedef enum NetNameType {
         NET_USB,
         NET_BCMA,
         NET_XENVIF,
-        NET_PLATFORM,
         NET_NETDEVSIM,
 } NetNameType;
 
@@ -65,7 +64,6 @@ typedef struct NetNames {
         char usb_ports[ALTIFNAMSIZ];
         char bcma_core[ALTIFNAMSIZ];
         char xen_slot[ALTIFNAMSIZ];
-        char platform_path[ALTIFNAMSIZ];
         char netdevsim_path[ALTIFNAMSIZ];
 } NetNames;
 
@@ -564,13 +562,18 @@ static int names_vio(sd_device *dev, const char *prefix, bool test) {
 #define PLATFORM_PATTERN4 "/sys/devices/platform/%4s%4x:%2x/net/eth%u"
 #define PLATFORM_PATTERN3 "/sys/devices/platform/%3s%4x:%2x/net/eth%u"
 
-static int names_platform(sd_device *dev, NetNames *names, bool test) {
+static int names_platform(sd_device *dev, const char *prefix, bool test) {
         sd_device *parent;
         char vendor[5];
         unsigned model, instance, ethid;
         const char *syspath, *pattern, *validchars, *subsystem;
         int r;
 
+        assert(dev);
+        assert(prefix);
+
+        /* get ACPI path names for ARM64 platform devices */
+
         /* check if our direct parent is a platform device with no other bus in-between */
         r = sd_device_get_parent(dev, &parent);
         if (r < 0)
@@ -621,10 +624,11 @@ static int names_platform(sd_device *dev, NetNames *names, bool test) {
 
         ascii_strlower(vendor);
 
-        xsprintf(names->platform_path, "a%s%xi%u", vendor, model, instance);
-        names->type = NET_PLATFORM;
-        log_device_debug(dev, "Platform identifier: vendor=%s model=%u instance=%u %s %s",
-                         vendor, model, instance, special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), names->platform_path);
+        char str[ALTIFNAMSIZ];
+        if (snprintf_ok(str, sizeof str, "%sa%s%xi%u", prefix, vendor, model, instance))
+                udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
+        log_device_debug(dev, "Platform identifier: vendor=%s model=%x instance=%u %s %s",
+                         vendor, model, instance, special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), str + strlen(prefix));
         return 0;
 }
 
@@ -1212,15 +1216,7 @@ static int builtin_net_id(UdevEvent *event, int argc, char *argv[], bool test) {
         (void) names_devicetree(dev, prefix, test);
         (void) names_ccw(dev, prefix, test);
         (void) names_vio(dev, prefix, test);
-
-        /* get ACPI path names for ARM64 platform devices */
-        if (names_platform(dev, &names, test) >= 0 && names.type == NET_PLATFORM) {
-                char str[ALTIFNAMSIZ];
-
-                if (snprintf_ok(str, sizeof str, "%s%s", prefix, names.platform_path))
-                        udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
-                return 0;
-        }
+        (void) names_platform(dev, prefix, test);
 
         /* get netdevsim path names */
         if (names_netdevsim(dev, &info, &names) >= 0 && names.type == NET_NETDEVSIM) {