From: Wei Ming Chen <jj251510319013@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: andreyknvl@gmail.com, balbi@kernel.org,
gregkh@linuxfoundation.org, linux-usb@vger.kernel.org,
Wei Ming Chen <jj251510319013@gmail.com>
Subject: [PATCH] usb: gadget: return -EINVAL if no proper ep address available
Date: Tue, 8 Mar 2022 19:28:32 +0800 [thread overview]
Message-ID: <20220308112832.6170-1-jj251510319013@gmail.com> (raw)
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
next reply other threads:[~2022-03-08 11:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-08 11:28 Wei Ming Chen [this message]
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
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=20220308112832.6170-1-jj251510319013@gmail.com \
--to=jj251510319013@gmail.com \
--cc=andreyknvl@gmail.com \
--cc=balbi@kernel.org \
--cc=gregkh@linuxfoundation.org \
--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
all inboxes | Powered by JetHome®