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

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