Skip to contentSkip to conversation

usb: gadget: call usb_gadget_check_config() to verify UDC capability

PATCH In review Frank Li 5 participants 9 messages Jul 7, 2023 – Jul 25, 2023

Subsystems (4)
lore
Share & tools
lore

Frank Li

author maintainer
#0 lore raw

PATCH v2 1/2 usb: gadget: call usb_gadget_check_config() to verify UDC capability

The legacy gadget driver omitted calling usb_gadget_check_config() to ensure that the USB device controller (UDC) has adequate resources, including sufficient endpoint numbers and types, to support the given configuration.

Previously, usb_add_config() was solely invoked by the legacy gadget driver. Adds the necessary usb_gadget_check_config() after the bind() operation to fix the issue.

Fixes dce49449e04f ("usb: cdns3: allocate TX FIFO size according to composite EP number")

---
change from v1 to v2
- not change for this patch, just add new patch to fix multi-config case

 drivers/usb/gadget/composite.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/usb/gadget/composite.c +4 -0
index 403563c06477..cb0a4e2cdbb7 100644
@@ -1029,6 +1029,10 @@ int usb_add_config(struct usb_composite_dev *cdev,
 		goto done;
 
 	status = bind(config);
+
+	if (status == 0)
+		status = usb_gadget_check_config(cdev->gadget);
+
 	if (status < 0) {
 		while (!list_empty(&config->functions)) {
 			struct usb_function		*f;
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH v2 2/2 usb: cdns3: fix incorrect calculation of ep_buf_size when more than one config

Previously, the cdns3_gadget_check_config() function in the cdns3 driver mistakenly calculated the ep_buf_size by considering only one configuration's endpoint information because "claimed" will be clear after call usb_gadget_check_config().

The fix involves checking the private flags EP_CLAIMED instead of relying on the "claimed" flag.

Fixes dce49449e04f ("usb: cdns3: allocate TX FIFO size according to composite EP number")
---
 drivers/usb/cdns3/cdns3-gadget.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/cdns3/cdns3-gadget.c +3 -1
index ccfaebca6faa..3326955f6991 100644
@@ -2999,12 +2999,14 @@ static int cdns3_gadget_udc_stop(struct usb_gadget *gadget)
 static int cdns3_gadget_check_config(struct usb_gadget *gadget)
 {
 	struct cdns3_device *priv_dev = gadget_to_cdns3_device(gadget);
+	struct cdns3_endpoint *priv_ep;
 	struct usb_ep *ep;
 	int n_in = 0;
 	int total;
 
 	list_for_each_entry(ep, &gadget->ep_list, ep_list) {
-		if (ep->claimed && (ep->address & USB_DIR_IN))
+		priv_ep = ep_to_cdns3_ep(ep);
+		if ((priv_ep->flags & EP_CLAIMED) && (ep->address & USB_DIR_IN))
 			n_in++;
 	}
 
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v2 2/2] usb: cdns3: fix incorrect calculation of ep_buf_size when more than one config

…

Quoted 2 lines

The fix involves checking the private flags EP_CLAIMED instead of relying on the "claimed" flag.

…

Please choose an imperative change suggestion.

See also:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.4#n94

Will a cover letter become helpful also for the presented small patch series?

Regards,
Markus

#3 lore raw

Re: [PATCH v2 2/2] usb: cdns3: fix incorrect calculation of ep_buf_size when more than one config

Quoted 6 lines · Markus Elfring

…

Quoted 2 lines

The fix involves checking the private flags EP_CLAIMED instead of relying on the "claimed" flag.

…

Please choose an imperative change suggestion.

Please do not review USB kernel patches, the comments you make are not helpful for developers and will be ignored.

greg k-h

#4 lore raw

Re: [v2 2/2] usb: cdns3: fix incorrect calculation of ep_buf_size when more than one config

Quoted 9 lines
Quoted 6 lines

…

Quoted 2 lines

The fix involves checking the private flags EP_CLAIMED instead of relying on the "claimed" flag.

…

Please choose an imperative change suggestion.

Please do not review USB kernel patches, the comments you make are not helpful for developers and will be ignored.

Does such a response really indicate that you a reject a known advice from the Linux development documentation?

Do you like the same patch reviews more by other contributors?

By the way:
Further change suggestions (including patches) from my selection are still waiting on more positive and constructive feedback.

Regards,
Markus

maintainer Acked-by on v2 2/2
#5 lore raw

Re: [PATCH v2 2/2] usb: cdns3: fix incorrect calculation of ep_buf_size when more than one config

In reply to Frank Li
Quoted 24 lines · Frank Li

Previously, the cdns3_gadget_check_config() function in the cdns3 driver mistakenly calculated the ep_buf_size by considering only one configuration's endpoint information because "claimed" will be clear after call usb_gadget_check_config().

The fix involves checking the private flags EP_CLAIMED instead of relying on the "claimed" flag.

Fixes dce49449e04f ("usb: cdns3: allocate TX FIFO size according to composite EP number")
---
 drivers/usb/cdns3/cdns3-gadget.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/cdns3/cdns3-gadget.c +1 -0
index ccfaebca6faa..3326955f6991 100644
@@ -2999,12 +2999,14 @@ static int cdns3_gadget_udc_stop(struct usb_gadget *gadget)
 static int cdns3_gadget_check_config(struct usb_gadget *gadget)
 {
 	struct cdns3_device *priv_dev = gadget_to_cdns3_device(gadget);
+	struct cdns3_endpoint *priv_ep;

drivers/usb/cdns3/cdns3-gadget.c static int cdns3_gadget_udc_stop(struct usb_gadget *gadget) · line 3011

Quoted 10 lines
drivers/usb/cdns3/cdns3-gadget.c +2 -1
 	struct usb_ep *ep;
 	int n_in = 0;
 	int total;
 
 	list_for_each_entry(ep, &gadget->ep_list, ep_list) {
-		if (ep->claimed && (ep->address & USB_DIR_IN))
+		priv_ep = ep_to_cdns3_ep(ep);
+		if ((priv_ep->flags & EP_CLAIMED) && (ep->address & USB_DIR_IN))
 			n_in++;
 	}
Signature · 2 lines
Thanks,
Peter Chen
Tested-by on v2 2/2
#6 lore raw

Re: [PATCH v2 2/2] usb: cdns3: fix incorrect calculation of ep_buf_size when more than one config

In reply to Frank Li
Quoted 25 lines · Frank Li

Previously, the cdns3_gadget_check_config() function in the cdns3 driver mistakenly calculated the ep_buf_size by considering only one configuration's endpoint information because "claimed" will be clear after call usb_gadget_check_config().

The fix involves checking the private flags EP_CLAIMED instead of relying on the "claimed" flag.

Fixes dce49449e04f ("usb: cdns3: allocate TX FIFO size according to composite EP number")
---
 drivers/usb/cdns3/cdns3-gadget.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/cdns3/cdns3-gadget.c +1 -0
index ccfaebca6faa..3326955f6991 100644
@@ -2999,12 +2999,14 @@ static int cdns3_gadget_udc_stop(struct usb_gadget *gadget)
 static int cdns3_gadget_check_config(struct usb_gadget *gadget)
 {
 	struct cdns3_device *priv_dev = gadget_to_cdns3_device(gadget);
+	struct cdns3_endpoint *priv_ep;
 	struct usb_ep *ep;

drivers/usb/cdns3/cdns3-gadget.c static int cdns3_gadget_udc_stop(struct usb_gadget *gadget) · line 3012

Quoted 10 lines
drivers/usb/cdns3/cdns3-gadget.c +2 -1
 	int n_in = 0;
 	int total;
 
 	list_for_each_entry(ep, &gadget->ep_list, ep_list) {
-		if (ep->claimed && (ep->address & USB_DIR_IN))
+		priv_ep = ep_to_cdns3_ep(ep);
+		if ((priv_ep->flags & EP_CLAIMED) && (ep->address & USB_DIR_IN))
 			n_in++;
 	}
 
Signature · 2 lines
Regards,
Ravi
author maintainer
#7 lore raw
In reply to Frank Li
Quoted 5 lines · Frank Li

The legacy gadget driver omitted calling usb_gadget_check_config() to ensure that the USB device controller (UDC) has adequate resources, including sufficient endpoint numbers and types, to support the given configuration.

Quoted 8 lines

Previously, usb_add_config() was solely invoked by the legacy gadget driver. Adds the necessary usb_gadget_check_config() after the bind() operation to fix the issue.

Fixes dce49449e04f ("usb: cdns3: allocate TX FIFO size according to composite EP number")

---

@greg
ping

Quoted 24 lines

change from v1 to v2
- not change for this patch, just add new patch to fix multi-config case

 drivers/usb/gadget/composite.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/usb/gadget/composite.c +4 -0
index 403563c06477..cb0a4e2cdbb7 100644
@@ -1029,6 +1029,10 @@ int usb_add_config(struct usb_composite_dev *cdev,
 		goto done;
 
 	status = bind(config);
+
+	if (status == 0)
+		status = usb_gadget_check_config(cdev->gadget);
+
 	if (status < 0) {
 		while (!list_empty(&config->functions)) {
 			struct usb_function		*f;
Signature · 1 line
2.34.1
maintainer
#8 lore raw
Quoted 10 lines · Frank Li
Quoted 9 lines · Frank Li

The legacy gadget driver omitted calling usb_gadget_check_config() to ensure that the USB device controller (UDC) has adequate resources, including sufficient endpoint numbers and types, to support the given configuration.

Previously, usb_add_config() was solely invoked by the legacy gadget driver. Adds the necessary usb_gadget_check_config() after the bind() operation to fix the issue.

Quoted 7 lines
Quoted 4 lines
Fixes dce49449e04f ("usb: cdns3: allocate TX FIFO size according to composite EP number")

---

@greg
ping

It's in my review queue, please give me a chance to catch up.

While you wait, doing review of other USB patches would be most appreciated.

thanks,

greg k-h