void usb_claim_port(USBDevice *dev, Error **errp)

{

    USBBus *bus = usb_bus_from_device(dev);

    USBPort *port;



    assert(dev->port == NULL);



    if (dev->port_path) {

        QTAILQ_FOREACH(port, &bus->free, next) {

            if (strcmp(port->path, dev->port_path) == 0) {

                break;

            }

        }

        if (port == NULL) {

            error_setg(errp, "usb port %s (bus %s) not found (in use?)",

                       dev->port_path, bus->qbus.name);

            return;

        }

    } else {

        if (bus->nfree == 1 && strcmp(object_get_typename(OBJECT(dev)), "usb-hub") != 0) {

            /* Create a new hub and chain it on */

            usb_create_simple(bus, "usb-hub");

        }

        if (bus->nfree == 0) {

            error_setg(errp, "tried to attach usb device %s to a bus "

                       "with no free ports", dev->product_desc);

            return;

        }

        port = QTAILQ_FIRST(&bus->free);

    }

    trace_usb_port_claim(bus->busnr, port->path);



    QTAILQ_REMOVE(&bus->free, port, next);

    bus->nfree--;



    dev->port = port;

    port->dev = dev;



    QTAILQ_INSERT_TAIL(&bus->used, port, next);

    bus->nused++;

}

void usb_claim_port(USBDevice *dev, Error **errp)

{

    USBBus *bus = usb_bus_from_device(dev);

    USBPort *port;



    assert(dev->port == NULL);



    if (dev->port_path) {

        QTAILQ_FOREACH(port, &bus->free, next) {

            if (strcmp(port->path, dev->port_path) == 0) {

                break;

            }

        }

        if (port == NULL) {

            error_setg(errp, "usb port %s (bus %s) not found (in use?)",

                       dev->port_path, bus->qbus.name);

            return;

        }

    } else {

        if (bus->nfree == 1 && strcmp(object_get_typename(OBJECT(dev)), "usb-hub") != 0) {

            

            usb_create_simple(bus, "usb-hub");

        }

        if (bus->nfree == 0) {

            error_setg(errp, "tried to attach usb device %s to a bus "

                       "with no free ports", dev->product_desc);

            return;

        }

        port = QTAILQ_FIRST(&bus->free);

    }

    trace_usb_port_claim(bus->busnr, port->path);



    QTAILQ_REMOVE(&bus->free, port, next);

    bus->nfree--;



    dev->port = port;

    port->dev = dev;



    QTAILQ_INSERT_TAIL(&bus->used, port, next);

    bus->nused++;

}

            usb_create_simple(bus, "usb-hub");
void FUNC_0(USBDevice *VAR_0, Error **VAR_1)

{

    USBBus *bus = usb_bus_from_device(VAR_0);

    USBPort *port;



    assert(VAR_0->port == NULL);



    if (VAR_0->port_path) {

        QTAILQ_FOREACH(port, &bus->free, next) {

            if (strcmp(port->path, VAR_0->port_path) == 0) {

                break;

            }

        }

        if (port == NULL) {

            error_setg(VAR_1, "usb port %s (bus %s) not found (in use?)",

                       VAR_0->port_path, bus->qbus.name);

            return;

        }

    } else {

        if (bus->nfree == 1 && strcmp(object_get_typename(OBJECT(VAR_0)), "usb-hub") != 0) {

            

            usb_create_simple(bus, "usb-hub");

        }

        if (bus->nfree == 0) {

            error_setg(VAR_1, "tried to attach usb device %s to a bus "

                       "with no free ports", VAR_0->product_desc);

            return;

        }

        port = QTAILQ_FIRST(&bus->free);

    }

    trace_usb_port_claim(bus->busnr, port->path);



    QTAILQ_REMOVE(&bus->free, port, next);

    bus->nfree--;



    VAR_0->port = port;

    port->VAR_0 = VAR_0;



    QTAILQ_INSERT_TAIL(&bus->used, port, next);

    bus->nused++;

}

void FUNC_0(USBDevice *VAR_0, Error **VAR_1)
{ USBBus *bus = usb_bus_from_device(VAR_0); USBPort *port; assert(VAR_0->port == NULL); if (VAR_0->port_path) { QTAILQ_FOREACH(port, &bus->free, next) { if (strcmp(port->path, VAR_0->port_path) == 0) { break; } } if (port == NULL) { error_setg(VAR_1, "usb port %s (bus %s) not found (in use?)",
VAR_0->port_path, bus->qbus.name); return; } } else { if (bus->nfree == 1 && strcmp(object_get_typename(OBJECT(VAR_0)), "usb-hub") != 0) { usb_create_simple(bus, "usb-hub"); } if (bus->nfree == 0) { error_setg(VAR_1, "tried to attach usb device %s to a bus "
"with no free ports", VAR_0->product_desc); return; } port = QTAILQ_FIRST(&bus->free); } trace_usb_port_claim(bus->busnr, port->path); QTAILQ_REMOVE(&bus->free, port, next); bus->nfree--; VAR_0->port = port; port->VAR_0 = VAR_0; QTAILQ_INSERT_TAIL(&bus->used, port, next); bus->nused++; }