summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHuacai Chen <chenhc@lemote.com>2020-07-05 05:59:58 -0400
committerHuacai Chen <chenhc@lemote.com>2020-07-28 16:14:55 +0800
commit9fbd3e43dd9e13700df96b508c3d97f77e2b9f7e (patch)
treeeef07ce6f8d0813eb58139296a442fbe0dbe4d84
parent591916ea9e7a77f68f436b4a541402d9deadfe64 (diff)
linux: Fix platform device probe for DT-based PCI
On a DT-base PCI platform, the sysfs path of vga device is like this: /sys/devices/platform/bus@10000000/1a000000.pci/pci0000:00/0000:00:11.0/0000:04:00.0. Then the ID_PATH from udev is platform-1a000000.pci-pci-0000:04:00.0 and the BusID will be pci-0000:04:00.0, which causes Xorg start fail. This is because config_udev_odev_setup_attribs() use strstr() to search the first "pci-" in ID_PATH. To fix this, we implement a strrstr() function and use it to search the last "pci-" in ID_PATH, which can get a correct BusID. Signed-off-by: Huacai Chen <chenhc@lemote.com>
-rw-r--r--config/udev.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/config/udev.c b/config/udev.c
index bbbda802d..c51bda98a 100644
--- a/config/udev.c
+++ b/config/udev.c
@@ -477,6 +477,31 @@ config_udev_fini(void)
#ifdef CONFIG_UDEV_KMS
+/* Find the last occurrence of the needle in haystack */
+static char *strrstr(const char *haystack, const char *needle)
+{
+ char *prev, *last, *tmp;
+
+ prev = strstr(haystack, needle);
+ if (!prev)
+ return NULL;
+
+ last = prev;
+ tmp = prev + 1;
+
+ while (tmp) {
+ last = strstr(tmp, needle);
+ if (!last)
+ return prev;
+ else {
+ prev = last;
+ tmp = prev + 1;
+ }
+ }
+
+ return last;
+}
+
static void
config_udev_odev_setup_attribs(struct udev_device *udev_device, const char *path, const char *syspath,
int major, int minor,
@@ -491,7 +516,7 @@ config_udev_odev_setup_attribs(struct udev_device *udev_device, const char *path
attribs->minor = minor;
value = udev_device_get_property_value(udev_device, "ID_PATH");
- if (value && (str = strstr(value, "pci-"))) {
+ if (value && (str = strrstr(value, "pci-"))) {
attribs->busid = XNFstrdup(str);
attribs->busid[3] = ':';
}