mptable: Simplify bus id duplication check logic
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Thu, 3 Mar 2011 11:24:26 +0000 (19:24 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Thu, 3 Mar 2011 11:30:20 +0000 (19:30 +0800)
sys/platform/pc32/i386/mp_machdep.c
sys/platform/pc64/x86_64/mp_machdep.c

index 483b930..d12f993 100644 (file)
@@ -2894,7 +2894,15 @@ mptable_bus_info_callback(void *xarg, const void *pos, int type)
 
        if (type != 1)
                return 0;
+
        ent = pos;
+       TAILQ_FOREACH(bus, &bus_info->mbi_list, mb_link) {
+               if (bus->mb_id == ent->bus_id) {
+                       kprintf("mptable_bus_info_alloc: duplicated bus id "
+                               "(%d)\n", bus->mb_id);
+                       return EINVAL;
+               }
+       }
 
        bus = NULL;
        if (strncmp(ent->bus_type, "PCI", 3) == 0) {
@@ -2906,23 +2914,8 @@ mptable_bus_info_callback(void *xarg, const void *pos, int type)
        }
 
        if (bus != NULL) {
-               const struct mptable_bus *bus1;
-
-               TAILQ_FOREACH(bus1, &bus_info->mbi_list, mb_link) {
-                       if (bus1->mb_id == ent->bus_id) {
-                               kprintf("mptable_bus_info_alloc: "
-                                       "duplicated bus id (%d)\n", bus1->mb_id);
-                               break;
-                       }
-               }
-
-               if (bus1 == NULL) {
-                       bus->mb_id = ent->bus_id;
-                       TAILQ_INSERT_TAIL(&bus_info->mbi_list, bus, mb_link);
-               } else {
-                       kfree(bus, M_TEMP);
-                       return EINVAL;
-               }
+               bus->mb_id = ent->bus_id;
+               TAILQ_INSERT_TAIL(&bus_info->mbi_list, bus, mb_link);
        }
        return 0;
 }
index 197a860..d3078f9 100644 (file)
@@ -2888,7 +2888,15 @@ mptable_bus_info_callback(void *xarg, const void *pos, int type)
 
        if (type != 1)
                return 0;
+
        ent = pos;
+       TAILQ_FOREACH(bus, &bus_info->mbi_list, mb_link) {
+               if (bus->mb_id == ent->bus_id) {
+                       kprintf("mptable_bus_info_alloc: duplicated bus id "
+                               "(%d)\n", bus->mb_id);
+                       return EINVAL;
+               }
+       }
 
        bus = NULL;
        if (strncmp(ent->bus_type, "PCI", 3) == 0) {
@@ -2900,23 +2908,8 @@ mptable_bus_info_callback(void *xarg, const void *pos, int type)
        }
 
        if (bus != NULL) {
-               const struct mptable_bus *bus1;
-
-               TAILQ_FOREACH(bus1, &bus_info->mbi_list, mb_link) {
-                       if (bus1->mb_id == ent->bus_id) {
-                               kprintf("mptable_bus_info_alloc: "
-                                       "duplicated bus id (%d)\n", bus1->mb_id);
-                               break;
-                       }
-               }
-
-               if (bus1 == NULL) {
-                       bus->mb_id = ent->bus_id;
-                       TAILQ_INSERT_TAIL(&bus_info->mbi_list, bus, mb_link);
-               } else {
-                       kfree(bus, M_TEMP);
-                       return EINVAL;
-               }
+               bus->mb_id = ent->bus_id;
+               TAILQ_INSERT_TAIL(&bus_info->mbi_list, bus, mb_link);
        }
        return 0;
 }