Commit c489f5fb authored by Yijing Wang's avatar Yijing Wang Committed by Bjorn Helgaas

PCI: Add pci_dev_show_local_cpu() to simplify code

local_cpus_show() and local_cpulist_show() are almost the same.
This adds a new helper function, pci_dev_show_local_cpu(), to simplify
code.

The same strategy is already used by cpuaffinity_show() and
cpulistaffinity_show().
Signed-off-by: default avatarYijing Wang <wangyijing@huawei.com>
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
parent 135530d5
...@@ -74,9 +74,11 @@ static ssize_t broken_parity_status_store(struct device *dev, ...@@ -74,9 +74,11 @@ static ssize_t broken_parity_status_store(struct device *dev,
return count; return count;
} }
static ssize_t local_cpus_show(struct device *dev, static ssize_t pci_dev_show_local_cpu(struct device *dev,
struct device_attribute *attr, char *buf) int type,
{ struct device_attribute *attr,
char *buf)
{
const struct cpumask *mask; const struct cpumask *mask;
int len; int len;
...@@ -86,29 +88,25 @@ static ssize_t local_cpus_show(struct device *dev, ...@@ -86,29 +88,25 @@ static ssize_t local_cpus_show(struct device *dev,
#else #else
mask = cpumask_of_pcibus(to_pci_dev(dev)->bus); mask = cpumask_of_pcibus(to_pci_dev(dev)->bus);
#endif #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++] = '\n';
buf[len] = '\0'; buf[len] = '\0';
return len; 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, static ssize_t local_cpulist_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
const struct cpumask *mask; return pci_dev_show_local_cpu(dev, 0, attr, buf);
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;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment