PCI/sysfs: Define ACPI label attributes with DEVICE_ATTR*()
authorKrzysztof Wilczyński <kw@linux.com>
Tue, 27 Apr 2021 18:48:51 +0000 (13:48 -0500)
committerBjorn Helgaas <bhelgaas@google.com>
Thu, 29 Apr 2021 15:07:31 +0000 (10:07 -0500)
Use DEVICE_ATTR*() to simplify definitions of the ACPI label attributes.
No functional change intended.

[bhelgaas: split to separate patch]
Link: https://lore.kernel.org/r/20210416205856.3234481-6-kw@linux.com
Signed-off-by: Krzysztof Wilczyński <kw@linux.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/pci/pci-label.c

index 5fd5824db82f3b3edd20edfa32798a1fcbe7fb44..4fef6fc0740fdb6b670cc28dfb2da44acbe2886f 100644 (file)
@@ -225,50 +225,42 @@ static int dsm_get_label(struct device *dev, char *buf,
        return len;
 }
 
-static umode_t acpi_index_string_exist(struct kobject *kobj,
-                                      struct attribute *attr, int n)
+static umode_t acpi_attr_is_visible(struct kobject *kobj, struct attribute *a,
+                                   int n)
 {
        struct device *dev;
 
        dev = kobj_to_dev(kobj);
 
-       if (device_has_acpi_name(dev))
-               return S_IRUGO;
+       if (!device_has_acpi_name(dev))
+               return 0;
 
-       return 0;
+       return a->mode;
 }
 
-static ssize_t acpilabel_show(struct device *dev,
-                             struct device_attribute *attr, char *buf)
+static ssize_t label_show(struct device *dev, struct device_attribute *attr,
+                         char *buf)
 {
        return dsm_get_label(dev, buf, ACPI_ATTR_LABEL_SHOW);
 }
+static DEVICE_ATTR_RO(label);
 
-static ssize_t acpiindex_show(struct device *dev,
+static ssize_t acpi_index_show(struct device *dev,
                              struct device_attribute *attr, char *buf)
 {
        return dsm_get_label(dev, buf, ACPI_ATTR_INDEX_SHOW);
 }
+static DEVICE_ATTR_RO(acpi_index);
 
-static struct device_attribute acpi_attr_label = {
-       .attr = {.name = "label", .mode = 0444},
-       .show = acpilabel_show,
-};
-
-static struct device_attribute acpi_attr_index = {
-       .attr = {.name = "acpi_index", .mode = 0444},
-       .show = acpiindex_show,
-};
-
-static struct attribute *acpi_attributes[] = {
-       &acpi_attr_label.attr,
-       &acpi_attr_index.attr,
+static struct attribute *acpi_attrs[] = {
+       &dev_attr_label.attr,
+       &dev_attr_acpi_index.attr,
        NULL,
 };
 
 static const struct attribute_group acpi_attr_group = {
-       .attrs = acpi_attributes,
-       .is_visible = acpi_index_string_exist,
+       .attrs = acpi_attrs,
+       .is_visible = acpi_attr_is_visible,
 };
 
 static int pci_create_acpi_index_label_files(struct pci_dev *pdev)