From 8c244c51121d9cbc0c3bdaa8c0169135e60a99e4 Mon Sep 17 00:00:00 2001 From: Hemant Kumar Date: Wed, 11 Jul 2018 18:07:35 -0700 Subject: [PATCH 1/4] usb: gadget: uac2: Change synchronization type of data ep to SYNC As per the UAC 2.0 specification, ASYNC data endpoint is required to have feedback data endpoint. Since driver descriptor does not include feedback data endpoint, change endpoint bmAttributes for data endpoint to represent as SYNC instead of ASYNC. This allows device to enumerate on windows 10 PC. Change-Id: Ied3c2c94a8cd1cc130bb77484641f0d8d5ed642d Signed-off-by: Hemant Kumar --- drivers/usb/gadget/function/f_uac2.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/function/f_uac2.c b/drivers/usb/gadget/function/f_uac2.c index 0927d4c0c1db..ced1575628b2 100644 --- a/drivers/usb/gadget/function/f_uac2.c +++ b/drivers/usb/gadget/function/f_uac2.c @@ -276,7 +276,7 @@ static struct usb_endpoint_descriptor fs_epout_desc = { .bDescriptorType = USB_DT_ENDPOINT, .bEndpointAddress = USB_DIR_OUT, - .bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ASYNC, + .bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_SYNC, .wMaxPacketSize = cpu_to_le16(1023), .bInterval = 1, }; @@ -285,7 +285,7 @@ static struct usb_endpoint_descriptor hs_epout_desc = { .bLength = USB_DT_ENDPOINT_SIZE, .bDescriptorType = USB_DT_ENDPOINT, - .bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ASYNC, + .bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_SYNC, .wMaxPacketSize = cpu_to_le16(1024), .bInterval = 4, }; @@ -360,7 +360,7 @@ static struct usb_endpoint_descriptor fs_epin_desc = { .bDescriptorType = USB_DT_ENDPOINT, .bEndpointAddress = USB_DIR_IN, - .bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ASYNC, + .bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_SYNC, .wMaxPacketSize = cpu_to_le16(1023), .bInterval = 1, }; @@ -369,7 +369,7 @@ static struct usb_endpoint_descriptor hs_epin_desc = { .bLength = USB_DT_ENDPOINT_SIZE, .bDescriptorType = USB_DT_ENDPOINT, - .bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ASYNC, + .bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_SYNC, .wMaxPacketSize = cpu_to_le16(1024), .bInterval = 4, }; From 9b107b59acfcca6c01c251a79036e94aa930727f Mon Sep 17 00:00:00 2001 From: Jack Pham Date: Mon, 8 Jun 2020 11:26:57 -0700 Subject: [PATCH 2/4] usb: gadget: Allow USB_CONFIGFS_F_UAC2 to be built as a module Simply changing bool to tristate should do the trick. Change-Id: I12916801778c4cc2150f9f2c820095a09b104851 Signed-off-by: Jack Pham --- drivers/usb/gadget/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index ec6507314155..70e68e7694e3 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig @@ -459,7 +459,7 @@ config USB_CONFIGFS_F_UAC1_LEGACY to be present on the device. config USB_CONFIGFS_F_UAC2 - bool "Audio Class 2.0" + tristate "Audio Class 2.0" depends on USB_CONFIGFS depends on SND select USB_LIBCOMPOSITE From da731b304ae94c541bd96bba0c935a7d776e57b8 Mon Sep 17 00:00:00 2001 From: Jack Pham Date: Mon, 8 Jun 2020 11:28:51 -0700 Subject: [PATCH 3/4] arm64: defconfig: Enable USB_CONFIGFS_F_UAC2 for Lahaina Enable F_UAC2 USB ConfigFS driver as a GKI module on Lahaina. Change-Id: I72ba962aa13832091ad78db9404bddf4c29df066 Signed-off-by: Jack Pham --- arch/arm64/configs/vendor/lahaina_GKI.config | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/configs/vendor/lahaina_GKI.config b/arch/arm64/configs/vendor/lahaina_GKI.config index 4b1ccb339a6e..370d5f411955 100644 --- a/arch/arm64/configs/vendor/lahaina_GKI.config +++ b/arch/arm64/configs/vendor/lahaina_GKI.config @@ -36,6 +36,7 @@ CONFIG_USB_CONFIGFS_F_DIAG=m CONFIG_USB_CONFIGFS_F_CCID=m CONFIG_USB_CONFIGFS_F_CDEV=m CONFIG_USB_CONFIGFS_F_GSI=m +CONFIG_USB_CONFIGFS_F_UAC2=m CONFIG_USB_STORAGE=m CONFIG_TYPEC_UCSI=m CONFIG_UCSI_QTI_GLINK=m From 29974620bdcaf099ac2df54eea6f2f36306ad1d0 Mon Sep 17 00:00:00 2001 From: Jack Pham Date: Mon, 15 Jun 2020 10:23:07 -0700 Subject: [PATCH 4/4] usb: gadget: audio: Free requests only after callback As per the kernel doc for usb_ep_dequeue(), it states that "this routine is asynchronous, that is, it may return before the completion routine runs". And indeed the dwc3 gadget driver recently updated its behavior to place dequeued requests on to a cancelled list to be given back later after the endpoint is stopped. The free_ep() was incorrectly assuming that a request was ready to be freed after calling dequeue which results in a use-after-free in dwc3 when it traverses its cancelled list. Fix this by moving the usb_ep_free_request() call to the callback itself in case the ep is disabled. Change-Id: I51751e002ad86b226d9f0d872c66a77e94e8cab7 Signed-off-by: Jack Pham --- drivers/usb/gadget/function/u_audio.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/function/u_audio.c b/drivers/usb/gadget/function/u_audio.c index 56906d15fb55..f08f036d520e 100644 --- a/drivers/usb/gadget/function/u_audio.c +++ b/drivers/usb/gadget/function/u_audio.c @@ -89,7 +89,12 @@ static void u_audio_iso_complete(struct usb_ep *ep, struct usb_request *req) struct snd_uac_chip *uac = prm->uac; /* i/f shutting down */ - if (!prm->ep_enabled || req->status == -ESHUTDOWN) + if (!prm->ep_enabled) { + usb_ep_free_request(ep, req); + return; + } + + if (req->status == -ESHUTDOWN) return; /* @@ -352,7 +357,6 @@ static inline void free_ep(struct uac_rtd_params *prm, struct usb_ep *ep) for (i = 0; i < params->req_number; i++) { if (prm->ureq[i].req) { usb_ep_dequeue(ep, prm->ureq[i].req); - usb_ep_free_request(ep, prm->ureq[i].req); prm->ureq[i].req = NULL; } }