On Wed, Nov 10, 2010 at 5:14 PM, Gleb Natapov <[email protected]> wrote:
>
> Signed-off-by: Gleb Natapov <[email protected]>
> ---
> hw/usb-bus.c | 35 +++++++++++++++++++++++++++++++++++
> 1 files changed, 35 insertions(+), 0 deletions(-)
>
> diff --git a/hw/usb-bus.c b/hw/usb-bus.c
> index 256b881..6292282 100644
> --- a/hw/usb-bus.c
> +++ b/hw/usb-bus.c
> @@ -5,11 +5,13 @@
> #include "monitor.h"
>
> static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent);
> +static char *usbbus_get_fw_dev_path(DeviceState *dev);
>
> static struct BusInfo usb_bus_info = {
> .name = "USB",
> .size = sizeof(USBBus),
> .print_dev = usb_bus_dev_print,
> + .get_fw_dev_path = usbbus_get_fw_dev_path,
> };
> static int next_usb_bus = 0;
> static QTAILQ_HEAD(, USBBus) busses = QTAILQ_HEAD_INITIALIZER(busses);
> @@ -307,3 +309,36 @@ USBDevice *usbdevice_create(const char *cmdline)
> }
> return usb->usbdevice_init(params);
> }
> +
> +static int usbbus_get_fw_dev_path_helper(USBDevice *d, USBBus *bus, char *p,
> + int len)
> +{
> + int l = 0;
> + USBPort *port;
> +
> + QTAILQ_FOREACH(port, &bus->used, next) {
> + if (port->dev != d)
Braces.
> + continue;
> +
> + if (port->pdev) {
> + l = usbbus_get_fw_dev_path_helper(port->pdev, bus, p, len);
> + }
> + l += snprintf(p + l, len - l, "%...@%x/", qdev_fw_name(&d->qdev),
> + port->index);
> + return l;
> + }
> + return 0;
With this return value...
> +}
> +
> +static char *usbbus_get_fw_dev_path(DeviceState *dev)
> +{
> + USBDevice *d = (USBDevice*)dev;
> + USBBus *bus = usb_bus_from_device(d);
> + char path[100];
> + int l;
> +
> + l = usbbus_get_fw_dev_path_helper(d, bus, path, sizeof(path));
> + path[l-1] = '\0';
...this statement will have undesirable effects...
> +
> + return strdup(path);
...like this.