summaryrefslogtreecommitdiff
path: root/platform-intel.c
diff options
context:
space:
mode:
authorDimitri John Ledkov <xnox@ubuntu.com>2017-05-12 12:32:07 +0100
committerDimitri John Ledkov <xnox@ubuntu.com>2017-05-12 12:32:07 +0100
commit77b19ed5f259bc62680acf2b1a3454baa2472bc5 (patch)
tree7441d8d057c09e54c8ea23c984f2ccdf22c98649 /platform-intel.c
parentca114f3c76374493f0fd64f8ea0a9b96ae9b1dc5 (diff)
New upstream release.
Diffstat (limited to 'platform-intel.c')
-rw-r--r--platform-intel.c50
1 files changed, 37 insertions, 13 deletions
diff --git a/platform-intel.c b/platform-intel.c
index 88818f3..9867697 100644
--- a/platform-intel.c
+++ b/platform-intel.c
@@ -48,9 +48,9 @@ static void free_sys_dev(struct sys_dev **list)
struct sys_dev *find_driver_devices(const char *bus, const char *driver)
{
/* search sysfs for devices driven by 'driver' */
- char path[292];
- char link[256];
- char *c;
+ char path[PATH_MAX];
+ char link[PATH_MAX];
+ char *c, *p;
DIR *driver_dir;
struct dirent *de;
struct sys_dev *head = NULL;
@@ -123,6 +123,22 @@ struct sys_dev *find_driver_devices(const char *bus, const char *driver)
if (devpath_to_ll(path, "class", &class) != 0)
continue;
+ /*
+ * Each VMD device (domain) adds separate PCI bus, it is better
+ * to store path as a path to that bus (easier further
+ * determination which NVMe dev is connected to this particular
+ * VMD domain).
+ */
+ if (type == SYS_DEV_VMD) {
+ sprintf(path, "/sys/bus/%s/drivers/%s/%s/domain/device",
+ bus, driver, de->d_name);
+ }
+ p = realpath(path, NULL);
+ if (p == NULL) {
+ pr_err("Unable to get real path for '%s'\n", path);
+ continue;
+ }
+
/* start / add list entry */
if (!head) {
head = xmalloc(sizeof(*head));
@@ -140,16 +156,9 @@ struct sys_dev *find_driver_devices(const char *bus, const char *driver)
list->dev_id = (__u16) dev_id;
list->class = (__u32) class;
list->type = type;
- /* Each VMD device (domain) adds separate PCI bus, it is better to
- * store path as a path to that bus (easier further determination which
- * NVMe dev is connected to this particular VMD domain).
- */
- if (type == SYS_DEV_VMD) {
- sprintf(path, "/sys/bus/%s/drivers/%s/%s/domain/device",
- bus, driver, de->d_name);
- }
- list->path = realpath(path, NULL);
list->next = NULL;
+ list->path = p;
+
if ((list->pci_id = strrchr(list->path, '/')) != NULL)
list->pci_id++;
}
@@ -178,6 +187,16 @@ struct sys_dev *device_by_id(__u16 device_id)
return NULL;
}
+struct sys_dev *device_by_id_and_path(__u16 device_id, const char *path)
+{
+ struct sys_dev *iter;
+
+ for (iter = intel_devices; iter != NULL; iter = iter->next)
+ if ((iter->dev_id == device_id) && strstr(iter->path, path))
+ return iter;
+ return NULL;
+}
+
static int devpath_to_ll(const char *dev_path, const char *entry, unsigned long long *val)
{
char path[strlen(dev_path) + strlen(entry) + 2];
@@ -724,8 +743,10 @@ char *vmd_domain_to_controller(struct sys_dev *hba, char *buf)
return NULL;
dir = opendir("/sys/bus/pci/drivers/vmd");
+ if (!dir)
+ return NULL;
- for (ent = dir ? readdir(dir) : NULL; ent; ent = readdir(dir)) {
+ for (ent = readdir(dir); ent; ent = readdir(dir)) {
sprintf(path, "/sys/bus/pci/drivers/vmd/%s/domain/device",
ent->d_name);
@@ -734,8 +755,11 @@ char *vmd_domain_to_controller(struct sys_dev *hba, char *buf)
if (strncmp(buf, hba->path, strlen(buf)) == 0) {
sprintf(path, "/sys/bus/pci/drivers/vmd/%s", ent->d_name);
+ closedir(dir);
return realpath(path, buf);
}
}
+
+ closedir(dir);
return NULL;
}