Skip to contentSkip to conversation

usb: gadget: make usb_ep_enable return -EBUSY if ep has already enabled

PATCH Superseded [email protected] 2 participants 4 messages Dec 4, 2015 – Dec 14, 2015 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: gadget: make usb_ep_enable return -EBUSY if ep has already enabled

From: "Du, Changbin" <[email protected]>

When usb_ep_enable on a enabled ep, the configuration of the ep probably has changed. In this scenario, the ep configuration in hw should be reprogrammed by udc driver. Hence, it is better to return an error to inform the caller.

---
 include/linux/usb/gadget.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/usb/gadget.h +1 -1
index d813bd2..89f9fdd 100644
@@ -268,7 +268,7 @@ static inline int usb_ep_enable(struct usb_ep *ep)
 	int ret;
 
 	if (ep->enabled)
-		return 0;
+		return -EBUSY;
 
 	ret = ep->ops->enable(ep, ep->desc);
 	if (ret)
Signature · 1 line
2.5.0
#1 lore raw

Hi,

Quoted 17 lines · [email protected] writes:

From: "Du, Changbin" <[email protected]>

When usb_ep_enable on a enabled ep, the configuration of the ep probably has changed. In this scenario, the ep configuration in hw should be reprogrammed by udc driver. Hence, it is better to return an error to inform the caller.

---
 include/linux/usb/gadget.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/usb/gadget.h +0 -0
index d813bd2..89f9fdd 100644

include/linux/usb/gadget.h static inline int usb_ep_enable(struct usb_ep *ep) · line 271

Quoted 5 lines
include/linux/usb/gadget.h +1 -1
@@ -268,7 +268,7 @@ static inline int usb_ep_enable(struct usb_ep *ep)
 	int ret;
 
 	if (ep->enabled)
-		return 0;
+		return -EBUSY;

While at that, can you add a WARN_ON() as well ?

	if (WARN_ON(ep->enabled))
        	return -EBUSY;
Signature · 1 line
balbi
#2 lore raw
Quoted 24 lines
Quoted 1 line

When usb_ep_enable on a enabled ep, the configuration of the ep

probably

Quoted 14 lines

has changed. In this scenario, the ep configuration in hw should be reprogrammed by udc driver. Hence, it is better to return an error to inform the caller.

---
 include/linux/usb/gadget.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/usb/gadget.h +0 -0
index d813bd2..89f9fdd 100644

include/linux/usb/gadget.h static inline int usb_ep_enable(struct usb_ep *ep) · line 271

Quoted 5 lines
include/linux/usb/gadget.h +1 -1
@@ -268,7 +268,7 @@ static inline int usb_ep_enable(struct usb_ep *ep)
 	int ret;
 
 	if (ep->enabled)
-		return 0;
+		return -EBUSY;

While at that, can you add a WARN_ON() as well ?

Quoted 5 lines
	if (WARN_ON(ep->enabled))
        	return -EBUSY;

--
balbi

I will update the patch, thanks.

#3 lore raw

PATCH v2 1/1 usb: gadget: make usb_ep_enable return -EBUSY if ep has already enabled

In reply to Felipe Balbi

From: "Du, Changbin" <[email protected]>

When usb_ep_enable on a enabled ep, the configuration of the ep probably has changed. In this scenario, the ep configuration in hw should be reprogrammed by udc driver. Hence, it is better to return an error to inform the caller.

---
change from v1: add WARN_ON_ONCE message.

---
 include/linux/usb/gadget.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
include/linux/usb/gadget.h +6 -2
index 3d583a1..b88df2a 100644
@@ -267,8 +267,12 @@ static inline int usb_ep_enable(struct usb_ep *ep)
 {
 	int ret;
 
-	if (ep->enabled)
-		return 0;
+	/**
+	 * An enabled ep may has requests in progress, hence shouldn't
+	 * reprogram its hw configuration.
+	 */
+	if (WARN_ON_ONCE(ep->enabled))
+		return -EBUSY;
 
 	ret = ep->ops->enable(ep, ep->desc);
 	if (ret)
Signature · 1 line
2.5.0