提交 3bc770b0 编写于 作者: Y YueHaibing 提交者: Joerg Roedel

iommu/vt-d: Use DEVICE_ATTR_RO macro

Use DEVICE_ATTR_RO() helper instead of plain DEVICE_ATTR(),
which makes the code a bit shorter and easier to read.
Signed-off-by: NYueHaibing <yuehaibing@huawei.com>
Signed-off-by: NLu Baolu <baolu.lu@linux.intel.com>
Link: https://lore.kernel.org/r/20210528130229.22108-1-yuehaibing@huawei.com
Link: https://lore.kernel.org/r/20210610020115.1637656-19-baolu.lu@linux.intel.comSigned-off-by: NJoerg Roedel <jroedel@suse.de>
上级 606636dc
...@@ -4139,62 +4139,56 @@ static inline struct intel_iommu *dev_to_intel_iommu(struct device *dev) ...@@ -4139,62 +4139,56 @@ static inline struct intel_iommu *dev_to_intel_iommu(struct device *dev)
return container_of(iommu_dev, struct intel_iommu, iommu); return container_of(iommu_dev, struct intel_iommu, iommu);
} }
static ssize_t intel_iommu_show_version(struct device *dev, static ssize_t version_show(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr, char *buf)
char *buf)
{ {
struct intel_iommu *iommu = dev_to_intel_iommu(dev); struct intel_iommu *iommu = dev_to_intel_iommu(dev);
u32 ver = readl(iommu->reg + DMAR_VER_REG); u32 ver = readl(iommu->reg + DMAR_VER_REG);
return sprintf(buf, "%d:%d\n", return sprintf(buf, "%d:%d\n",
DMAR_VER_MAJOR(ver), DMAR_VER_MINOR(ver)); DMAR_VER_MAJOR(ver), DMAR_VER_MINOR(ver));
} }
static DEVICE_ATTR(version, S_IRUGO, intel_iommu_show_version, NULL); static DEVICE_ATTR_RO(version);
static ssize_t intel_iommu_show_address(struct device *dev, static ssize_t address_show(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr, char *buf)
char *buf)
{ {
struct intel_iommu *iommu = dev_to_intel_iommu(dev); struct intel_iommu *iommu = dev_to_intel_iommu(dev);
return sprintf(buf, "%llx\n", iommu->reg_phys); return sprintf(buf, "%llx\n", iommu->reg_phys);
} }
static DEVICE_ATTR(address, S_IRUGO, intel_iommu_show_address, NULL); static DEVICE_ATTR_RO(address);
static ssize_t intel_iommu_show_cap(struct device *dev, static ssize_t cap_show(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr, char *buf)
char *buf)
{ {
struct intel_iommu *iommu = dev_to_intel_iommu(dev); struct intel_iommu *iommu = dev_to_intel_iommu(dev);
return sprintf(buf, "%llx\n", iommu->cap); return sprintf(buf, "%llx\n", iommu->cap);
} }
static DEVICE_ATTR(cap, S_IRUGO, intel_iommu_show_cap, NULL); static DEVICE_ATTR_RO(cap);
static ssize_t intel_iommu_show_ecap(struct device *dev, static ssize_t ecap_show(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr, char *buf)
char *buf)
{ {
struct intel_iommu *iommu = dev_to_intel_iommu(dev); struct intel_iommu *iommu = dev_to_intel_iommu(dev);
return sprintf(buf, "%llx\n", iommu->ecap); return sprintf(buf, "%llx\n", iommu->ecap);
} }
static DEVICE_ATTR(ecap, S_IRUGO, intel_iommu_show_ecap, NULL); static DEVICE_ATTR_RO(ecap);
static ssize_t intel_iommu_show_ndoms(struct device *dev, static ssize_t domains_supported_show(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr, char *buf)
char *buf)
{ {
struct intel_iommu *iommu = dev_to_intel_iommu(dev); struct intel_iommu *iommu = dev_to_intel_iommu(dev);
return sprintf(buf, "%ld\n", cap_ndoms(iommu->cap)); return sprintf(buf, "%ld\n", cap_ndoms(iommu->cap));
} }
static DEVICE_ATTR(domains_supported, S_IRUGO, intel_iommu_show_ndoms, NULL); static DEVICE_ATTR_RO(domains_supported);
static ssize_t intel_iommu_show_ndoms_used(struct device *dev, static ssize_t domains_used_show(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr, char *buf)
char *buf)
{ {
struct intel_iommu *iommu = dev_to_intel_iommu(dev); struct intel_iommu *iommu = dev_to_intel_iommu(dev);
return sprintf(buf, "%d\n", bitmap_weight(iommu->domain_ids, return sprintf(buf, "%d\n", bitmap_weight(iommu->domain_ids,
cap_ndoms(iommu->cap))); cap_ndoms(iommu->cap)));
} }
static DEVICE_ATTR(domains_used, S_IRUGO, intel_iommu_show_ndoms_used, NULL); static DEVICE_ATTR_RO(domains_used);
static struct attribute *intel_iommu_attrs[] = { static struct attribute *intel_iommu_attrs[] = {
&dev_attr_version.attr, &dev_attr_version.attr,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册