return 0;
}
-static bool is_valid_onboard_index(unsigned long idx) {
+static bool is_valid_onboard_index(unsigned idx) {
/* Some BIOSes report rubbish indexes that are excessively high (2^24-1 is an index VMware likes to
* report for example). Let's define a cut-off where we don't consider the index reliable anymore. We
* pick some arbitrary cut-off, which is somewhere beyond the realistic number of physical network
return idx <= (naming_scheme_has(NAMING_16BIT_INDEX) ? ONBOARD_16BIT_INDEX_MAX : ONBOARD_14BIT_INDEX_MAX);
}
-/* retrieve on-board index number and label from firmware */
-static int dev_pci_onboard(sd_device *dev, const LinkInfo *info, NetNames *names) {
- _cleanup_free_ char *port = NULL;
- unsigned long idx;
- const char *attr;
+static int pci_get_onboard_index(sd_device *dev, unsigned *ret) {
+ unsigned idx;
int r;
assert(dev);
- assert(info);
- assert(names);
+ assert(ret);
/* ACPI _DSM — device specific method for naming a PCI or PCI Express device */
- if (sd_device_get_sysattr_value(names->pcidev, "acpi_index", &attr) >= 0)
- log_device_debug(names->pcidev, "acpi_index=%s", attr);
- else {
+ r = device_get_sysattr_unsigned(dev, "acpi_index", &idx);
+ if (r < 0)
/* SMBIOS type 41 — Onboard Devices Extended Information */
- r = sd_device_get_sysattr_value(names->pcidev, "index", &attr);
- if (r < 0)
- return r;
- log_device_debug(names->pcidev, "index=%s", attr);
- }
-
- r = safe_atolu(attr, &idx);
+ r = device_get_sysattr_unsigned(dev, "index", &idx);
if (r < 0)
- return log_device_debug_errno(names->pcidev, r,
- "Failed to parse onboard index \"%s\": %m", attr);
+ return r;
+
if (idx == 0 && !naming_scheme_has(NAMING_ZERO_ACPI_INDEX))
- return log_device_debug_errno(names->pcidev, SYNTHETIC_ERRNO(EINVAL),
+ return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EINVAL),
"Naming scheme does not allow onboard index==0.");
if (!is_valid_onboard_index(idx))
- return log_device_debug_errno(names->pcidev, SYNTHETIC_ERRNO(ENOENT),
- "Not a valid onboard index: %lu", idx);
+ return log_device_debug_errno(dev, SYNTHETIC_ERRNO(ENOENT),
+ "Not a valid onboard index: %u", idx);
+
+ *ret = idx;
+ return 0;
+}
+
+static int dev_pci_onboard(sd_device *dev, const LinkInfo *info, NetNames *names) {
+ _cleanup_free_ char *port = NULL;
+ unsigned idx = 0; /* avoid false maybe-uninitialized warning */
+ int r;
+
+ assert(dev);
+ assert(info);
+ assert(names);
+
+ /* retrieve on-board index number and label from firmware */
+ r = pci_get_onboard_index(names->pcidev, &idx);
+ if (r < 0)
+ return r;
r = get_port_specifier(dev, /* fallback_to_dev_id = */ false, &port);
if (r < 0)
return r;
- if (!snprintf_ok(names->pci_onboard, sizeof(names->pci_onboard), "o%lu%s", idx, strempty(port)))
+ if (!snprintf_ok(names->pci_onboard, sizeof(names->pci_onboard), "o%u%s", idx, strempty(port)))
names->pci_onboard[0] = '\0';
- log_device_debug(dev, "Onboard index identifier: index=%lu port=%s %s %s",
+ log_device_debug(dev, "Onboard index identifier: index=%u port=%s %s %s",
idx, strna(port),
special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), empty_to_na(names->pci_onboard));