mirror of
https://github.com/systemd/systemd.git
synced 2026-08-08 00:51:19 +00:00
udev-builtin-net_id: split-out pci_get_onboard_index() from dev_pci_onboard()
This also changes the onboard index type to unsigned, as it is at most 2^16 - 1. Hence, unsigned is enough. Then, we can use device_get_sysattr_unsigned() helper function. This also drops mostly redundant debugging logs. The index will be logged later anyway.
This commit is contained in:
@@ -230,7 +230,7 @@ static int get_port_specifier(sd_device *dev, bool fallback_to_dev_id, char **re
|
||||
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
|
||||
@@ -240,47 +240,54 @@ static bool is_valid_onboard_index(unsigned long idx) {
|
||||
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 pci_get_onboard_index(sd_device *dev, unsigned *ret) {
|
||||
unsigned idx;
|
||||
int r;
|
||||
|
||||
assert(dev);
|
||||
assert(ret);
|
||||
|
||||
/* ACPI _DSM — device specific method for naming a PCI or PCI Express device */
|
||||
r = device_get_sysattr_unsigned(dev, "acpi_index", &idx);
|
||||
if (r < 0)
|
||||
/* SMBIOS type 41 — Onboard Devices Extended Information */
|
||||
r = device_get_sysattr_unsigned(dev, "index", &idx);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (idx == 0 && !naming_scheme_has(NAMING_ZERO_ACPI_INDEX))
|
||||
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(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 long idx;
|
||||
const char *attr;
|
||||
unsigned idx = 0; /* avoid false maybe-uninitialized warning */
|
||||
int r;
|
||||
|
||||
assert(dev);
|
||||
assert(info);
|
||||
assert(names);
|
||||
|
||||
/* 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 {
|
||||
/* 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);
|
||||
/* retrieve on-board index number and label from firmware */
|
||||
r = pci_get_onboard_index(names->pcidev, &idx);
|
||||
if (r < 0)
|
||||
return log_device_debug_errno(names->pcidev, r,
|
||||
"Failed to parse onboard index \"%s\": %m", attr);
|
||||
if (idx == 0 && !naming_scheme_has(NAMING_ZERO_ACPI_INDEX))
|
||||
return log_device_debug_errno(names->pcidev, 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 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));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user