1
0
mirror of https://github.com/systemd/systemd.git synced 2025-02-09 13:57:42 +03:00

udev-builtin-net_id: make names_platform() self-contained

It is not necessary to store its partial result into NetNames.

No functional changes, just refactoring.
This commit is contained in:
Yu Watanabe 2022-09-27 16:44:29 +09:00
parent ded2b1d093
commit 0bf8330d68

View 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) {