Blame SOURCES/0029-Deal-with-devices-that-don-t-have-a-device-link-in-s.patch

80b73c
From e83002b08aa6db57b90d89968ab8d34f6c7f73cf Mon Sep 17 00:00:00 2001
80b73c
From: Peter Jones <pjones@redhat.com>
80b73c
Date: Mon, 17 Sep 2018 16:13:24 -0400
80b73c
Subject: [PATCH 29/30] Deal with devices that don't have a ->device link in
80b73c
 sysfs
80b73c
80b73c
Signed-off-by: Peter Jones <pjones@redhat.com>
80b73c
---
80b73c
 src/linux.c | 53 ++++++++++++++++++++++++++++++-----------------------
80b73c
 1 file changed, 30 insertions(+), 23 deletions(-)
80b73c
80b73c
diff --git a/src/linux.c b/src/linux.c
80b73c
index 19eb488c992..6d405af8a76 100644
80b73c
--- a/src/linux.c
80b73c
+++ b/src/linux.c
80b73c
@@ -389,43 +389,50 @@ struct device HIDDEN
80b73c
 
80b73c
         rc = sysfs_readlink(&tmpbuf, "block/%s/device", dev->disk_name);
80b73c
         if (rc < 0 || !tmpbuf) {
80b73c
-                efi_error("readlink of /sys/block/%s/device failed",
80b73c
+                debug("readlink of /sys/block/%s/device failed",
80b73c
                           dev->disk_name);
80b73c
-                goto err;
80b73c
+
80b73c
+                dev->device = strdup("");
80b73c
+        } else {
80b73c
+                dev->device = strdup(tmpbuf);
80b73c
         }
80b73c
 
80b73c
-        dev->device = strdup(tmpbuf);
80b73c
         if (!dev->device) {
80b73c
                 efi_error("strdup(\"%s\") failed", tmpbuf);
80b73c
                 goto err;
80b73c
         }
80b73c
 
80b73c
-        rc = sysfs_readlink(&tmpbuf, "block/%s/device/driver", dev->disk_name);
80b73c
-        if (rc < 0 || !tmpbuf) {
80b73c
-                if (errno == ENOENT) {
80b73c
-                        /*
80b73c
-                         * nvme, for example, will have nvme0n1/device point
80b73c
-                         * at nvme0, and we need to look for device/driver
80b73c
-                         * there.
80b73c
-                         */
80b73c
-                        rc = sysfs_readlink(&tmpbuf,
80b73c
-                                            "block/%s/device/device/driver",
80b73c
-                                            dev->disk_name);
80b73c
-                }
80b73c
+        if (dev->device[0] != 0) {
80b73c
+                rc = sysfs_readlink(&tmpbuf, "block/%s/device/driver", dev->disk_name);
80b73c
                 if (rc < 0 || !tmpbuf) {
80b73c
-                        efi_error("readlink of /sys/block/%s/device/driver failed",
80b73c
-                                  dev->disk_name);
80b73c
+                        if (errno == ENOENT) {
80b73c
+                                /*
80b73c
+                                 * nvme, for example, will have nvme0n1/device point
80b73c
+                                 * at nvme0, and we need to look for device/driver
80b73c
+                                 * there.
80b73c
+                                 */
80b73c
+                                rc = sysfs_readlink(&tmpbuf,
80b73c
+                                                    "block/%s/device/device/driver",
80b73c
+                                                    dev->disk_name);
80b73c
+                        }
80b73c
+                        if (rc < 0 || !tmpbuf) {
80b73c
+                                efi_error("readlink of /sys/block/%s/device/driver failed",
80b73c
+                                          dev->disk_name);
80b73c
+                                goto err;
80b73c
+                        }
80b73c
+                }
80b73c
+
80b73c
+                linkbuf = pathseg(tmpbuf, -1);
80b73c
+                if (!linkbuf) {
80b73c
+                        efi_error("could not get segment -1 of \"%s\"", tmpbuf);
80b73c
                         goto err;
80b73c
                 }
80b73c
-        }
80b73c
 
80b73c
-        linkbuf = pathseg(tmpbuf, -1);
80b73c
-        if (!linkbuf) {
80b73c
-                efi_error("could not get segment -1 of \"%s\"", tmpbuf);
80b73c
-                goto err;
80b73c
+                dev->driver = strdup(linkbuf);
80b73c
+        } else {
80b73c
+                dev->driver = strdup("");
80b73c
         }
80b73c
 
80b73c
-        dev->driver = strdup(linkbuf);
80b73c
         if (!dev->driver) {
80b73c
                 efi_error("strdup(\"%s\") failed", linkbuf);
80b73c
                 goto err;
80b73c
-- 
80b73c
2.17.1
80b73c