summaryrefslogtreecommitdiff
path: root/src/udev/udev-builtin-net_id.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/udev/udev-builtin-net_id.c')
-rw-r--r--src/udev/udev-builtin-net_id.c96
1 files changed, 46 insertions, 50 deletions
diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c
index 945585d82a..36994360c7 100644
--- a/src/udev/udev-builtin-net_id.c
+++ b/src/udev/udev-builtin-net_id.c
@@ -115,6 +115,7 @@
#include "stdio-util.h"
#include "string-util.h"
#include "udev.h"
+#include "udev-util.h"
#define ONBOARD_INDEX_MAX (16*1024-1)
@@ -236,11 +237,11 @@ static int dev_pci_slot(struct udev_device *dev, struct netnames *names) {
size_t l;
char *s;
const char *attr, *port_name;
- struct udev_device *pci = NULL;
+ _cleanup_udev_device_unref_ struct udev_device *pci = NULL;
char slots[PATH_MAX];
_cleanup_closedir_ DIR *dir = NULL;
struct dirent *dent;
- int hotplug_slot = 0, err = 0;
+ int hotplug_slot = 0;
if (sscanf(udev_device_get_sysname(names->pcidev), "%x:%x:%x.%u", &domain, &bus, &slot, &func) != 4)
return -ENOENT;
@@ -270,21 +271,20 @@ static int dev_pci_slot(struct udev_device *dev, struct netnames *names) {
/* ACPI _SUN — slot user number */
pci = udev_device_new_from_subsystem_sysname(udev, "subsystem", "pci");
- if (!pci) {
- err = -ENOENT;
- goto out;
- }
+ if (!pci)
+ return -ENOENT;
+
+ if (!snprintf_ok(slots, sizeof slots, "%s/slots", udev_device_get_syspath(pci)))
+ return -ENAMETOOLONG;
- xsprintf(slots, "%s/slots", udev_device_get_syspath(pci));
dir = opendir(slots);
- if (!dir) {
- err = -errno;
- goto out;
- }
+ if (!dir)
+ return -errno;
FOREACH_DIRENT_ALL(dent, dir, break) {
int i;
- char *rest, *address, str[PATH_MAX];
+ char *rest, str[PATH_MAX];
+ _cleanup_free_ char *address = NULL;
if (dent->d_name[0] == '.')
continue;
@@ -294,13 +294,11 @@ static int dev_pci_slot(struct udev_device *dev, struct netnames *names) {
if (i < 1)
continue;
- xsprintf(str, "%s/%s/address", slots, dent->d_name);
- if (read_one_line_file(str, &address) >= 0) {
+ if (snprintf_ok(str, sizeof str, "%s/%s/address", slots, dent->d_name) &&
+ read_one_line_file(str, &address) >= 0)
/* match slot address with device by stripping the function */
- if (strneq(address, udev_device_get_sysname(names->pcidev), strlen(address)))
+ if (streq(address, udev_device_get_sysname(names->pcidev)))
hotplug_slot = i;
- free(address);
- }
if (hotplug_slot > 0)
break;
@@ -321,9 +319,8 @@ static int dev_pci_slot(struct udev_device *dev, struct netnames *names) {
if (l == 0)
names->pci_slot[0] = '\0';
}
-out:
- udev_device_unref(pci);
- return err;
+
+ return 0;
}
static int names_vio(struct udev_device *dev, struct netnames *names) {
@@ -517,7 +514,6 @@ static int names_ccw(struct udev_device *dev, struct netnames *names) {
const char *bus_id, *subsys;
size_t bus_id_len;
size_t bus_id_start;
- int rc;
assert(dev);
assert(names);
@@ -559,9 +555,9 @@ static int names_ccw(struct udev_device *dev, struct netnames *names) {
bus_id += bus_id_start < bus_id_len ? bus_id_start : bus_id_len - 1;
/* Store the CCW bus-ID for use as network device name */
- rc = snprintf(names->ccw_busid, sizeof(names->ccw_busid), "c%s", bus_id);
- if (rc >= 0 && rc < (int)sizeof(names->ccw_busid))
+ if (snprintf_ok(names->ccw_busid, sizeof(names->ccw_busid), "c%s", bus_id))
names->type = NET_CCW;
+
return 0;
}
@@ -674,7 +670,7 @@ static int builtin_net_id(struct udev_device *dev, int argc, char *argv[], bool
if (err >= 0 && names.type == NET_CCW) {
char str[IFNAMSIZ];
- if (snprintf(str, sizeof(str), "%s%s", prefix, names.ccw_busid) < (int)sizeof(str))
+ if (snprintf_ok(str, sizeof str, "%s%s", prefix, names.ccw_busid))
udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
goto out;
}
@@ -684,7 +680,7 @@ static int builtin_net_id(struct udev_device *dev, int argc, char *argv[], bool
if (err >= 0 && names.type == NET_VIO) {
char str[IFNAMSIZ];
- if (snprintf(str, sizeof(str), "%s%s", prefix, names.vio_slot) < (int)sizeof(str))
+ if (snprintf_ok(str, sizeof str, "%s%s", prefix, names.vio_slot))
udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str);
goto out;
}
@@ -694,7 +690,7 @@ static int builtin_net_id(struct udev_device *dev, int argc, char *argv[], bool
if (err >= 0 && names.type == NET_PLATFORM) {
char str[IFNAMSIZ];
- if (snprintf(str, sizeof(str), "%s%s", prefix, names.platform_path) < (int)sizeof(str))
+ if (snprintf_ok(str, sizeof str, "%s%s", prefix, names.platform_path))
udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
goto out;
}
@@ -708,21 +704,21 @@ static int builtin_net_id(struct udev_device *dev, int argc, char *argv[], bool
if (names.type == NET_PCI) {
char str[IFNAMSIZ];
- if (names.pci_onboard[0])
- if (snprintf(str, sizeof(str), "%s%s", prefix, names.pci_onboard) < (int)sizeof(str))
- udev_builtin_add_property(dev, test, "ID_NET_NAME_ONBOARD", str);
+ if (names.pci_onboard[0] &&
+ snprintf_ok(str, sizeof str, "%s%s", prefix, names.pci_onboard))
+ udev_builtin_add_property(dev, test, "ID_NET_NAME_ONBOARD", str);
- if (names.pci_onboard_label)
- if (snprintf(str, sizeof(str), "%s%s", prefix, names.pci_onboard_label) < (int)sizeof(str))
- udev_builtin_add_property(dev, test, "ID_NET_LABEL_ONBOARD", str);
+ if (names.pci_onboard_label &&
+ snprintf_ok(str, sizeof str, "%s%s", prefix, names.pci_onboard_label))
+ udev_builtin_add_property(dev, test, "ID_NET_LABEL_ONBOARD", str);
- if (names.pci_path[0])
- if (snprintf(str, sizeof(str), "%s%s", prefix, names.pci_path) < (int)sizeof(str))
- udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
+ if (names.pci_path[0] &&
+ snprintf_ok(str, sizeof str, "%s%s", prefix, names.pci_path))
+ udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
- if (names.pci_slot[0])
- if (snprintf(str, sizeof(str), "%s%s", prefix, names.pci_slot) < (int)sizeof(str))
- udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str);
+ if (names.pci_slot[0] &&
+ snprintf_ok(str, sizeof str, "%s%s", prefix, names.pci_slot))
+ udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str);
goto out;
}
@@ -731,13 +727,13 @@ static int builtin_net_id(struct udev_device *dev, int argc, char *argv[], bool
if (err >= 0 && names.type == NET_USB) {
char str[IFNAMSIZ];
- if (names.pci_path[0])
- if (snprintf(str, sizeof(str), "%s%s%s", prefix, names.pci_path, names.usb_ports) < (int)sizeof(str))
- udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
+ if (names.pci_path[0] &&
+ snprintf_ok(str, sizeof str, "%s%s%s", prefix, names.pci_path, names.usb_ports))
+ udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
- if (names.pci_slot[0])
- if (snprintf(str, sizeof(str), "%s%s%s", prefix, names.pci_slot, names.usb_ports) < (int)sizeof(str))
- udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str);
+ if (names.pci_slot[0] &&
+ snprintf_ok(str, sizeof str, "%s%s%s", prefix, names.pci_slot, names.usb_ports))
+ udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str);
goto out;
}
@@ -746,13 +742,13 @@ static int builtin_net_id(struct udev_device *dev, int argc, char *argv[], bool
if (err >= 0 && names.type == NET_BCMA) {
char str[IFNAMSIZ];
- if (names.pci_path[0])
- if (snprintf(str, sizeof(str), "%s%s%s", prefix, names.pci_path, names.bcma_core) < (int)sizeof(str))
- udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
+ 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])
- if (snprintf(str, sizeof(str), "%s%s%s", prefix, names.pci_slot, names.bcma_core) < (int)sizeof(str))
- udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str);
+ if (names.pci_slot[0] &&
+ snprintf(str, sizeof str, "%s%s%s", prefix, names.pci_slot, names.bcma_core))
+ udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str);
goto out;
}
out: