iommu/amd: Fix crash when accessing AMD-Vi sysfs entries
authorJoerg Roedel <jroedel@suse.de>
Tue, 28 Feb 2017 12:57:18 +0000 (13:57 +0100)
committerJoerg Roedel <jroedel@suse.de>
Tue, 28 Feb 2017 14:48:23 +0000 (15:48 +0100)
The link between the iommu sysfs-device and the struct
amd_iommu is no longer stored as driver-data. Update the
code to the new correct way of getting from device to
amd_iommu.

Reported-by: Dave Jones <davej@codemonkey.org.uk>
Fixes: 39ab9555c241 ('iommu: Add sysfs bindings for struct iommu_device')
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/amd_iommu_init.c
drivers/iommu/amd_iommu_types.h

index 04cdac7ab3e34bbcc3a4cba19fbb57d44129549b..6130278c5d71bd08e925cc35007610bc32736938 100644 (file)
@@ -1507,7 +1507,7 @@ static ssize_t amd_iommu_show_cap(struct device *dev,
                                  struct device_attribute *attr,
                                  char *buf)
 {
-       struct amd_iommu *iommu = dev_get_drvdata(dev);
+       struct amd_iommu *iommu = dev_to_amd_iommu(dev);
        return sprintf(buf, "%x\n", iommu->cap);
 }
 static DEVICE_ATTR(cap, S_IRUGO, amd_iommu_show_cap, NULL);
@@ -1516,7 +1516,7 @@ static ssize_t amd_iommu_show_features(struct device *dev,
                                       struct device_attribute *attr,
                                       char *buf)
 {
-       struct amd_iommu *iommu = dev_get_drvdata(dev);
+       struct amd_iommu *iommu = dev_to_amd_iommu(dev);
        return sprintf(buf, "%llx\n", iommu->features);
 }
 static DEVICE_ATTR(features, S_IRUGO, amd_iommu_show_features, NULL);
index af00f381a7b1a34e060039db569b274d04a532d1..003f3ceb2661c3cf1112cf39ecb7e1afb3488772 100644 (file)
@@ -569,6 +569,11 @@ struct amd_iommu {
        volatile u64 __aligned(8) cmd_sem;
 };
 
+static inline struct amd_iommu *dev_to_amd_iommu(struct device *dev)
+{
+       return container_of(dev, struct amd_iommu, iommu.dev);
+}
+
 #define ACPIHID_UID_LEN 256
 #define ACPIHID_HID_LEN 9