From: Yu Watanabe Date: Tue, 1 Aug 2023 13:26:21 +0000 (+0900) Subject: udev-builtin-net_id: drop redundant copy of BCMA identifier in names_bcma() X-Git-Tag: v255-rc1~843^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f831aef509089dd2deb03ea6e6947fc29f534567;p=thirdparty%2Fsystemd.git udev-builtin-net_id: drop redundant copy of BCMA identifier in names_bcma() Then, this makes names based on the BCMA and PCI identifiers in names_bcma(). No functional change, just refactoring. --- diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c index d61ed0cd7a2..4eeae179c83 100644 --- a/src/udev/udev-builtin-net_id.c +++ b/src/udev/udev-builtin-net_id.c @@ -46,7 +46,6 @@ typedef enum NetNameType { NET_UNDEF, NET_PCI, - NET_BCMA, } NetNameType; typedef struct NetNames { @@ -57,8 +56,6 @@ typedef struct NetNames { char pci_path[ALTIFNAMSIZ]; char pci_onboard[ALTIFNAMSIZ]; const char *pci_onboard_label; - - char bcma_core[ALTIFNAMSIZ]; } NetNames; /* skip intermediate virtio devices */ @@ -1028,14 +1025,17 @@ static int get_bcma_specifier(sd_device *dev, char **ret) { return 0; } -static int names_bcma(sd_device *dev, NetNames *names) { +static int names_bcma(sd_device *dev, const char *prefix, NetNames *names, bool test) { _cleanup_free_ char *suffix = NULL; sd_device *bcmadev; int r; assert(dev); + assert(prefix); assert(names); + /* Broadcom bus */ + r = sd_device_get_parent_with_subsystem_devtype(dev, "bcma", NULL, &bcmadev); if (r < 0) return log_device_debug_errno(dev, r, "Could not get bcma parent device: %m"); @@ -1044,9 +1044,14 @@ static int names_bcma(sd_device *dev, NetNames *names) { if (r < 0) return r; - size_t l = strscpy(names->bcma_core, sizeof(names->bcma_core), strempty(suffix)); - if (l != 0) - names->type = NET_BCMA; + char str[ALTIFNAMSIZ]; + if (names->pci_path[0] && + snprintf_ok(str, sizeof str, "%s%s%s", prefix, names->pci_path, suffix)) + udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str); + + if (names->pci_slot[0] && + snprintf_ok(str, sizeof str, "%s%s%s", prefix, names->pci_slot, suffix)) + udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str); return 0; } @@ -1412,20 +1417,7 @@ static int builtin_net_id(UdevEvent *event, int argc, char *argv[], bool test) { } (void) names_usb(dev, prefix, &names, test); - - /* Broadcom bus */ - if (names_bcma(dev, &names) >= 0 && names.type == NET_BCMA) { - char str[ALTIFNAMSIZ]; - - if (names.pci_path[0] && - snprintf_ok(str, sizeof str, "%s%s%s", prefix, names.pci_path, names.bcma_core)) - udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str); - - if (names.pci_slot[0] && - snprintf_ok(str, sizeof str, "%s%s%s", prefix, names.pci_slot, names.bcma_core)) - udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str); - return 0; - } + (void) names_bcma(dev, prefix, &names, test); return 0; }