[PATCH libdrm 1/2] xf86drm: Pass PCI path rather than maj/min when parsing sysfs files
Alistair Popple <[email protected]> Fri, 31 Jul 2026 16:04:14 +1000
| Newsgroups | dev.linux.lists.nova-gpu,org.freedesktop.lists.dri-devel |
|---|---|
| Message-ID | <[email protected]> |
Both parse_separate_sysfs_files() and parse_config_sysfs_file() take a maj/min device numbers and resolve the actual PCI path using get_pci_path(). This was to allow virtio to resolve the correct path. However there is no reason to call get_pci_path() in these functions - in all cases the caller can call get_pci_path() prior to calling these functions. This results in a minor code simplification for a future change which allows callers to provide the PCI device path instead of using get_pci_path(). Signed-off-by: Alistair Popple <[email protected]> --- xf86drm.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/xf86drm.c b/xf86drm.c index a8b39a31..25f2a3ff 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -3833,7 +3833,7 @@ static int drmGetMaxNodeName(void) } #ifdef __linux__ -static int parse_separate_sysfs_files(int maj, int min, +static int parse_separate_sysfs_files(const char *pci_path, drmPciDeviceInfoPtr device, bool ignore_revision) { @@ -3844,13 +3844,11 @@ static int parse_separate_sysfs_files(int maj, int min, "subsystem_vendor", "subsystem_device", }; - char path[PATH_MAX + 1], pci_path[PATH_MAX + 1]; + char path[PATH_MAX + 1]; unsigned int data[ARRAY_SIZE(attrs)]; FILE *fp; int ret; - get_pci_path(maj, min, pci_path); - for (unsigned i = ignore_revision ? 1 : 0; i < ARRAY_SIZE(attrs); i++) { if (snprintf(path, PATH_MAX, "%s/%s", pci_path, attrs[i]) < 0) return -errno; @@ -3875,15 +3873,13 @@ static int parse_separate_sysfs_files(int maj, int min, return 0; } -static int parse_config_sysfs_file(int maj, int min, +static int parse_config_sysfs_file(const char *pci_path, drmPciDeviceInfoPtr device) { - char path[PATH_MAX + 1], pci_path[PATH_MAX + 1]; + char path[PATH_MAX + 1]; unsigned char config[64]; int fd, ret; - get_pci_path(maj, min, pci_path); - if (snprintf(path, PATH_MAX, "%s/config", pci_path) < 0) return -errno; @@ -3911,11 +3907,15 @@ static int drmParsePciDeviceInfo(int maj, int min, uint32_t flags) { #ifdef __linux__ + char pci_path[PATH_MAX + 1]; + + get_pci_path(maj, min, pci_path); + if (!(flags & DRM_DEVICE_GET_PCI_REVISION)) - return parse_separate_sysfs_files(maj, min, device, true); + return parse_separate_sysfs_files(pci_path, device, true); - if (parse_separate_sysfs_files(maj, min, device, false)) - return parse_config_sysfs_file(maj, min, device); + if (parse_separate_sysfs_files(pci_path, device, false)) + return parse_config_sysfs_file(pci_path, device); return 0; #elif defined(__OpenBSD__) || defined(__DragonFly__) -- 2.54.0