]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/pci/hotplug/rpaphp_core.c
PCI: rpaphp: match up alloc and free in same routine
[linux-2.6-omap-h63xx.git] / drivers / pci / hotplug / rpaphp_core.c
index 7288a3eccfb3e34b1bab1a8d2d9e6a762858d746..ca95e1515d6f2844185a32774b1d4da16d371639 100644 (file)
@@ -26,6 +26,7 @@
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/pci.h>
+#include <linux/pci_hotplug.h>
 #include <linux/slab.h>
 #include <linux/smp.h>
 #include <linux/smp_lock.h>
 #include "../pci.h"            /* for pci_add_new_bus */
                                /* and pci_do_scan_bus */
 #include "rpaphp.h"
-#include "pci_hotplug.h"
 
 int debug;
 static struct semaphore rpaphp_sem;
 LIST_HEAD(rpaphp_slot_head);
-int num_slots;
 
 #define DRIVER_VERSION "0.1"
 #define DRIVER_AUTHOR  "Linda Xie <lxie@us.ibm.com>"
@@ -299,34 +298,38 @@ int rpaphp_add_slot(struct device_node *dn)
        const int *indexes, *names, *types, *power_domains;
        char *name, *type;
 
+       if (!dn->name || strcmp(dn->name, "pci"))
+               return 0;
+
+       if (!is_php_dn(dn, &indexes, &names, &types, &power_domains))
+               return 0;
+
        dbg("Entry %s: dn->full_name=%s\n", __FUNCTION__, dn->full_name);
 
        /* register PCI devices */
-       if (dn->name != 0 && strcmp(dn->name, "pci") == 0) {
-               if (!is_php_dn(dn, &indexes, &names, &types, &power_domains))
-                       goto exit;
-
-               name = (char *) &names[1];
-               type = (char *) &types[1];
-               for (i = 0; i < indexes[0]; i++,
-                       name += (strlen(name) + 1), type += (strlen(type) + 1))                 {
-
-                       if (!(slot = alloc_slot_struct(dn, indexes[i + 1], name,
-                                      power_domains[i + 1]))) {
-                               retval = -ENOMEM;
-                               goto exit;
-                       }
-                       slot->type = simple_strtoul(type, NULL, 10);
+       name = (char *) &names[1];
+       type = (char *) &types[1];
+       for (i = 0; i < indexes[0]; i++) {
+
+               slot = alloc_slot_struct(dn, indexes[i + 1], name, power_domains[i + 1]);
+               if (!slot)
+                       return -ENOMEM;
+
+               slot->type = simple_strtoul(type, NULL, 10);
                                
-                       dbg("Found drc-index:0x%x drc-name:%s drc-type:%s\n",
-                                       indexes[i + 1], name, type);
+               dbg("Found drc-index:0x%x drc-name:%s drc-type:%s\n",
+                               indexes[i + 1], name, type);
 
-                       retval = rpaphp_register_pci_slot(slot);
-               }
+               retval = rpaphp_register_pci_slot(slot);
+               if (retval)
+                       dealloc_slot_struct(slot);
+
+               name += strlen(name) + 1;
+               type += strlen(type) + 1;
        }
-exit:
-       dbg("%s - Exit: num_slots=%d rc[%d]\n",
-           __FUNCTION__, num_slots, retval);
+       dbg("%s - Exit: rc[%d]\n", __FUNCTION__, retval);
+
+       /* XXX FIXME: reports a failure only if last entry in loop failed */
        return retval;
 }
 
@@ -356,7 +359,7 @@ static int __init rpaphp_init(void)
        info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
        init_MUTEX(&rpaphp_sem);
 
-       while ((dn = of_find_node_by_type(dn, "pci")))
+       while ((dn = of_find_node_by_name(dn, "pci")))
                rpaphp_add_slot(dn);
 
        return 0;