PCI: fix issue with busses registering multiple times in sysfs

PCI busses can be registered multiple times, so we need to detect if we
have registered our bus structure in sysfs already. If so, don't do it
again.

Thanks to Guennadi Liakhovetski <g.liakhovetski@gmx.de> for reporting
the problem, and to Linus for poking me to get me to believe that it was
a real problem.

Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

+6 -1
+5 -1
drivers/pci/bus.c
··· 143 /* register the bus with sysfs as the parent is now 144 * properly registered. */ 145 child_bus = dev->subordinate; 146 child_bus->dev.parent = child_bus->bridge; 147 retval = device_register(&child_bus->dev); 148 if (retval) 149 dev_err(&dev->dev, "Error registering pci_bus," 150 " continuing...\n"); 151 - else 152 retval = device_create_file(&child_bus->dev, 153 &dev_attr_cpuaffinity); 154 if (retval) 155 dev_err(&dev->dev, "Error creating cpuaffinity" 156 " file, continuing...\n");
··· 143 /* register the bus with sysfs as the parent is now 144 * properly registered. */ 145 child_bus = dev->subordinate; 146 + if (child_bus->is_added) 147 + continue; 148 child_bus->dev.parent = child_bus->bridge; 149 retval = device_register(&child_bus->dev); 150 if (retval) 151 dev_err(&dev->dev, "Error registering pci_bus," 152 " continuing...\n"); 153 + else { 154 + child_bus->is_added = 1; 155 retval = device_create_file(&child_bus->dev, 156 &dev_attr_cpuaffinity); 157 + } 158 if (retval) 159 dev_err(&dev->dev, "Error creating cpuaffinity" 160 " file, continuing...\n");
+1
include/linux/pci.h
··· 278 struct device dev; 279 struct bin_attribute *legacy_io; /* legacy I/O for this bus */ 280 struct bin_attribute *legacy_mem; /* legacy mem */ 281 }; 282 283 #define pci_bus_b(n) list_entry(n, struct pci_bus, node)
··· 278 struct device dev; 279 struct bin_attribute *legacy_io; /* legacy I/O for this bus */ 280 struct bin_attribute *legacy_mem; /* legacy mem */ 281 + unsigned int is_added:1; 282 }; 283 284 #define pci_bus_b(n) list_entry(n, struct pci_bus, node)