Commit 81ebb98b24eb5ea0f9d5a2717d71bcd01d652972

Authored by Gerd Hoffmann
Committed by Anthony Liguori
1 parent 15239b2e

qdev: factor out driver search to qdev_find_info()

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing 1 changed file with 15 additions and 7 deletions
hw/qdev.c
... ... @@ -46,6 +46,20 @@ void qdev_register(DeviceInfo *info)
46 46 device_info_list = info;
47 47 }
48 48  
  49 +static DeviceInfo *qdev_find_info(BusInfo *bus_info, const char *name)
  50 +{
  51 + DeviceInfo *info;
  52 +
  53 + for (info = device_info_list; info != NULL; info = info->next) {
  54 + if (bus_info && info->bus_info != bus_info)
  55 + continue;
  56 + if (strcmp(info->name, name) != 0)
  57 + continue;
  58 + return info;
  59 + }
  60 + return NULL;
  61 +}
  62 +
49 63 /* Create a new device. This only initializes the device state structure
50 64 and allows properties to be set. qdev_init should be called to
51 65 initialize the actual device emulation. */
... ... @@ -61,13 +75,7 @@ DeviceState *qdev_create(BusState *bus, const char *name)
61 75 bus = main_system_bus;
62 76 }
63 77  
64   - for (info = device_info_list; info != NULL; info = info->next) {
65   - if (info->bus_info != bus->info)
66   - continue;
67   - if (strcmp(info->name, name) != 0)
68   - continue;
69   - break;
70   - }
  78 + info = qdev_find_info(bus->info, name);
71 79 if (!info) {
72 80 hw_error("Unknown device '%s' for bus '%s'\n", name, bus->info->name);
73 81 }
... ...