Skip to contentSkip to conversation

PCI: Introudce pci_dev_show_local_cpu() to simplify code

PATCH Applied Yijing Wang 2 participants 2 messages Sep 30, 2013 – Oct 4, 2013 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: Introudce pci_dev_show_local_cpu() to simplify code

Local_cpus_show() and local_cpulist_show() are almost the same, introudce a new helper function pci_dev_show_local_cpu() to simplify code.

---
 drivers/pci/pci-sysfs.c |   32 +++++++++++++++-----------------
 1 files changed, 15 insertions(+), 17 deletions(-)
drivers/pci/pci-sysfs.c +15 -17
index 7128cfd..3b41405 100644
@@ -74,9 +74,11 @@ static ssize_t broken_parity_status_store(struct device *dev,
 	return count;
 }
 
-static ssize_t local_cpus_show(struct device *dev,
-			struct device_attribute *attr, char *buf)
-{		
+static ssize_t pci_dev_show_local_cpu(struct device *dev,
+		int type,
+		struct device_attribute *attr,
+		char *buf)
+{
 	const struct cpumask *mask;
 	int len;
 
@@ -86,29 +88,25 @@ static ssize_t local_cpus_show(struct device *dev,
 #else
 	mask = cpumask_of_pcibus(to_pci_dev(dev)->bus);
 #endif
-	len = cpumask_scnprintf(buf, PAGE_SIZE-2, mask);
+	len = type ?
+		cpumask_scnprintf(buf, PAGE_SIZE-2, mask) :
+		cpulist_scnprintf(buf, PAGE_SIZE-2, mask);
+
 	buf[len++] = '\n';
 	buf[len] = '\0';
 	return len;
 }
 
+static ssize_t local_cpus_show(struct device *dev,
+			struct device_attribute *attr, char *buf)
+{
+	return pci_dev_show_local_cpu(dev, 1, attr, buf);
+}
 
 static ssize_t local_cpulist_show(struct device *dev,
 			struct device_attribute *attr, char *buf)
 {
-	const struct cpumask *mask;
-	int len;
-
-#ifdef CONFIG_NUMA
-	mask = (dev_to_node(dev) == -1) ? cpu_online_mask :
-					  cpumask_of_node(dev_to_node(dev));
-#else
-	mask = cpumask_of_pcibus(to_pci_dev(dev)->bus);
-#endif
-	len = cpulist_scnprintf(buf, PAGE_SIZE-2, mask);
-	buf[len++] = '\n';
-	buf[len] = '\0';
-	return len;
+	return pci_dev_show_local_cpu(dev, 0, attr, buf);
 }
 
 /*
Signature · 1 line
1.7.1
maintainer Applied
#1 lore raw
Quoted 5 lines · Yijing Wang

Local_cpus_show() and local_cpulist_show() are almost the same, introudce a new helper function pci_dev_show_local_cpu() to simplify code.

Applied to pci/misc, thanks!

Bjorn

Quoted 67 lines
---
 drivers/pci/pci-sysfs.c |   32 +++++++++++++++-----------------
 1 files changed, 15 insertions(+), 17 deletions(-)
drivers/pci/pci-sysfs.c +15 -18
index 7128cfd..3b41405 100644
@@ -74,9 +74,11 @@ static ssize_t broken_parity_status_store(struct device *dev,
        return count;
 }
 
-static ssize_t local_cpus_show(struct device *dev,
-                       struct device_attribute *attr, char *buf)
-{
+static ssize_t pci_dev_show_local_cpu(struct device *dev,
+               int type,
+               struct device_attribute *attr,
+               char *buf)
+{
        const struct cpumask *mask;
        int len;
 
@@ -86,29 +88,25 @@ static ssize_t local_cpus_show(struct device *dev,
 #else
        mask = cpumask_of_pcibus(to_pci_dev(dev)->bus);
 #endif
-       len = cpumask_scnprintf(buf, PAGE_SIZE-2, mask);
+       len = type ?
+               cpumask_scnprintf(buf, PAGE_SIZE-2, mask) :
+               cpulist_scnprintf(buf, PAGE_SIZE-2, mask);
+
        buf[len++] = '\n';
        buf[len] = '\0';
        return len;
 }
 
+static ssize_t local_cpus_show(struct device *dev,
+                       struct device_attribute *attr, char *buf)
+{
+       return pci_dev_show_local_cpu(dev, 1, attr, buf);
+}
 
 static ssize_t local_cpulist_show(struct device *dev,
                        struct device_attribute *attr, char *buf)
 {
-       const struct cpumask *mask;
-       int len;
-
-#ifdef CONFIG_NUMA
-       mask = (dev_to_node(dev) == -1) ? cpu_online_mask :
-                                         cpumask_of_node(dev_to_node(dev));
-#else
-       mask = cpumask_of_pcibus(to_pci_dev(dev)->bus);
-#endif
-       len = cpulist_scnprintf(buf, PAGE_SIZE-2, mask);
-       buf[len++] = '\n';
-       buf[len] = '\0';
-       return len;
+       return pci_dev_show_local_cpu(dev, 0, attr, buf);
 }
 
 /*
--

1.7.1