From: Emil Velikov Date: Mon, 7 Sep 2015 11:37:57 +0000 (+0100) Subject: xf86drm: flex platform specifics into drmParsePciBusInfo X-Git-Tag: libdrm-2.4.66~80 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=536e0deba3829e194aafda6d9a1d9e938ba8277a;p=platform%2Fupstream%2Flibdrm.git xf86drm: flex platform specifics into drmParsePciBusInfo This will allow one to reuse the core drmGetDevices implementation on other platforms. Keeping all the platform specifics in ParseFoo. On the plus side this saves a bit of code :) Signed-off-by: Emil Velikov Acked-by: Alex Deucher --- diff --git a/xf86drm.c b/xf86drm.c index a5a7b41..b4c5aa0 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -2855,23 +2855,33 @@ static int drmParseSubsystemType(const char *str) return -EINVAL; } -static int drmParsePciBusInfo(const char *str, drmPciBusInfoPtr info) +static int drmParsePciBusInfo(int maj, int min, drmPciBusInfoPtr info) { + char path[PATH_MAX + 1]; + char data[128]; + char *str; int domain, bus, dev, func; - char *value; + int fd, ret; - if (str == NULL) - return -EINVAL; + snprintf(path, PATH_MAX, "/sys/dev/char/%d:%d/device/uevent", maj, min); + fd = open(path, O_RDONLY); + if (fd < 0) + return -errno; - value = strstr(str, "PCI_SLOT_NAME="); - if (value == NULL) - return -EINVAL; + ret = read(fd, data, sizeof(data)); + close(fd); + if (ret < 0) + return -errno; - value += strlen("PCI_SLOT_NAME="); +#define TAG "PCI_SLOT_NAME=" + str = strstr(data, TAG); + if (str == NULL) + return -EINVAL; - if (sscanf(value, "%04x:%02x:%02x.%1u", + if (sscanf(str, TAG "%04x:%02x:%02x.%1u", &domain, &bus, &dev, &func) != 4) return -EINVAL; +#undef TAG info->domain = domain; info->bus = bus; @@ -2981,7 +2991,6 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices) struct stat sbuf = {0}; char node[PATH_MAX + 1] = ""; char path[PATH_MAX + 1] = ""; - char data[128] = ""; unsigned char config[64] = ""; int node_type, subsystem_type; int maj, min; @@ -3030,22 +3039,7 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices) goto free_locals; } - snprintf(path, PATH_MAX, "/sys/dev/char/%d:%d/device/uevent", - maj, min); - fd = open(path, O_RDONLY); - if (fd < 0) { - ret = -errno; - goto free_locals; - } - ret = read(fd, data, sizeof(data)); - if (ret < 0) { - ret = -errno; - close(fd); - goto free_locals; - } - - ret = drmParsePciBusInfo(data, pcibus); - close(fd); + ret = drmParsePciBusInfo(maj, min, pcibus); if (ret) goto free_locals;