]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev-builtin-net_id: make names_vio() self-contained
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 27 Sep 2022 07:32:22 +0000 (16:32 +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 in NetNames.

No functional changes, just refactoring.

src/udev/udev-builtin-net_id.c

index a1e6af9df50a1bd9de556a10a0c706e44735074c..aeb7bceaa57271e8becd7005595b776c4ff603bf 100644 (file)
@@ -48,7 +48,6 @@ typedef enum NetNameType {
         NET_PCI,
         NET_USB,
         NET_BCMA,
-        NET_VIO,
         NET_XENVIF,
         NET_PLATFORM,
         NET_NETDEVSIM,
@@ -65,7 +64,6 @@ typedef struct NetNames {
 
         char usb_ports[ALTIFNAMSIZ];
         char bcma_core[ALTIFNAMSIZ];
-        char vio_slot[ALTIFNAMSIZ];
         char xen_slot[ALTIFNAMSIZ];
         char platform_path[ALTIFNAMSIZ];
         char netdevsim_path[ALTIFNAMSIZ];
@@ -502,12 +500,17 @@ static int dev_pci_slot(sd_device *dev, const LinkInfo *info, NetNames *names) {
         return 0;
 }
 
-static int names_vio(sd_device *dev, NetNames *names) {
+static int names_vio(sd_device *dev, const char *prefix, bool test) {
         sd_device *parent;
         unsigned busid, slotid, ethid;
         const char *syspath, *subsystem;
         int r;
 
+        assert(dev);
+        assert(prefix);
+
+        /* get ibmveth/ibmvnic slot-based names. */
+
         /* check if our direct parent is a VIO device with no other bus in-between */
         r = sd_device_get_parent(dev, &parent);
         if (r < 0)
@@ -534,10 +537,11 @@ static int names_vio(sd_device *dev, NetNames *names) {
         if (r != 3)
                 return -EINVAL;
 
-        xsprintf(names->vio_slot, "v%u", slotid);
-        names->type = NET_VIO;
+        char str[ALTIFNAMSIZ];
+        if (snprintf_ok(str, sizeof str, "%sv%u", prefix, slotid))
+                udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str);
         log_device_debug(dev, "Vio slot identifier: slotid=%u %s %s",
-                         slotid, special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), names->vio_slot);
+                         slotid, special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), str + strlen(prefix));
         return 0;
 }
 
@@ -1192,15 +1196,7 @@ static int builtin_net_id(UdevEvent *event, int argc, char *argv[], bool test) {
         (void) names_mac(dev, prefix, test);
         (void) names_devicetree(dev, prefix, test);
         (void) names_ccw(dev, prefix, test);
-
-        /* get ibmveth/ibmvnic slot-based names. */
-        if (names_vio(dev, &names) >= 0 && names.type == NET_VIO) {
-                char str[ALTIFNAMSIZ];
-
-                if (snprintf_ok(str, sizeof str, "%s%s", prefix, names.vio_slot))
-                        udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str);
-                return 0;
-        }
+        (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) {