提交 4dd7dfa1 编写于 作者: K Krzysztof Wilczyński 提交者: Bjorn Helgaas

PCI/sysfs: Define SMBIOS label attributes with DEVICE_ATTR*()

Use DEVICE_ATTR*() to simplify definition of the SMBIOS label attributes.
No functional change intended.

Note that dev_attr_smbios_label requires __ATTR() because the "label"
attribute can be exposed via either ACPI or SMBIOS, and we already have the
ACPI label_show() function in this file.

[bhelgaas: split to separate patch]
Link: https://lore.kernel.org/r/20210416205856.3234481-6-kw@linux.comSigned-off-by: NKrzysztof Wilczyński <kw@linux.com>
Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
上级 2ed64941
...@@ -92,8 +92,8 @@ static size_t find_smbios_instance_string(struct pci_dev *pdev, char *buf, ...@@ -92,8 +92,8 @@ static size_t find_smbios_instance_string(struct pci_dev *pdev, char *buf,
return 0; return 0;
} }
static umode_t smbios_instance_string_exist(struct kobject *kobj, static umode_t smbios_attr_is_visible(struct kobject *kobj, struct attribute *a,
struct attribute *attr, int n) int n)
{ {
struct device *dev; struct device *dev;
struct pci_dev *pdev; struct pci_dev *pdev;
...@@ -101,12 +101,14 @@ static umode_t smbios_instance_string_exist(struct kobject *kobj, ...@@ -101,12 +101,14 @@ static umode_t smbios_instance_string_exist(struct kobject *kobj,
dev = kobj_to_dev(kobj); dev = kobj_to_dev(kobj);
pdev = to_pci_dev(dev); pdev = to_pci_dev(dev);
return find_smbios_instance_string(pdev, NULL, SMBIOS_ATTR_NONE) ? if (!find_smbios_instance_string(pdev, NULL, SMBIOS_ATTR_NONE))
S_IRUGO : 0; return 0;
return a->mode;
} }
static ssize_t smbioslabel_show(struct device *dev, static ssize_t smbios_label_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct pci_dev *pdev; struct pci_dev *pdev;
pdev = to_pci_dev(dev); pdev = to_pci_dev(dev);
...@@ -114,9 +116,11 @@ static ssize_t smbioslabel_show(struct device *dev, ...@@ -114,9 +116,11 @@ static ssize_t smbioslabel_show(struct device *dev,
return find_smbios_instance_string(pdev, buf, return find_smbios_instance_string(pdev, buf,
SMBIOS_ATTR_LABEL_SHOW); SMBIOS_ATTR_LABEL_SHOW);
} }
static struct device_attribute dev_attr_smbios_label = __ATTR(label, 0444,
smbios_label_show, NULL);
static ssize_t smbiosinstance_show(struct device *dev, static ssize_t index_show(struct device *dev, struct device_attribute *attr,
struct device_attribute *attr, char *buf) char *buf)
{ {
struct pci_dev *pdev; struct pci_dev *pdev;
pdev = to_pci_dev(dev); pdev = to_pci_dev(dev);
...@@ -124,26 +128,17 @@ static ssize_t smbiosinstance_show(struct device *dev, ...@@ -124,26 +128,17 @@ static ssize_t smbiosinstance_show(struct device *dev,
return find_smbios_instance_string(pdev, buf, return find_smbios_instance_string(pdev, buf,
SMBIOS_ATTR_INSTANCE_SHOW); SMBIOS_ATTR_INSTANCE_SHOW);
} }
static DEVICE_ATTR_RO(index);
static struct device_attribute smbios_attr_label = { static struct attribute *smbios_attrs[] = {
.attr = {.name = "label", .mode = 0444}, &dev_attr_smbios_label.attr,
.show = smbioslabel_show, &dev_attr_index.attr,
};
static struct device_attribute smbios_attr_instance = {
.attr = {.name = "index", .mode = 0444},
.show = smbiosinstance_show,
};
static struct attribute *smbios_attributes[] = {
&smbios_attr_label.attr,
&smbios_attr_instance.attr,
NULL, NULL,
}; };
static const struct attribute_group smbios_attr_group = { static const struct attribute_group smbios_attr_group = {
.attrs = smbios_attributes, .attrs = smbios_attrs,
.is_visible = smbios_instance_string_exist, .is_visible = smbios_attr_is_visible,
}; };
static int pci_create_smbiosname_file(struct pci_dev *pdev) static int pci_create_smbiosname_file(struct pci_dev *pdev)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册