/* The device can be found directly from the address (see wusb_cack_add() for where the device address is set to port_idx +2), except when the address is zero.  */
static struct wusb_dev* wusbhc_find_dev_by_addr(struct wusbhc *wusbhc, u8 addr)
/* The device can be found directly from the address (see wusb_cack_add() for where the device address is set to port_idx +2), except when the address is zero.  */
static struct wusb_dev* wusbhc_find_dev_by_addr(struct wusbhc *wusbhc, u8 addr)
{
	int p;
	if (addr == 0xff)
		return NULL;
	if (addr > 0) {
		int port = (addr & ~0x80) - 2;
		if (port < 0 || port >= wusbhc->ports_max)
			return NULL;
		return wusb_port_by_idx(wusbhc, port)->wusb_dev;
	}
	for (p = 0; p < wusbhc->ports_max; p++) {
		struct wusb_dev *wusb_dev = wusb_port_by_idx(wusbhc, p)->wusb_dev;
		if (wusb_dev && wusb_dev->addr == addr)
			return wusb_dev;
	}
	return NULL;
}