From 81ebb98b24eb5ea0f9d5a2717d71bcd01d652972 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Wed, 15 Jul 2009 13:43:32 +0200 Subject: [PATCH] qdev: factor out driver search to qdev_find_info() Signed-off-by: Gerd Hoffmann Signed-off-by: Anthony Liguori --- hw/qdev.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index 64461e7eb2..a53125dd88 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -46,6 +46,20 @@ void qdev_register(DeviceInfo *info) device_info_list = info; } +static DeviceInfo *qdev_find_info(BusInfo *bus_info, const char *name) +{ + DeviceInfo *info; + + for (info = device_info_list; info != NULL; info = info->next) { + if (bus_info && info->bus_info != bus_info) + continue; + if (strcmp(info->name, name) != 0) + continue; + return info; + } + return NULL; +} + /* Create a new device. This only initializes the device state structure and allows properties to be set. qdev_init should be called to initialize the actual device emulation. */ @@ -61,13 +75,7 @@ DeviceState *qdev_create(BusState *bus, const char *name) bus = main_system_bus; } - for (info = device_info_list; info != NULL; info = info->next) { - if (info->bus_info != bus->info) - continue; - if (strcmp(info->name, name) != 0) - continue; - break; - } + info = qdev_find_info(bus->info, name); if (!info) { hw_error("Unknown device '%s' for bus '%s'\n", name, bus->info->name); } -- 2.11.4.GIT