udev-builtin-net_id: use sd_device_get_sysnum() to get index of netdevsim

This commit is contained in:
Yu Watanabe
2023-07-29 22:14:24 +09:00
parent f7abd9ede8
commit bc710857d1
+6 -4
View File
@@ -1037,7 +1037,7 @@ static int names_mac(sd_device *dev, const char *prefix, bool test) {
static int names_netdevsim(sd_device *dev, const char *prefix, bool test) {
sd_device *netdevsimdev;
const char *sysname, *phys_port_name;
const char *sysnum, *phys_port_name;
unsigned addr;
int r;
@@ -1052,12 +1052,14 @@ static int names_netdevsim(sd_device *dev, const char *prefix, bool test) {
r = sd_device_get_parent_with_subsystem_devtype(dev, "netdevsim", NULL, &netdevsimdev);
if (r < 0)
return r;
r = sd_device_get_sysname(netdevsimdev, &sysname);
r = sd_device_get_sysnum(netdevsimdev, &sysnum);
if (r < 0)
return r;
if (sscanf(sysname, "netdevsim%u", &addr) != 1)
return -EINVAL;
r = safe_atou(sysnum, &addr);
if (r < 0)
return r;
r = sd_device_get_sysattr_value(dev, "phys_port_name", &phys_port_name);
if (r < 0)