From nobody Sun Apr 30 06:57:49 2023 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Q8HGk2X74z48sC5; Sun, 30 Apr 2023 06:57:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Q8HGk1tmDz3Mm5; Sun, 30 Apr 2023 06:57:50 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682837870; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ovUHHAw0QziET2kttiil1yotqpe4ekBTbmEeacikbSg=; b=i8CnpPodDOEXZQa8vlDtxm6+ZBzGgPakRJ8XSOsgYyGIg3shIb4ITRHw89GsdyhmH2qFrc OgAUdDcPCwdj+0WiOiAtjDd2OUz6cCAO0qBFr9JW5VVRm8//B8pjvc1A4APNbomezRqcu7 m99uhA+s/nELL8BMubzK1diPX3JNcGXbBH1x9rVtaAVHB7en9ug+VZXT//TWcH+ybF8rjO hRtFT8Rp2wwJmFg0ZiYI086W0FKHbVSfYiBJYCnvRRZcQd5L2Q5jkPOoall4EXqLLWv+Nw X1jU09DtHT8SfC3WBr+xLyoOalH53BVRbkqvRn1g0yHbn6PTYF1CFU+zTkdy8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682837870; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ovUHHAw0QziET2kttiil1yotqpe4ekBTbmEeacikbSg=; b=S6M9C4+MC8/0RLpwmW1TJ9pu5gtcvHql38LHrexeBah/iOfJrPoZjjm5WAYO0PDqsO5Ptn CCHwjB7Q/ybar6Xac0IhW+LDIwOHuAwk/+Z/N2rxv4Vkan7cunRQYOWDxrfXhwQcqOGzgp mTL0oK1YqR11IbN/g4noEXF8/tToUk98vxrAC7LzBhtWIRNxGuSmEv7jevdaHI0qi4oLRT 9XRZCozEweVwLF1yircVsxdvMDVJLn339bkXmdiH/KlhQRcooXgmVKHsCwHB3/u9Rt8Ro/ WT0b7EhBEylzsfY62FlbC/XiqhzCaiOAgkGZgCEdMbBdFgusE0mlOZnt42csfA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1682837870; a=rsa-sha256; cv=none; b=k8A/2EhdFYJKtncpUrI8yEFgkKmT+IiU0sfb8dNfj3LRSybA0VNxFKy1u4x+GECm1yMTdS OtKhjswqSKTNGp/ijFzckX/lwdbEzpz9XWDiGFmpZ4PsjKr7l3J1YZ9aNcm9ucMp1xn8+Z 3kiS4CJ0UV8D+t7+WVvd9Nnh9Ds//R1bLUc++wqclw5RhJ+232ZvYsds0PzoII8dN/rPk+ 32F7uaQOq7IaLBoZGq5KHiCV6RlIXyy4GMI0NGyovYfI3M3bm1GhF7LarFkZ7MRTqfPfaD 9UKxcM9QwKP80pshjGPmBoLv82fkPUFwvVWOxfBMZrYC3BpxR5bP53nrIOM1jg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Q8HGk0ZKDz1CgB; Sun, 30 Apr 2023 06:57:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 33U6vnIr071470; Sun, 30 Apr 2023 06:57:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 33U6vnPk071469; Sun, 30 Apr 2023 06:57:49 GMT (envelope-from git) Date: Sun, 30 Apr 2023 06:57:49 GMT Message-Id: <202304300657.33U6vnPk071469@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Hans Petter Selasky Subject: git: c6203b6c00ca - stable/13 - usb(4): Call optional endpoint_uninit() when changing configuration or alternate setting. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: hselasky X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: c6203b6c00ca87a182a8a81d372ade0dc3e1f5f5 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by hselasky: URL: https://cgit.FreeBSD.org/src/commit/?id=c6203b6c00ca87a182a8a81d372ade0dc3e1f5f5 commit c6203b6c00ca87a182a8a81d372ade0dc3e1f5f5 Author: Hans Petter Selasky AuthorDate: 2022-12-15 22:32:47 +0000 Commit: Hans Petter Selasky CommitDate: 2023-04-30 06:56:16 +0000 usb(4): Call optional endpoint_uninit() when changing configuration or alternate setting. Sponsored by: NVIDIA Networking (cherry picked from commit e4611d26265fb9e3bd2a345cf4776863f49a2587) --- sys/dev/usb/usb_device.c | 55 ++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/sys/dev/usb/usb_device.c b/sys/dev/usb/usb_device.c index b5e51cbdc7a7..392d969587c0 100644 --- a/sys/dev/usb/usb_device.c +++ b/sys/dev/usb/usb_device.c @@ -841,38 +841,53 @@ usb_config_parse(struct usb_device *udev, uint8_t iface_index, uint8_t cmd) DPRINTFN(5, "iface_index=%d cmd=%d\n", iface_index, cmd); - if (cmd == USB_CFG_FREE) - goto cleanup; - - if (cmd == USB_CFG_INIT) { + if (cmd == USB_CFG_INIT || cmd == USB_CFG_FREE) { sx_assert(&udev->enum_sx, SA_LOCKED); /* check for in-use endpoints */ + if (cmd == USB_CFG_INIT) { + ep = udev->endpoints; + ep_max = udev->endpoints_max; + while (ep_max--) { + /* look for matching endpoints */ + if (iface_index == USB_IFACE_INDEX_ANY || + iface_index == ep->iface_index) { + if (ep->refcount_alloc != 0) + return (USB_ERR_IN_USE); + } + } + } + ep = udev->endpoints; ep_max = udev->endpoints_max; while (ep_max--) { /* look for matching endpoints */ - if ((iface_index == USB_IFACE_INDEX_ANY) || - (iface_index == ep->iface_index)) { - if (ep->refcount_alloc != 0) { - /* - * This typically indicates a - * more serious error. - */ - err = USB_ERR_IN_USE; - } else { - /* reset endpoint */ - memset(ep, 0, sizeof(*ep)); - /* make sure we don't zero the endpoint again */ - ep->iface_index = USB_IFACE_INDEX_ANY; - } + if (iface_index == USB_IFACE_INDEX_ANY || + iface_index == ep->iface_index) { + /* + * Check if hardware needs a callback + * to unconfigure the endpoint. This + * may happen multiple times, + * because the requested alternate + * setting may fail. The callback + * implementation should be aware of + * and handle that. + */ + if (ep->edesc != NULL && + udev->bus->methods->endpoint_uninit != NULL) + udev->bus->methods->endpoint_uninit(udev, ep); + + /* reset endpoint */ + memset(ep, 0, sizeof(*ep)); + /* make sure we don't zero the endpoint again */ + ep->iface_index = USB_IFACE_INDEX_ANY; } ep++; } - if (err) - return (err); + if (cmd == USB_CFG_FREE) + goto cleanup; } memset(&ips, 0, sizeof(ips));