/* Free the URB as it purpose has been served.  */
void usbh_urb_free(usbh_urb *urb, usbh_transfer_status status)
/* Free the URB as it purpose has been served.  */
void usbh_urb_free(usbh_urb *urb, usbh_transfer_status status)
{
	LOG_CALL
	usbh_urb_id cached_urb_id = urb->id;
	urb->id = USBH_INVALID_URB_ID;
	if (urb->backend_tag != INVALID_BACKEND_TAG) {
		usbh_host *host = urb->transfer.device->host;
		host->backend->transfer_cancel(host, urb);
	}
	LOGF_LN("URB %"PRIu64" transfer status = %s", cached_urb_id,
		stringify_transfer_status(status));
	if (urb->transfer.callback != NULL) {
		if (urb->transfer.flags & USBH_FLAG_NO_SUCCESS_CALLBACK) {
			if (status == USBH_SUCCESS) {
				return;
			}
		}
		const usbh_transfer transfer = urb->transfer;
		transfer.callback(&transfer, status, cached_urb_id);
	}
}