diff mbox series

[18/20] PCI: Rearrange attributes from the pcie_dev_attr_group

Message ID 20210416205856.3234481-19-kw@linux.com (mailing list archive)
State Superseded, archived
Delegated to: Bjorn Helgaas
Headers show
Series PCI: Convert dynamic sysfs objects into static | expand

Commit Message

Krzysztof Wilczy��ski April 16, 2021, 8:58 p.m. UTC
When new sysfs objects were added to the PCI device over time, the code
that implemented new attributes has been added in many different places
in the pci-sysfs.c file.  This makes it hard to read and also hard to
find relevant code.

Thus, collect all the attributes that are part of the "pcie_dev_attr_group"
attribute group together and move to the top of the file sorting
everything attribute in the order of use.

No functional change intended.

Suggested-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Krzysztof Wilczyński <kw@linux.com>
---
 drivers/pci/pci-sysfs.c | 106 ++++++++++++++++++++--------------------
 1 file changed, 53 insertions(+), 53 deletions(-)
diff mbox series

Patch

diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 1899c24081f7..44ce65bcacba 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -940,28 +940,29 @@  static const struct attribute_group pci_bridge_attr_group = {
 	.is_visible = pci_bridge_attr_is_visible,
 };
 
-/*
- * PCI Bus Class Devices
- */
-static ssize_t cpuaffinity_show(struct device *dev,
-				struct device_attribute *attr, char *buf)
+static ssize_t current_link_speed_show(struct device *dev,
+				       struct device_attribute *attr, char *buf)
 {
-	struct pci_bus *bus = to_pci_bus(dev);
-	const struct cpumask *cpumask = cpumask_of_pcibus(bus);
+	struct pci_dev *pdev = to_pci_dev(dev);
+	enum pci_bus_speed speed;
 
-	return cpumap_print_to_pagebuf(false, buf, cpumask);
+	pcie_bandwidth_available(pdev, NULL, &speed, NULL);
+
+	return sysfs_emit(buf, "%s\n", pci_speed_string(speed));
 }
-static DEVICE_ATTR_RO(cpuaffinity);
+static DEVICE_ATTR_RO(current_link_speed);
 
-static ssize_t cpulistaffinity_show(struct device *dev,
-				    struct device_attribute *attr, char *buf)
+static ssize_t current_link_width_show(struct device *dev,
+				       struct device_attribute *attr, char *buf)
 {
-	struct pci_bus *bus = to_pci_bus(dev);
-	const struct cpumask *cpumask = cpumask_of_pcibus(bus);
+	struct pci_dev *pdev = to_pci_dev(dev);
+	enum pcie_link_width width;
 
-	return cpumap_print_to_pagebuf(true, buf, cpumask);
+	pcie_bandwidth_available(pdev, NULL, NULL, &width);
+
+	return sysfs_emit(buf, "%u\n", width);
 }
-static DEVICE_ATTR_RO(cpulistaffinity);
+static DEVICE_ATTR_RO(current_link_width);
 
 static ssize_t max_link_speed_show(struct device *dev,
 				   struct device_attribute *attr, char *buf)
@@ -982,29 +983,52 @@  static ssize_t max_link_width_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(max_link_width);
 
-static ssize_t current_link_speed_show(struct device *dev,
-				       struct device_attribute *attr, char *buf)
+static struct attribute *pcie_dev_attrs[] = {
+	&dev_attr_current_link_speed.attr,
+	&dev_attr_current_link_width.attr,
+	&dev_attr_max_link_speed.attr,
+	&dev_attr_max_link_width.attr,
+	NULL,
+};
+
+static umode_t pcie_dev_attr_is_visible(struct kobject *kobj,
+					struct attribute *a, int n)
 {
-	struct pci_dev *pdev = to_pci_dev(dev);
-	enum pci_bus_speed speed;
+	struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));
 
-	pcie_bandwidth_available(pdev, NULL, &speed, NULL);
+	if (!pci_is_pcie(pdev))
+		return 0;
 
-	return sysfs_emit(buf, "%s\n", pci_speed_string(speed));
+	return a->mode;
 }
-static DEVICE_ATTR_RO(current_link_speed);
 
-static ssize_t current_link_width_show(struct device *dev,
-				       struct device_attribute *attr, char *buf)
+static const struct attribute_group pcie_dev_attr_group = {
+	.attrs = pcie_dev_attrs,
+	.is_visible = pcie_dev_attr_is_visible,
+};
+
+/*
+ * PCI Bus Class Devices
+ */
+static ssize_t cpuaffinity_show(struct device *dev,
+				struct device_attribute *attr, char *buf)
 {
-	struct pci_dev *pdev = to_pci_dev(dev);
-	enum pcie_link_width width;
+	struct pci_bus *bus = to_pci_bus(dev);
+	const struct cpumask *cpumask = cpumask_of_pcibus(bus);
 
-	pcie_bandwidth_available(pdev, NULL, NULL, &width);
+	return cpumap_print_to_pagebuf(false, buf, cpumask);
+}
+static DEVICE_ATTR_RO(cpuaffinity);
 
-	return sysfs_emit(buf, "%u\n", width);
+static ssize_t cpulistaffinity_show(struct device *dev,
+				    struct device_attribute *attr, char *buf)
+{
+	struct pci_bus *bus = to_pci_bus(dev);
+	const struct cpumask *cpumask = cpumask_of_pcibus(bus);
+
+	return cpumap_print_to_pagebuf(true, buf, cpumask);
 }
-static DEVICE_ATTR_RO(current_link_width);
+static DEVICE_ATTR_RO(cpulistaffinity);
 
 static ssize_t rescan_store(struct bus_type *bus, const char *buf, size_t count)
 {
@@ -1063,14 +1087,6 @@  static ssize_t bus_rescan_store(struct device *dev,
 static struct device_attribute dev_attr_bus_rescan = __ATTR(rescan, 0200, NULL,
 							    bus_rescan_store);
 
-static struct attribute *pcie_dev_attrs[] = {
-	&dev_attr_current_link_speed.attr,
-	&dev_attr_current_link_width.attr,
-	&dev_attr_max_link_width.attr,
-	&dev_attr_max_link_speed.attr,
-	NULL,
-};
-
 static struct attribute *pcibus_attrs[] = {
 	&dev_attr_bus_rescan.attr,
 	&dev_attr_cpuaffinity.attr,
@@ -1555,17 +1571,6 @@  static int __init pci_sysfs_init(void)
 }
 late_initcall(pci_sysfs_init);
 
-static umode_t pcie_dev_attr_is_visible(struct kobject *kobj,
-					struct attribute *a, int n)
-{
-	struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));
-
-	if (!pci_is_pcie(pdev))
-		return 0;
-
-	return a->mode;
-}
-
 const struct attribute_group *pci_dev_groups[] = {
 	&pci_dev_group,
 	&pci_dev_config_attr_group,
@@ -1581,11 +1586,6 @@  const struct attribute_group *pci_dev_groups[] = {
 	NULL,
 };
 
-static const struct attribute_group pcie_dev_attr_group = {
-	.attrs = pcie_dev_attrs,
-	.is_visible = pcie_dev_attr_is_visible,
-};
-
 static const struct attribute_group *pci_dev_attr_groups[] = {
 	&pci_dev_attr_group,
 	&pci_dev_hp_attr_group,