* [v2] usb: musb: gadget: Fix big-endian arch issue
@ 2018-08-03 9:03 Alexey Spirkov
0 siblings, 0 replies; 4+ messages in thread
From: Alexey Spirkov @ 2018-08-03 9:03 UTC (permalink / raw)
To: Bin Liu, Greg Kroah-Hartman, linux-usb@vger.kernel.org; +Cc: andrew@ncrmnt.org
Existing code is not applicable to big-endian machines
ctrlrequest fields received in USB endian - i.e. in little-endian
and should be converted to cpu endianness before usage.
Signed-off-by: Alexey Spirkov <alexeis@astrosoft.ru>
---
drivers/usb/musb/musb_gadget_ep0.c | 29 ++++++++++++++---------------
1 file changed, 14 insertions(+), 15 deletions(-)
--
2.9.5
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/drivers/usb/musb/musb_gadget_ep0.c b/drivers/usb/musb/musb_gadget_ep0.c
index 91a5027..90abacb 100644
--- a/drivers/usb/musb/musb_gadget_ep0.c
+++ b/drivers/usb/musb/musb_gadget_ep0.c
@@ -82,7 +82,7 @@ static int service_tx_status_request(
u16 tmp;
void __iomem *regs;
- epnum = (u8) ctrlrequest->wIndex;
+ epnum = (u8) le16_to_cpu(ctrlrequest->wIndex);
if (!epnum) {
result[0] = 0;
break;
@@ -209,6 +209,8 @@ __acquires(musb->lock)
int handled = -EINVAL;
void __iomem *mbase = musb->mregs;
const u8 recip = ctrlrequest->bRequestType & USB_RECIP_MASK;
+ u16 reqval = le16_to_cpu(ctrlrequest->wValue);
+ u16 reqidx = le16_to_cpu(ctrlrequest->wIndex);
/* the gadget driver handles everything except what we MUST handle */
if ((ctrlrequest->bRequestType & USB_TYPE_MASK)
@@ -217,15 +219,14 @@ __acquires(musb->lock)
case USB_REQ_SET_ADDRESS:
/* change it after the status stage */
musb->set_address = true;
- musb->address = (u8) (ctrlrequest->wValue & 0x7f);
+ musb->address = (u8) (reqval & 0x7f);
handled = 1;
break;
case USB_REQ_CLEAR_FEATURE:
switch (recip) {
case USB_RECIP_DEVICE:
- if (ctrlrequest->wValue
- != USB_DEVICE_REMOTE_WAKEUP)
+ if (reqval != USB_DEVICE_REMOTE_WAKEUP)
break;
musb->may_wakeup = 0;
handled = 1;
@@ -233,8 +234,7 @@ __acquires(musb->lock)
case USB_RECIP_INTERFACE:
break;
case USB_RECIP_ENDPOINT:{
- const u8 epnum =
- ctrlrequest->wIndex & 0x0f;
+ const u8 epnum = reqidx & 0x0f;
struct musb_ep *musb_ep;
struct musb_hw_ep *ep;
struct musb_request *request;
@@ -243,12 +243,12 @@ __acquires(musb->lock)
u16 csr;
if (epnum == 0 || epnum >= MUSB_C_NUM_EPS ||
- ctrlrequest->wValue != USB_ENDPOINT_HALT)
+ reqval != USB_ENDPOINT_HALT)
break;
ep = musb->endpoints + epnum;
regs = ep->regs;
- is_in = ctrlrequest->wIndex & USB_DIR_IN;
+ is_in = reqidx & USB_DIR_IN;
if (is_in)
musb_ep = &ep->ep_in;
else
@@ -300,17 +300,17 @@ __acquires(musb->lock)
switch (recip) {
case USB_RECIP_DEVICE:
handled = 1;
- switch (ctrlrequest->wValue) {
+ switch (reqval) {
case USB_DEVICE_REMOTE_WAKEUP:
musb->may_wakeup = 1;
break;
case USB_DEVICE_TEST_MODE:
if (musb->g.speed != USB_SPEED_HIGH)
goto stall;
- if (ctrlrequest->wIndex & 0xff)
+ if (reqidx & 0xff)
goto stall;
- switch (ctrlrequest->wIndex >> 8) {
+ switch (reqidx >> 8) {
case 1:
pr_debug("TEST_J\n");
/* TEST_J */
@@ -398,8 +398,7 @@ __acquires(musb->lock)
break;
case USB_RECIP_ENDPOINT:{
- const u8 epnum =
- ctrlrequest->wIndex & 0x0f;
+ const u8 epnum = reqidx & 0x0f;
struct musb_ep *musb_ep;
struct musb_hw_ep *ep;
void __iomem *regs;
@@ -407,12 +406,12 @@ __acquires(musb->lock)
u16 csr;
if (epnum == 0 || epnum >= MUSB_C_NUM_EPS ||
- ctrlrequest->wValue != USB_ENDPOINT_HALT)
+ reqval != USB_ENDPOINT_HALT)
break;
ep = musb->endpoints + epnum;
regs = ep->regs;
- is_in = ctrlrequest->wIndex & USB_DIR_IN;
+ is_in = reqidx & USB_DIR_IN;
if (is_in)
musb_ep = &ep->ep_in;
else
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [v2] usb: musb: gadget: Fix big-endian arch issue
@ 2018-08-03 9:16 Andy Shevchenko
0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2018-08-03 9:16 UTC (permalink / raw)
To: Alexey Spirkov
Cc: Bin Liu, Greg Kroah-Hartman, linux-usb@vger.kernel.org,
andrew@ncrmnt.org
On Fri, Aug 3, 2018 at 12:03 PM, Alexey Spirkov <AlexeiS@astrosoft.ru> wrote:
> Existing code is not applicable to big-endian machines
> ctrlrequest fields received in USB endian - i.e. in little-endian
> and should be converted to cpu endianness before usage.
> - epnum = (u8) ctrlrequest->wIndex;
> + epnum = (u8) le16_to_cpu(ctrlrequest->wIndex);
> + u16 reqval = le16_to_cpu(ctrlrequest->wValue);
> + u16 reqidx = le16_to_cpu(ctrlrequest->wIndex);
I'm wondering, if you run make with C=1 CF=-D__CHECK_ENDIAN__ before
and after your change.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [v2] usb: musb: gadget: Fix big-endian arch issue
@ 2018-08-03 9:41 Alexey Spirkov
0 siblings, 0 replies; 4+ messages in thread
From: Alexey Spirkov @ 2018-08-03 9:41 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Bin Liu, Greg Kroah-Hartman, linux-usb@vger.kernel.org,
andrew@ncrmnt.org
Hi Andy,
Before my change:
CHECK drivers/usb/musb/musb_gadget_ep0.c
drivers/usb/musb/musb_gadget_ep0.c:85:26: warning: cast from restricted __le16
drivers/usb/musb/musb_gadget_ep0.c:220:58: warning: restricted __le16 degrades to integer
drivers/usb/musb/musb_gadget_ep0.c:227:48: warning: restricted __le16 degrades to integer
drivers/usb/musb/musb_gadget_ep0.c:237:52: warning: restricted __le16 degrades to integer
drivers/usb/musb/musb_gadget_ep0.c:251:52: warning: restricted __le16 degrades to integer
drivers/usb/musb/musb_gadget_ep0.c:310:56: warning: restricted __le16 degrades to integer
drivers/usb/musb/musb_gadget_ep0.c:313:60: warning: restricted __le16 degrades to integer
drivers/usb/musb/musb_gadget_ep0.c:303:52: warning: restricted __le16 degrades to integer
drivers/usb/musb/musb_gadget_ep0.c:303:52: warning: restricted __le16 degrades to integer
drivers/usb/musb/musb_gadget_ep0.c:303:52: warning: restricted __le16 degrades to integer
drivers/usb/musb/musb_gadget_ep0.c:303:52: warning: restricted __le16 degrades to integer
drivers/usb/musb/musb_gadget_ep0.c:303:52: warning: restricted __le16 degrades to integer
drivers/usb/musb/musb_gadget_ep0.c:303:52: warning: restricted __le16 degrades to integer
drivers/usb/musb/musb_gadget_ep0.c:402:52: warning: restricted __le16 degrades to integer
drivers/usb/musb/musb_gadget_ep0.c:415:52: warning: restricted __le16 degrades to integer
drivers/usb/musb/musb_gadget_ep0.c:540:22: warning: expression using sizeof(void)
After my change:
CHECK drivers/usb/musb/musb_gadget_ep0.c
drivers/usb/musb/musb_gadget_ep0.c:539:22: warning: expression using sizeof(void)
PS: Thanks for hint about endian issues check!
Best regards,
Alexey Spirkov
-----Original Message-----
From: Andy Shevchenko <andy.shevchenko@gmail.com>
Sent: Friday, August 3, 2018 12:17 PM
To: Alexey Spirkov <AlexeiS@astrosoft.ru>
Cc: Bin Liu <b-liu@ti.com>; Greg Kroah-Hartman <gregkh@linuxfoundation.org>; linux-usb@vger.kernel.org; andrew@ncrmnt.org
Subject: Re: [PATCH v2] usb: musb: gadget: Fix big-endian arch issue
On Fri, Aug 3, 2018 at 12:03 PM, Alexey Spirkov <AlexeiS@astrosoft.ru> wrote:
> Existing code is not applicable to big-endian machines ctrlrequest
> fields received in USB endian - i.e. in little-endian and should be
> converted to cpu endianness before usage.
> - epnum = (u8) ctrlrequest->wIndex;
> + epnum = (u8) le16_to_cpu(ctrlrequest->wIndex);
> + u16 reqval = le16_to_cpu(ctrlrequest->wValue);
> + u16 reqidx = le16_to_cpu(ctrlrequest->wIndex);
I'm wondering, if you run make with C=1 CF=-D__CHECK_ENDIAN__ before and after your change.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
* [v2] usb: musb: gadget: Fix big-endian arch issue
@ 2018-08-27 15:19 Bin Liu
0 siblings, 0 replies; 4+ messages in thread
From: Bin Liu @ 2018-08-27 15:19 UTC (permalink / raw)
To: Alexey Spirkov
Cc: Greg Kroah-Hartman, linux-usb@vger.kernel.org, andrew@ncrmnt.org
Hi,
On Fri, Aug 03, 2018 at 09:03:36AM +0000, Alexey Spirkov wrote:
> Existing code is not applicable to big-endian machines
> ctrlrequest fields received in USB endian - i.e. in little-endian
> and should be converted to cpu endianness before usage.
>
> Signed-off-by: Alexey Spirkov <alexeis@astrosoft.ru>
> ---
> drivers/usb/musb/musb_gadget_ep0.c | 29 ++++++++++++++---------------
> 1 file changed, 14 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/usb/musb/musb_gadget_ep0.c b/drivers/usb/musb/musb_gadget_ep0.c
> index 91a5027..90abacb 100644
> --- a/drivers/usb/musb/musb_gadget_ep0.c
> +++ b/drivers/usb/musb/musb_gadget_ep0.c
> @@ -82,7 +82,7 @@ static int service_tx_status_request(
> u16 tmp;
^^^^^^^^^^^^^
The patch cannot be applied. All the tabs are converted to whitespaces.
Regards,
-Bin.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-08-27 15:19 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-27 15:19 [v2] usb: musb: gadget: Fix big-endian arch issue Bin Liu
-- strict thread matches above, loose matches on Subject: below --
2018-08-03 9:41 Alexey Spirkov
2018-08-03 9:16 Andy Shevchenko
2018-08-03 9:03 Alexey Spirkov
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).