linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Wei Ming Chen <jj251510319013@gmail.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Felipe Balbi <balbi@kernel.org>,
	USB list <linux-usb@vger.kernel.org>
Subject: Re: [PATCH v2] usb: raw-gadget: return -EINVAL if no proper ep address available
Date: Tue, 15 Mar 2022 15:32:01 +0100	[thread overview]
Message-ID: <YjCjYeIdrWvyINpX@kroah.com> (raw)
In-Reply-To: <CA+fCnZeXMKXBzJm=akMNm4OVN53T_1aQw4n+yYZ6Vkqmj8+KAQ@mail.gmail.com>

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

      reply	other threads:[~2022-03-15 14:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YjCjYeIdrWvyINpX@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=andreyknvl@gmail.com \
    --cc=balbi@kernel.org \
    --cc=jj251510319013@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).