qdev: Relax parsing of bus option

Treat multiple successive slashes as a one slash.  Ignore trailing
slashes.  This is how POSIX pathnames work.
This commit is contained in:
Markus Armbruster 2010-02-19 16:09:25 +01:00
parent fdcfa190ab
commit fc98eb430e

View file

@ -555,8 +555,8 @@ static BusState *qbus_find(const char *path)
pos = 0; pos = 0;
} else { } else {
if (sscanf(path, "%127[^/]%n", elem, &len) != 1) { if (sscanf(path, "%127[^/]%n", elem, &len) != 1) {
error_report("path parse error (\"%s\")", path); assert(!path[0]);
return NULL; elem[0] = len = 0;
} }
bus = qbus_find_recursive(main_system_bus, elem, NULL); bus = qbus_find_recursive(main_system_bus, elem, NULL);
if (!bus) { if (!bus) {
@ -567,15 +567,18 @@ static BusState *qbus_find(const char *path)
} }
for (;;) { for (;;) {
assert(path[pos] == '/' || !path[pos]);
while (path[pos] == '/') {
pos++;
}
if (path[pos] == '\0') { if (path[pos] == '\0') {
/* we are done */
return bus; return bus;
} }
/* find device */ /* find device */
if (sscanf(path+pos, "/%127[^/]%n", elem, &len) != 1) { if (sscanf(path+pos, "%127[^/]%n", elem, &len) != 1) {
error_report("path parse error (\"%s\" pos %d)", path, pos); assert(0);
return NULL; elem[0] = len = 0;
} }
pos += len; pos += len;
dev = qbus_find_dev(bus, elem); dev = qbus_find_dev(bus, elem);
@ -584,6 +587,11 @@ static BusState *qbus_find(const char *path)
qbus_list_dev(bus); qbus_list_dev(bus);
return NULL; return NULL;
} }
assert(path[pos] == '/' || !path[pos]);
while (path[pos] == '/') {
pos++;
}
if (path[pos] == '\0') { if (path[pos] == '\0') {
/* last specified element is a device. If it has exactly /* last specified element is a device. If it has exactly
* one child bus accept it nevertheless */ * one child bus accept it nevertheless */
@ -601,9 +609,9 @@ static BusState *qbus_find(const char *path)
} }
/* find bus */ /* find bus */
if (sscanf(path+pos, "/%127[^/]%n", elem, &len) != 1) { if (sscanf(path+pos, "%127[^/]%n", elem, &len) != 1) {
error_report("path parse error (\"%s\" pos %d)", path, pos); assert(0);
return NULL; elem[0] = len = 0;
} }
pos += len; pos += len;
bus = qbus_find_bus(dev, elem); bus = qbus_find_bus(dev, elem);