From 58b26055f428fd6a99ffb889caa5e2472352b641 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 3 Oct 2013 14:08:36 +0100 Subject: [PATCH] intel: Querying device attributes must be non-NULL Check first for a NULL platform device before querying the attributes or else suffer a segfault during PCI probing. Signed-off-by: Chris Wilson --- src/intel_device.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/intel_device.c b/src/intel_device.c index c41179a4..668ce19b 100644 --- a/src/intel_device.c +++ b/src/intel_device.c @@ -223,8 +223,16 @@ static char *find_render_node(int fd) #if defined(ODEV_ATTRIB_PATH) static char *get_path(struct xf86_platform_device *dev) { - const char *path = xf86_get_platform_device_attrib(dev, ODEV_ATTRIB_PATH); - return path ? strdup(path) : NULL; + const char *path; + + if (dev == NULL) + return NULL; + + path = xf86_get_platform_device_attrib(dev, ODEV_ATTRIB_PATH); + if (path == NULL) + return NULL; + + return strdup(path); } #else @@ -239,9 +247,15 @@ static char *get_path(struct xf86_platform_device *dev) #if defined(ODEV_ATTRIB_FD) && 0 static int get_fd(struct xf86_platform_device *dev) { - const char *str = xf86_get_platform_device_attrib(dev, ODEV_ATTRIB_FD); + const char *str; + + if (dev == NULL) + return -1; + + str = xf86_get_platform_device_attrib(dev, ODEV_ATTRIB_FD); if (str == NULL) return -1; + return atoi(str); }