[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 08/15] qbus_find_recursive(): reorganize
From: |
Laszlo Ersek |
Subject: |
[Qemu-devel] [PATCH v2 08/15] qbus_find_recursive(): reorganize |
Date: |
Tue, 5 Feb 2013 21:39:21 +0100 |
Eliminate the "match" variable, and move the remaining locals to the
narrowest possible scope.
Signed-off-by: Laszlo Ersek <address@hidden>
---
hw/qdev-monitor.c | 35 ++++++++++++++++-------------------
1 files changed, 16 insertions(+), 19 deletions(-)
diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
index da32763..64359ee 100644
--- a/hw/qdev-monitor.c
+++ b/hw/qdev-monitor.c
@@ -289,38 +289,35 @@ static DeviceState *qbus_find_dev(BusState *bus, char
*elem)
}
static BusState *qbus_find_recursive(BusState *bus, const char *name,
- const char *bus_typename)
+ const char *type)
{
- BusClass *bus_class = BUS_GET_CLASS(bus);
BusChild *kid;
- BusState *child, *ret;
- int match = 1;
- if (name && (strcmp(bus->name, name) != 0)) {
- match = 0;
- }
- if (bus_typename && !object_dynamic_cast(OBJECT(bus), bus_typename)) {
- match = 0;
- }
- if ((bus_class->max_dev != 0) && (bus_class->max_dev <= bus->max_index)) {
+ if ((name == NULL || strcmp(bus->name, name) == 0) &&
+ (type == NULL || object_dynamic_cast(OBJECT(bus), type) != NULL)) {
+ BusClass *bus_class = BUS_GET_CLASS(bus);
+
+ /* name (if any) and type (if any) match; check free slots */
+ if (bus_class->max_dev == 0 || bus->max_index < bus_class->max_dev) {
+ return bus;
+ }
+
+ /* bus is full -- fatal error for search by name */
if (name != NULL) {
- /* bus was explicitly specified: return an error. */
qerror_report(ERROR_CLASS_GENERIC_ERROR, "Bus '%s' is full",
bus->name);
return NULL;
- } else {
- /* bus was not specified: try to find another one. */
- match = 0;
}
}
- if (match) {
- return bus;
- }
QTAILQ_FOREACH(kid, &bus->children, sibling) {
DeviceState *dev = kid->child;
+ BusState *child;
+
QLIST_FOREACH(child, &dev->child_bus, sibling) {
- ret = qbus_find_recursive(child, name, bus_typename);
+ BusState *ret;
+
+ ret = qbus_find_recursive(child, name, type);
if (ret) {
return ret;
}
--
1.7.1
- Re: [Qemu-devel] [PATCH v2 05/15] qdev_prop_parse(): change return type to void, (continued)
- [Qemu-devel] [PATCH v2 06/15] set_property(): extend signature with Error, Laszlo Ersek, 2013/02/05
- [Qemu-devel] [PATCH v2 07/15] set_property(): push error handling to callers, Laszlo Ersek, 2013/02/05
- [Qemu-devel] [PATCH v2 12/15] qbus_find(): propagate error handling / consumption to callers, Laszlo Ersek, 2013/02/05
- [Qemu-devel] [PATCH v2 11/15] qbus_find(): extend signature with Error, Laszlo Ersek, 2013/02/05
- [Qemu-devel] [PATCH v2 15/15] qdev_device_add(): beautify "driver not found" error message, Laszlo Ersek, 2013/02/05
- [Qemu-devel] [PATCH v2 09/15] qbus_find_recursive(): extend signature with Error, Laszlo Ersek, 2013/02/05
- [Qemu-devel] [PATCH v2 08/15] qbus_find_recursive(): reorganize,
Laszlo Ersek <=
- [Qemu-devel] [PATCH v2 13/15] qdev_device_add(): extend signature with Error, Laszlo Ersek, 2013/02/05
- [Qemu-devel] [PATCH v2 14/15] qdev_device_add(): push error handling/consumption to callers, Laszlo Ersek, 2013/02/05
- [Qemu-devel] [PATCH v2 10/15] qbus_find_recursive(): push Error and make it terminate a recursive search, Laszlo Ersek, 2013/02/05
- Re: [Qemu-devel] [PATCH v2 00/15] propagate Errors to do_device_add(), Luiz Capitulino, 2013/02/08