From: Sepherosa Ziehau Date: Thu, 3 Mar 2011 11:24:26 +0000 (+0800) Subject: mptable: Simplify bus id duplication check logic X-Git-Tag: v2.11.0~265^2~14 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/c715f06282f34c48bddd663e0342bd4cdf7c35a1 mptable: Simplify bus id duplication check logic --- diff --git a/sys/platform/pc32/i386/mp_machdep.c b/sys/platform/pc32/i386/mp_machdep.c index 483b930944..d12f99301d 100644 --- a/sys/platform/pc32/i386/mp_machdep.c +++ b/sys/platform/pc32/i386/mp_machdep.c @@ -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; } diff --git a/sys/platform/pc64/x86_64/mp_machdep.c b/sys/platform/pc64/x86_64/mp_machdep.c index 197a86036d..d3078f9127 100644 --- a/sys/platform/pc64/x86_64/mp_machdep.c +++ b/sys/platform/pc64/x86_64/mp_machdep.c @@ -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; }