Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

PCI/sysfs: move bus cpuaffinity to class dev_attrs

Requested by Greg KH to fix a race condition in the creating of PCI bus
cpuaffinity files.

Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>

authored by

Yinghai Lu and committed by
Jesse Barnes
dc2c2c9d b9d320fc

+36 -52
-6
drivers/pci/bus.c
··· 163 163 164 164 bus->is_added = 1; 165 165 166 - retval = device_create_file(&bus->dev, &dev_attr_cpuaffinity); 167 - if (retval) 168 - return retval; 169 - 170 - retval = device_create_file(&bus->dev, &dev_attr_cpulistaffinity); 171 - 172 166 /* Create legacy_io and legacy_mem files for this bus */ 173 167 pci_create_legacy_files(bus); 174 168
+36
drivers/pci/pci-sysfs.c
··· 108 108 return len; 109 109 } 110 110 111 + /* 112 + * PCI Bus Class Devices 113 + */ 114 + static ssize_t pci_bus_show_cpuaffinity(struct device *dev, 115 + int type, 116 + struct device_attribute *attr, 117 + char *buf) 118 + { 119 + int ret; 120 + const struct cpumask *cpumask; 121 + 122 + cpumask = cpumask_of_pcibus(to_pci_bus(dev)); 123 + ret = type ? 124 + cpulist_scnprintf(buf, PAGE_SIZE-2, cpumask) : 125 + cpumask_scnprintf(buf, PAGE_SIZE-2, cpumask); 126 + buf[ret++] = '\n'; 127 + buf[ret] = '\0'; 128 + return ret; 129 + } 130 + 131 + static inline ssize_t pci_bus_show_cpumaskaffinity(struct device *dev, 132 + struct device_attribute *attr, 133 + char *buf) 134 + { 135 + return pci_bus_show_cpuaffinity(dev, 0, attr, buf); 136 + } 137 + 138 + static inline ssize_t pci_bus_show_cpulistaffinity(struct device *dev, 139 + struct device_attribute *attr, 140 + char *buf) 141 + { 142 + return pci_bus_show_cpuaffinity(dev, 1, attr, buf); 143 + } 144 + 111 145 /* show resources */ 112 146 static ssize_t 113 147 resource_show(struct device * dev, struct device_attribute *attr, char * buf) ··· 404 370 #ifdef CONFIG_HOTPLUG 405 371 __ATTR(rescan, (S_IWUSR|S_IWGRP), NULL, dev_bus_rescan_store), 406 372 #endif 373 + __ATTR(cpuaffinity, S_IRUGO, pci_bus_show_cpumaskaffinity, NULL), 374 + __ATTR(cpulistaffinity, S_IRUGO, pci_bus_show_cpulistaffinity, NULL), 407 375 __ATTR_NULL, 408 376 }; 409 377
-2
drivers/pci/pci.h
··· 157 157 } 158 158 extern struct device_attribute pci_dev_attrs[]; 159 159 extern struct device_attribute pcibus_dev_attrs[]; 160 - extern struct device_attribute dev_attr_cpuaffinity; 161 - extern struct device_attribute dev_attr_cpulistaffinity; 162 160 #ifdef CONFIG_HOTPLUG 163 161 extern struct bus_attribute pci_bus_attrs[]; 164 162 #else
-42
drivers/pci/probe.c
··· 43 43 EXPORT_SYMBOL(no_pci_devices); 44 44 45 45 /* 46 - * PCI Bus Class Devices 47 - */ 48 - static ssize_t pci_bus_show_cpuaffinity(struct device *dev, 49 - int type, 50 - struct device_attribute *attr, 51 - char *buf) 52 - { 53 - int ret; 54 - const struct cpumask *cpumask; 55 - 56 - cpumask = cpumask_of_pcibus(to_pci_bus(dev)); 57 - ret = type? 58 - cpulist_scnprintf(buf, PAGE_SIZE-2, cpumask) : 59 - cpumask_scnprintf(buf, PAGE_SIZE-2, cpumask); 60 - buf[ret++] = '\n'; 61 - buf[ret] = '\0'; 62 - return ret; 63 - } 64 - 65 - static ssize_t inline pci_bus_show_cpumaskaffinity(struct device *dev, 66 - struct device_attribute *attr, 67 - char *buf) 68 - { 69 - return pci_bus_show_cpuaffinity(dev, 0, attr, buf); 70 - } 71 - 72 - static ssize_t inline pci_bus_show_cpulistaffinity(struct device *dev, 73 - struct device_attribute *attr, 74 - char *buf) 75 - { 76 - return pci_bus_show_cpuaffinity(dev, 1, attr, buf); 77 - } 78 - 79 - DEVICE_ATTR(cpuaffinity, S_IRUGO, pci_bus_show_cpumaskaffinity, NULL); 80 - DEVICE_ATTR(cpulistaffinity, S_IRUGO, pci_bus_show_cpulistaffinity, NULL); 81 - 82 - /* 83 46 * PCI Bus Class 84 47 */ 85 48 static void release_pcibus_dev(struct device *dev) ··· 1419 1456 error = device_register(&b->dev); 1420 1457 if (error) 1421 1458 goto class_dev_reg_err; 1422 - error = device_create_file(&b->dev, &dev_attr_cpuaffinity); 1423 - if (error) 1424 - goto dev_create_file_err; 1425 1459 1426 1460 /* Create legacy_io and legacy_mem files for this bus */ 1427 1461 pci_create_legacy_files(b); ··· 1429 1469 1430 1470 return b; 1431 1471 1432 - dev_create_file_err: 1433 - device_unregister(&b->dev); 1434 1472 class_dev_reg_err: 1435 1473 device_unregister(dev); 1436 1474 dev_reg_err:
-2
drivers/pci/remove.c
··· 73 73 return; 74 74 75 75 pci_remove_legacy_files(pci_bus); 76 - device_remove_file(&pci_bus->dev, &dev_attr_cpuaffinity); 77 - device_remove_file(&pci_bus->dev, &dev_attr_cpulistaffinity); 78 76 device_unregister(&pci_bus->dev); 79 77 } 80 78 EXPORT_SYMBOL(pci_remove_bus);