PCI: factor pci_bus_add_child() from pci_bus_add_devices()
authorYu Zhao <yu.zhao@intel.com>
Fri, 21 Nov 2008 18:42:35 +0000 (02:42 +0800)
committerJesse Barnes <jbarnes@virtuousgeek.org>
Wed, 7 Jan 2009 19:13:06 +0000 (11:13 -0800)
This patch splits a new function, pci_bus_add_child(), from
pci_bus_add_devices(). The new function can be used to register PCI
buses to the device core.

Signed-off-by: Yu Zhao <yu.zhao@intel.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
drivers/pci/bus.c
drivers/pci/pci.h

index 1b6de1b565aa826650779235eba593f74a5243b0..52b54f053be092e4c589b03d1dd03c6be9deacb6 100644 (file)
@@ -90,6 +90,37 @@ int pci_bus_add_device(struct pci_dev *dev)
        return 0;
 }
 
+/**
+ * pci_bus_add_child - add a child bus
+ * @bus: bus to add
+ *
+ * This adds sysfs entries for a single bus
+ */
+int pci_bus_add_child(struct pci_bus *bus)
+{
+       int retval;
+
+       if (bus->bridge)
+               bus->dev.parent = bus->bridge;
+
+       retval = device_register(&bus->dev);
+       if (retval)
+               return retval;
+
+       bus->is_added = 1;
+
+       retval = device_create_file(&bus->dev, &dev_attr_cpuaffinity);
+       if (retval)
+               return retval;
+
+       retval = device_create_file(&bus->dev, &dev_attr_cpulistaffinity);
+
+       /* Create legacy_io and legacy_mem files for this bus */
+       pci_create_legacy_files(bus);
+
+       return retval;
+}
+
 /**
  * pci_bus_add_devices - insert newly discovered PCI devices
  * @bus: bus to check for new devices
@@ -140,30 +171,9 @@ void pci_bus_add_devices(struct pci_bus *bus)
                 */
                if (child->is_added)
                        continue;
-               child->dev.parent = child->bridge;
-               retval = device_register(&child->dev);
+               retval = pci_bus_add_child(child);
                if (retval)
-                       dev_err(&dev->dev, "Error registering pci_bus,"
-                               " continuing...\n");
-               else {
-                       child->is_added = 1;
-                       retval = device_create_file(&child->dev,
-                                               &dev_attr_cpuaffinity);
-                       if (retval)
-                               dev_err(&dev->dev, "Error creating cpuaffinity"
-                                       " file, continuing...\n");
-
-                       retval = device_create_file(&child->dev,
-                                               &dev_attr_cpulistaffinity);
-                       if (retval)
-                               dev_err(&dev->dev,
-                                       "Error creating cpulistaffinity"
-                                       " file, continuing...\n");
-
-                       /* Create legacy_io and legacy_mem files for this bus */
-                       pci_create_legacy_files(child_bus);
-
-               }
+                       dev_err(&dev->dev, "Error adding bus, continuing\n");
        }
 }
 
index c4f4a1e6ea28c7816227982d72124d44dff401bb..d1e92d83aa066567279f1a8893cbd6d486914b06 100644 (file)
@@ -173,6 +173,7 @@ extern int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
                                struct resource *res, unsigned int reg);
 extern int pci_resource_bar(struct pci_dev *dev, int resno,
                            enum pci_bar_type *type);
+extern int pci_bus_add_child(struct pci_bus *bus);
 extern void pci_enable_ari(struct pci_dev *dev);
 /**
  * pci_ari_enabled - query ARI forwarding status