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

93 lines
3.6 KiB
Diff
Raw Normal View History

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