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

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