2015-12-04 07:32:46

by Du, Changbin

[permalink] [raw]
Subject: [PATCH] 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.

Signed-off-by: Du, Changbin <[email protected]>
---
include/linux/usb/gadget.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index d813bd2..89f9fdd 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -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)
--
2.5.0


2015-12-10 17:24:23

by Felipe Balbi

[permalink] [raw]
Subject: Re: [PATCH] usb: gadget: make usb_ep_enable return -EBUSY if ep has already enabled


Hi,

[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.
>
> Signed-off-by: Du, Changbin <[email protected]>
> ---
> include/linux/usb/gadget.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
> index d813bd2..89f9fdd 100644
> --- a/include/linux/usb/gadget.h
> +++ b/include/linux/usb/gadget.h
> @@ -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;

--
balbi


Attachments:
signature.asc (818.00 B)

2015-12-14 03:16:45

by Du, Changbin

[permalink] [raw]
Subject: RE: [PATCH] usb: gadget: make usb_ep_enable return -EBUSY if ep has already enabled

> > 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.
> >
> > Signed-off-by: Du, Changbin <[email protected]>
> > ---
> > include/linux/usb/gadget.h | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
> > index d813bd2..89f9fdd 100644
> > --- a/include/linux/usb/gadget.h
> > +++ b/include/linux/usb/gadget.h
> > @@ -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;
>
> --
> balbi
I will update the patch, thanks.

2015-12-14 03:48:25

by Du, Changbin

[permalink] [raw]
Subject: [PATCH v2] 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.

Signed-off-by: Du, Changbin <[email protected]>
---
change from v1: add WARN_ON_ONCE message.

---
include/linux/usb/gadget.h | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 3d583a1..b88df2a 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -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)
--
2.5.0