/* If udev->state is already USB_STATE_NOTATTACHED then no change is made. Otherwise udev->state is set to new_state, and if new_state is USB_STATE_NOTATTACHED then all of udev's descendants' states are also set to USB_STATE_NOTATTACHED.  */
void usb_set_device_state(struct usb_host_virt_dev *udev, enum usb_device_state new_state)
/* If udev->state is already USB_STATE_NOTATTACHED then no change is made. Otherwise udev->state is set to new_state, and if new_state is USB_STATE_NOTATTACHED then all of udev's descendants' states are also set to USB_STATE_NOTATTACHED.  */
void usb_set_device_state(struct usb_host_virt_dev *udev, enum usb_device_state new_state)
{
    uint32_t flags;
    flags = hal_spin_lock_irqsave(&device_lock);
    if (udev->state == USB_STATE_NOTATTACHED)
        ;
    else if (new_state != USB_STATE_NOTATTACHED)
    {
        udev->state = new_state;
    }
    else
    {
        recursively_mark_NOTATTACHED(udev);
    }
    hal_spin_unlock_irqrestore(&device_lock, flags);
}