All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: return -EINVAL if no proper ep address available
@ 2022-03-08 11:28 Wei Ming Chen
  2022-03-09 23:59 ` Andrey Konovalov
  0 siblings, 1 reply; 7+ messages in thread
From: Wei Ming Chen @ 2022-03-08 11:28 UTC (permalink / raw)
  To: linux-kernel; +Cc: andreyknvl, balbi, gregkh, linux-usb, Wei Ming Chen

If we try to use raw_ioctl_ep_enable() for ep5in on a hardware that
only support from ep1-ep4 for both in and out direction, it will return
-EBUSY originally.

I think it will be more intuitive if we return -EINVAL, Cuz -EBUSY sounds
like ep5in is not available now, but might be available in the future.

Signed-off-by: Wei Ming Chen <jj251510319013@gmail.com>
---
 drivers/usb/gadget/legacy/raw_gadget.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/usb/gadget/legacy/raw_gadget.c b/drivers/usb/gadget/legacy/raw_gadget.c
index d86c3a36441e..b4cc083a7ca6 100644
--- a/drivers/usb/gadget/legacy/raw_gadget.c
+++ b/drivers/usb/gadget/legacy/raw_gadget.c
@@ -758,6 +758,7 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value)
 	unsigned long flags;
 	struct usb_endpoint_descriptor *desc;
 	struct raw_ep *ep;
+	bool ep_num_matched = false;
 
 	desc = memdup_user((void __user *)value, sizeof(*desc));
 	if (IS_ERR(desc))
@@ -792,6 +793,7 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value)
 		if (ep->addr != usb_endpoint_num(desc) &&
 				ep->addr != USB_RAW_EP_ADDR_ANY)
 			continue;
+		ep_num_matched = true;
 		if (!usb_gadget_ep_match_desc(dev->gadget, ep->ep, desc, NULL))
 			continue;
 		ep->ep->desc = desc;
@@ -815,6 +817,12 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value)
 		goto out_unlock;
 	}
 
+	if (!ep_num_matched) {
+		dev_dbg(&dev->gadget->dev, "fail, no proper ep address available\n");
+		ret = -EINVAL;
+		goto out_free;
+	}
+
 	dev_dbg(&dev->gadget->dev, "fail, no gadget endpoints available\n");
 	ret = -EBUSY;
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] usb: gadget: return -EINVAL if no proper ep address available
  2022-03-08 11:28 [PATCH] usb: gadget: return -EINVAL if no proper ep address available Wei Ming Chen
@ 2022-03-09 23:59 ` Andrey Konovalov
  2022-03-11  3:22   ` [PATCH v2] usb: raw-gadget: " Wei Ming Chen
  2022-03-11  8:29   ` Wei Ming Chen
  0 siblings, 2 replies; 7+ messages in thread
From: Andrey Konovalov @ 2022-03-09 23:59 UTC (permalink / raw)
  To: Wei Ming Chen; +Cc: LKML, Felipe Balbi, Greg Kroah-Hartman, USB list

[-- Attachment #1: Type: text/plain, Size: 2523 bytes --]

On Tue, Mar 8, 2022 at 12:31 PM Wei Ming Chen <jj251510319013@gmail.com> wrote:
>

Hi,

The commit name should be prefixed with "usb: raw-gadget:".

> If we try to use raw_ioctl_ep_enable() for ep5in on a hardware that
> only support from ep1-ep4 for both in and out direction, it will return
> -EBUSY originally.
>
> I think it will be more intuitive if we return -EINVAL, Cuz -EBUSY sounds
> like ep5in is not available now, but might be available in the future.

Cuz -> because

>
> Signed-off-by: Wei Ming Chen <jj251510319013@gmail.com>
> ---
>  drivers/usb/gadget/legacy/raw_gadget.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/drivers/usb/gadget/legacy/raw_gadget.c b/drivers/usb/gadget/legacy/raw_gadget.c
> index d86c3a36441e..b4cc083a7ca6 100644
> --- a/drivers/usb/gadget/legacy/raw_gadget.c
> +++ b/drivers/usb/gadget/legacy/raw_gadget.c
> @@ -758,6 +758,7 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value)
>         unsigned long flags;
>         struct usb_endpoint_descriptor *desc;
>         struct raw_ep *ep;
> +       bool ep_num_matched = false;
>
>         desc = memdup_user((void __user *)value, sizeof(*desc));
>         if (IS_ERR(desc))
> @@ -792,6 +793,7 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value)
>                 if (ep->addr != usb_endpoint_num(desc) &&
>                                 ep->addr != USB_RAW_EP_ADDR_ANY)
>                         continue;
> +               ep_num_matched = true;
>                 if (!usb_gadget_ep_match_desc(dev->gadget, ep->ep, desc, NULL))
>                         continue;
>                 ep->ep->desc = desc;
> @@ -815,6 +817,12 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value)
>                 goto out_unlock;
>         }
>
> +       if (!ep_num_matched) {
> +               dev_dbg(&dev->gadget->dev, "fail, no proper ep address available\n");
> +               ret = -EINVAL;
> +               goto out_free;
> +       }

Thinking more about this, we should cover the following cases:

1. If there are no endpoints that match the provided descriptor, return EINVAL.

2. If there are matching endpoints, but they are all already enabled,
return EBUSY.

A draft change is attached.

What do you think?

If the suggested change looks good, feel free to incorporate it into
the version 2 of your patch.

> +
>         dev_dbg(&dev->gadget->dev, "fail, no gadget endpoints available\n");
>         ret = -EBUSY;
>
> --
> 2.25.1
>

Thanks!

[-- Attachment #2: raw-gadget-retval.patch --]
[-- Type: text/x-patch, Size: 1208 bytes --]

diff --git a/drivers/usb/gadget/legacy/raw_gadget.c b/drivers/usb/gadget/legacy/raw_gadget.c
index d86c3a36441e..a0d5edf1b2c5 100644
--- a/drivers/usb/gadget/legacy/raw_gadget.c
+++ b/drivers/usb/gadget/legacy/raw_gadget.c
@@ -787,13 +787,14 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value)
 
 	for (i = 0; i < dev->eps_num; i++) {
 		ep = &dev->eps[i];
-		if (ep->state != STATE_EP_DISABLED)
-			continue;
 		if (ep->addr != usb_endpoint_num(desc) &&
 				ep->addr != USB_RAW_EP_ADDR_ANY)
 			continue;
 		if (!usb_gadget_ep_match_desc(dev->gadget, ep->ep, desc, NULL))
 			continue;
+		ep_props_matched = true;
+		if (ep->state != STATE_EP_DISABLED)
+			continue;
 		ep->ep->desc = desc;
 		ret = usb_ep_enable(ep->ep);
 		if (ret < 0) {
@@ -815,8 +816,13 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value)
 		goto out_unlock;
 	}
 
-	dev_dbg(&dev->gadget->dev, "fail, no gadget endpoints available\n");
-	ret = -EBUSY;
+	if (!ep_props_matched)
+		dev_dbg(&dev->gadget->dev, "fail, bad endpoint descriptor\n");
+		ret = -EINVAL;
+	} else {
+		dev_dbg(&dev->gadget->dev, "fail, no endpoints available\n");
+		ret = -EBUSY;
+	}
 
 out_free:
 	kfree(desc);

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2] usb: raw-gadget: return -EINVAL if no proper ep address available
  2022-03-09 23:59 ` Andrey Konovalov
@ 2022-03-11  3:22   ` Wei Ming Chen
  2022-03-11  6:43     ` Greg KH
  2022-03-11  8:29   ` Wei Ming Chen
  1 sibling, 1 reply; 7+ messages in thread
From: Wei Ming Chen @ 2022-03-11  3:22 UTC (permalink / raw)
  To: linux-kernel; +Cc: andreyknvl, balbi, gregkh, linux-usb, Wei Ming Chen

If we try to use raw_ioctl_ep_enable() for ep5in on a hardware that
only support from ep1-ep4 for both in and out direction, it will return
-EBUSY originally.

I think it will be more intuitive if we return -EINVAL, because -EBUSY
sounds like ep5in is not available now, but might be available in the
future.

Signed-off-by: Wei Ming Chen <jj251510319013@gmail.com>
---
 drivers/usb/gadget/legacy/raw_gadget.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/gadget/legacy/raw_gadget.c b/drivers/usb/gadget/legacy/raw_gadget.c
index d86c3a36441e..e5707626c4d4 100644
--- a/drivers/usb/gadget/legacy/raw_gadget.c
+++ b/drivers/usb/gadget/legacy/raw_gadget.c
@@ -758,6 +758,7 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value)
 	unsigned long flags;
 	struct usb_endpoint_descriptor *desc;
 	struct raw_ep *ep;
+	bool ep_props_matched = false;
 
 	desc = memdup_user((void __user *)value, sizeof(*desc));
 	if (IS_ERR(desc))
@@ -787,13 +788,14 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value)
 
 	for (i = 0; i < dev->eps_num; i++) {
 		ep = &dev->eps[i];
-		if (ep->state != STATE_EP_DISABLED)
-			continue;
 		if (ep->addr != usb_endpoint_num(desc) &&
 				ep->addr != USB_RAW_EP_ADDR_ANY)
 			continue;
 		if (!usb_gadget_ep_match_desc(dev->gadget, ep->ep, desc, NULL))
 			continue;
+		ep_props_matched = true;
+		if (ep->state != STATE_EP_DISABLED)
+			continue;
 		ep->ep->desc = desc;
 		ret = usb_ep_enable(ep->ep);
 		if (ret < 0) {
@@ -815,8 +817,13 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value)
 		goto out_unlock;
 	}
 
-	dev_dbg(&dev->gadget->dev, "fail, no gadget endpoints available\n");
-	ret = -EBUSY;
+	if (!ep_props_matched) {
+		dev_dbg(&dev->gadget->dev, "fail, bad endpoint descriptor\n");
+		ret = -EINVAL;
+	} else {
+		dev_dbg(&dev->gadget->dev, "fail, no endpoints available\n");
+		ret = -EBUSY;
+	}
 
 out_free:
 	kfree(desc);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] usb: raw-gadget: return -EINVAL if no proper ep address available
  2022-03-11  3:22   ` [PATCH v2] usb: raw-gadget: " Wei Ming Chen
@ 2022-03-11  6:43     ` Greg KH
  0 siblings, 0 replies; 7+ messages in thread
From: Greg KH @ 2022-03-11  6:43 UTC (permalink / raw)
  To: Wei Ming Chen; +Cc: linux-kernel, andreyknvl, balbi, linux-usb

On Fri, Mar 11, 2022 at 11:22:38AM +0800, Wei Ming Chen wrote:
> If we try to use raw_ioctl_ep_enable() for ep5in on a hardware that
> only support from ep1-ep4 for both in and out direction, it will return
> -EBUSY originally.
> 
> I think it will be more intuitive if we return -EINVAL, because -EBUSY
> sounds like ep5in is not available now, but might be available in the
> future.
> 
> Signed-off-by: Wei Ming Chen <jj251510319013@gmail.com>
> ---
>  drivers/usb/gadget/legacy/raw_gadget.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/usb/gadget/legacy/raw_gadget.c b/drivers/usb/gadget/legacy/raw_gadget.c
> index d86c3a36441e..e5707626c4d4 100644
> --- a/drivers/usb/gadget/legacy/raw_gadget.c
> +++ b/drivers/usb/gadget/legacy/raw_gadget.c
> @@ -758,6 +758,7 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value)
>  	unsigned long flags;
>  	struct usb_endpoint_descriptor *desc;
>  	struct raw_ep *ep;
> +	bool ep_props_matched = false;
>  
>  	desc = memdup_user((void __user *)value, sizeof(*desc));
>  	if (IS_ERR(desc))
> @@ -787,13 +788,14 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value)
>  
>  	for (i = 0; i < dev->eps_num; i++) {
>  		ep = &dev->eps[i];
> -		if (ep->state != STATE_EP_DISABLED)
> -			continue;
>  		if (ep->addr != usb_endpoint_num(desc) &&
>  				ep->addr != USB_RAW_EP_ADDR_ANY)
>  			continue;
>  		if (!usb_gadget_ep_match_desc(dev->gadget, ep->ep, desc, NULL))
>  			continue;
> +		ep_props_matched = true;
> +		if (ep->state != STATE_EP_DISABLED)
> +			continue;
>  		ep->ep->desc = desc;
>  		ret = usb_ep_enable(ep->ep);
>  		if (ret < 0) {
> @@ -815,8 +817,13 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value)
>  		goto out_unlock;
>  	}
>  
> -	dev_dbg(&dev->gadget->dev, "fail, no gadget endpoints available\n");
> -	ret = -EBUSY;
> +	if (!ep_props_matched) {
> +		dev_dbg(&dev->gadget->dev, "fail, bad endpoint descriptor\n");
> +		ret = -EINVAL;
> +	} else {
> +		dev_dbg(&dev->gadget->dev, "fail, no endpoints available\n");
> +		ret = -EBUSY;
> +	}
>  
>  out_free:
>  	kfree(desc);
> -- 
> 2.25.1
> 

Hi,

This is the friendly patch-bot of Greg Kroah-Hartman.  You have sent him
a patch that has triggered this response.  He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created.  Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.

You are receiving this message because of the following common error(s)
as indicated below:

- This looks like a new version of a previously submitted patch, but you
  did not list below the --- line any changes from the previous version.
  Please read the section entitled "The canonical patch format" in the
  kernel file, Documentation/SubmittingPatches for what needs to be done
  here to properly describe this.

If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.

thanks,

greg k-h's patch email bot

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2] usb: raw-gadget: return -EINVAL if no proper ep address available
  2022-03-09 23:59 ` Andrey Konovalov
  2022-03-11  3:22   ` [PATCH v2] usb: raw-gadget: " Wei Ming Chen
@ 2022-03-11  8:29   ` Wei Ming Chen
  2022-03-13 14:52     ` Andrey Konovalov
  1 sibling, 1 reply; 7+ messages in thread
From: Wei Ming Chen @ 2022-03-11  8:29 UTC (permalink / raw)
  To: linux-kernel; +Cc: andreyknvl, balbi, gregkh, linux-usb, Wei Ming Chen

If we try to use raw_ioctl_ep_enable() for ep5in on a hardware that
only support from ep1-ep4 for both in and out direction, it will return
-EBUSY originally.

I think it will be more intuitive if we return -EINVAL, because -EBUSY
sounds like ep5in is not available now, but might be available in the
future.

Signed-off-by: Wei Ming Chen <jj251510319013@gmail.com>
---

Changes in v2:
- Rename variable from ep_num_matched to ep_props_matched
- Incorporate the patch from Andrey Konovalov that cover
  the foloowing cases:
    1. If there are no endpoints that match the provided descriptor, return
       EINVAL.
    2. If there are matching endpoints, but they are all already enabled,
       return EBUSY.

 drivers/usb/gadget/legacy/raw_gadget.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/gadget/legacy/raw_gadget.c b/drivers/usb/gadget/legacy/raw_gadget.c
index d86c3a36441e..e5707626c4d4 100644
--- a/drivers/usb/gadget/legacy/raw_gadget.c
+++ b/drivers/usb/gadget/legacy/raw_gadget.c
@@ -758,6 +758,7 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value)
 	unsigned long flags;
 	struct usb_endpoint_descriptor *desc;
 	struct raw_ep *ep;
+	bool ep_props_matched = false;
 
 	desc = memdup_user((void __user *)value, sizeof(*desc));
 	if (IS_ERR(desc))
@@ -787,13 +788,14 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value)
 
 	for (i = 0; i < dev->eps_num; i++) {
 		ep = &dev->eps[i];
-		if (ep->state != STATE_EP_DISABLED)
-			continue;
 		if (ep->addr != usb_endpoint_num(desc) &&
 				ep->addr != USB_RAW_EP_ADDR_ANY)
 			continue;
 		if (!usb_gadget_ep_match_desc(dev->gadget, ep->ep, desc, NULL))
 			continue;
+		ep_props_matched = true;
+		if (ep->state != STATE_EP_DISABLED)
+			continue;
 		ep->ep->desc = desc;
 		ret = usb_ep_enable(ep->ep);
 		if (ret < 0) {
@@ -815,8 +817,13 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value)
 		goto out_unlock;
 	}
 
-	dev_dbg(&dev->gadget->dev, "fail, no gadget endpoints available\n");
-	ret = -EBUSY;
+	if (!ep_props_matched) {
+		dev_dbg(&dev->gadget->dev, "fail, bad endpoint descriptor\n");
+		ret = -EINVAL;
+	} else {
+		dev_dbg(&dev->gadget->dev, "fail, no endpoints available\n");
+		ret = -EBUSY;
+	}
 
 out_free:
 	kfree(desc);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] usb: raw-gadget: return -EINVAL if no proper ep address available
  2022-03-11  8:29   ` Wei Ming Chen
@ 2022-03-13 14:52     ` Andrey Konovalov
  2022-03-15 14:32       ` Greg Kroah-Hartman
  0 siblings, 1 reply; 7+ messages in thread
From: Andrey Konovalov @ 2022-03-13 14:52 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Wei Ming Chen; +Cc: LKML, Felipe Balbi, USB list

On Fri, Mar 11, 2022 at 9:30 AM Wei Ming Chen <jj251510319013@gmail.com> wrote:
>
> If we try to use raw_ioctl_ep_enable() for ep5in on a hardware that
> only support from ep1-ep4 for both in and out direction, it will return
> -EBUSY originally.
>
> I think it will be more intuitive if we return -EINVAL, because -EBUSY
> sounds like ep5in is not available now, but might be available in the
> future.
>
> Signed-off-by: Wei Ming Chen <jj251510319013@gmail.com>
> ---
>
> Changes in v2:
> - Rename variable from ep_num_matched to ep_props_matched
> - Incorporate the patch from Andrey Konovalov that cover
>   the foloowing cases:
>     1. If there are no endpoints that match the provided descriptor, return
>        EINVAL.
>     2. If there are matching endpoints, but they are all already enabled,
>        return EBUSY.
>
>  drivers/usb/gadget/legacy/raw_gadget.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/usb/gadget/legacy/raw_gadget.c b/drivers/usb/gadget/legacy/raw_gadget.c
> index d86c3a36441e..e5707626c4d4 100644
> --- a/drivers/usb/gadget/legacy/raw_gadget.c
> +++ b/drivers/usb/gadget/legacy/raw_gadget.c
> @@ -758,6 +758,7 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value)
>         unsigned long flags;
>         struct usb_endpoint_descriptor *desc;
>         struct raw_ep *ep;
> +       bool ep_props_matched = false;
>
>         desc = memdup_user((void __user *)value, sizeof(*desc));
>         if (IS_ERR(desc))
> @@ -787,13 +788,14 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value)
>
>         for (i = 0; i < dev->eps_num; i++) {
>                 ep = &dev->eps[i];
> -               if (ep->state != STATE_EP_DISABLED)
> -                       continue;
>                 if (ep->addr != usb_endpoint_num(desc) &&
>                                 ep->addr != USB_RAW_EP_ADDR_ANY)
>                         continue;
>                 if (!usb_gadget_ep_match_desc(dev->gadget, ep->ep, desc, NULL))
>                         continue;
> +               ep_props_matched = true;
> +               if (ep->state != STATE_EP_DISABLED)
> +                       continue;
>                 ep->ep->desc = desc;
>                 ret = usb_ep_enable(ep->ep);
>                 if (ret < 0) {
> @@ -815,8 +817,13 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value)
>                 goto out_unlock;
>         }
>
> -       dev_dbg(&dev->gadget->dev, "fail, no gadget endpoints available\n");
> -       ret = -EBUSY;
> +       if (!ep_props_matched) {
> +               dev_dbg(&dev->gadget->dev, "fail, bad endpoint descriptor\n");
> +               ret = -EINVAL;
> +       } else {
> +               dev_dbg(&dev->gadget->dev, "fail, no endpoints available\n");
> +               ret = -EBUSY;
> +       }
>
>  out_free:
>         kfree(desc);
> --
> 2.25.1
>

Reviewed-by: Andrey Konovalov <andreyknvl@gmail.com>

Greg, could you consider picking this up?

Thanks!

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] usb: raw-gadget: return -EINVAL if no proper ep address available
  2022-03-13 14:52     ` Andrey Konovalov
@ 2022-03-15 14:32       ` Greg Kroah-Hartman
  0 siblings, 0 replies; 7+ messages in thread
From: Greg Kroah-Hartman @ 2022-03-15 14:32 UTC (permalink / raw)
  To: Andrey Konovalov; +Cc: Wei Ming Chen, LKML, Felipe Balbi, USB list

On Sun, Mar 13, 2022 at 03:52:35PM +0100, Andrey Konovalov wrote:
> On Fri, Mar 11, 2022 at 9:30 AM Wei Ming Chen <jj251510319013@gmail.com> wrote:
> >
> > If we try to use raw_ioctl_ep_enable() for ep5in on a hardware that
> > only support from ep1-ep4 for both in and out direction, it will return
> > -EBUSY originally.
> >
> > I think it will be more intuitive if we return -EINVAL, because -EBUSY
> > sounds like ep5in is not available now, but might be available in the
> > future.
> >
> > Signed-off-by: Wei Ming Chen <jj251510319013@gmail.com>
> > ---
> >
> > Changes in v2:
> > - Rename variable from ep_num_matched to ep_props_matched
> > - Incorporate the patch from Andrey Konovalov that cover
> >   the foloowing cases:
> >     1. If there are no endpoints that match the provided descriptor, return
> >        EINVAL.
> >     2. If there are matching endpoints, but they are all already enabled,
> >        return EBUSY.
> >
> >  drivers/usb/gadget/legacy/raw_gadget.c | 15 +++++++++++----
> >  1 file changed, 11 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/usb/gadget/legacy/raw_gadget.c b/drivers/usb/gadget/legacy/raw_gadget.c
> > index d86c3a36441e..e5707626c4d4 100644
> > --- a/drivers/usb/gadget/legacy/raw_gadget.c
> > +++ b/drivers/usb/gadget/legacy/raw_gadget.c
> > @@ -758,6 +758,7 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value)
> >         unsigned long flags;
> >         struct usb_endpoint_descriptor *desc;
> >         struct raw_ep *ep;
> > +       bool ep_props_matched = false;
> >
> >         desc = memdup_user((void __user *)value, sizeof(*desc));
> >         if (IS_ERR(desc))
> > @@ -787,13 +788,14 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value)
> >
> >         for (i = 0; i < dev->eps_num; i++) {
> >                 ep = &dev->eps[i];
> > -               if (ep->state != STATE_EP_DISABLED)
> > -                       continue;
> >                 if (ep->addr != usb_endpoint_num(desc) &&
> >                                 ep->addr != USB_RAW_EP_ADDR_ANY)
> >                         continue;
> >                 if (!usb_gadget_ep_match_desc(dev->gadget, ep->ep, desc, NULL))
> >                         continue;
> > +               ep_props_matched = true;
> > +               if (ep->state != STATE_EP_DISABLED)
> > +                       continue;
> >                 ep->ep->desc = desc;
> >                 ret = usb_ep_enable(ep->ep);
> >                 if (ret < 0) {
> > @@ -815,8 +817,13 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value)
> >                 goto out_unlock;
> >         }
> >
> > -       dev_dbg(&dev->gadget->dev, "fail, no gadget endpoints available\n");
> > -       ret = -EBUSY;
> > +       if (!ep_props_matched) {
> > +               dev_dbg(&dev->gadget->dev, "fail, bad endpoint descriptor\n");
> > +               ret = -EINVAL;
> > +       } else {
> > +               dev_dbg(&dev->gadget->dev, "fail, no endpoints available\n");
> > +               ret = -EBUSY;
> > +       }
> >
> >  out_free:
> >         kfree(desc);
> > --
> > 2.25.1
> >
> 
> Reviewed-by: Andrey Konovalov <andreyknvl@gmail.com>
> 
> Greg, could you consider picking this up?

Now picked up, thanks.

greg k-h

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-03-15 14:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-08 11:28 [PATCH] usb: gadget: return -EINVAL if no proper ep address available Wei Ming Chen
2022-03-09 23:59 ` Andrey Konovalov
2022-03-11  3:22   ` [PATCH v2] usb: raw-gadget: " Wei Ming Chen
2022-03-11  6:43     ` Greg KH
2022-03-11  8:29   ` Wei Ming Chen
2022-03-13 14:52     ` Andrey Konovalov
2022-03-15 14:32       ` Greg Kroah-Hartman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.