mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: f_uac2: fix endianness of 'struct cntrl_*_lay3'
@ 2018-07-02 21:46 Eugeniu Rosca
  2018-07-02 22:36 ` Ruslan Bilovol
  0 siblings, 1 reply; 3+ messages in thread
From: Eugeniu Rosca @ 2018-07-02 21:46 UTC (permalink / raw)
  To: Felipe Balbi, Felipe Balbi
  Cc: Greg Kroah-Hartman, Ruslan Bilovol, Vincent Pelletier, linux-usb,
	linux-kernel, Eugeniu Rosca, Eugeniu Rosca

The list [1] of commits doing endianness fixes in USB subsystem is long
due to below quote from USB spec Revision 2.0 from April 27, 2000:

------------
8.1 Byte/Bit Ordering

Multiple byte fields in standard descriptors, requests, and responses
are interpreted as and moved over the bus in little-endian order, i.e.
LSB to MSB.
------------

This commit belongs to the same family.

[1] Example of endianness fixes in USB subsystem:
commit 14e1d56cbea6 ("usb: gadget: f_uac2: endianness fixes.")
commit 42370b821168 ("usb: gadget: f_uac1: endianness fixes.")
commit 63afd5cc7877 ("USB: chaoskey: fix Alea quirk on big-endian hosts")
commit 74098c4ac782 ("usb: gadget: acm: fix endianness in notifications")
commit cdd7928df0d2 ("ACM gadget: fix endianness in notifications")
commit 323ece54e076 ("cdc-wdm: fix endianness bug in debug statements")
commit e102609f1072 ("usb: gadget: uvc: Fix endianness mismatches")
       list goes on

Fixes: 132fcb460839 ("usb: gadget: Add Audio Class 2.0 Driver")
Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
---
 drivers/usb/gadget/function/f_uac2.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/gadget/function/f_uac2.c b/drivers/usb/gadget/function/f_uac2.c
index d2dc1f00180b..540a0ce63ad4 100644
--- a/drivers/usb/gadget/function/f_uac2.c
+++ b/drivers/usb/gadget/function/f_uac2.c
@@ -438,14 +438,14 @@ static struct usb_descriptor_header *hs_audio_desc[] = {
 };
 
 struct cntrl_cur_lay3 {
-	__u32	dCUR;
+	__le32	dCUR;
 };
 
 struct cntrl_range_lay3 {
-	__u16	wNumSubRanges;
-	__u32	dMIN;
-	__u32	dMAX;
-	__u32	dRES;
+	__le16	wNumSubRanges;
+	__le32	dMIN;
+	__le32	dMAX;
+	__le32	dRES;
 } __packed;
 
 static void set_ep_max_packet_size(const struct f_uac2_opts *uac2_opts,
@@ -703,9 +703,9 @@ in_rq_cur(struct usb_function *fn, const struct usb_ctrlrequest *cr)
 		memset(&c, 0, sizeof(struct cntrl_cur_lay3));
 
 		if (entity_id == USB_IN_CLK_ID)
-			c.dCUR = p_srate;
+			c.dCUR = cpu_to_le32(p_srate);
 		else if (entity_id == USB_OUT_CLK_ID)
-			c.dCUR = c_srate;
+			c.dCUR = cpu_to_le32(c_srate);
 
 		value = min_t(unsigned, w_length, sizeof c);
 		memcpy(req->buf, &c, value);
@@ -742,15 +742,15 @@ in_rq_range(struct usb_function *fn, const struct usb_ctrlrequest *cr)
 
 	if (control_selector == UAC2_CS_CONTROL_SAM_FREQ) {
 		if (entity_id == USB_IN_CLK_ID)
-			r.dMIN = p_srate;
+			r.dMIN = cpu_to_le32(p_srate);
 		else if (entity_id == USB_OUT_CLK_ID)
-			r.dMIN = c_srate;
+			r.dMIN = cpu_to_le32(c_srate);
 		else
 			return -EOPNOTSUPP;
 
 		r.dMAX = r.dMIN;
 		r.dRES = 0;
-		r.wNumSubRanges = 1;
+		r.wNumSubRanges = cpu_to_le16(1);
 
 		value = min_t(unsigned, w_length, sizeof r);
 		memcpy(req->buf, &r, value);
-- 
2.18.0


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

* Re: [PATCH] usb: gadget: f_uac2: fix endianness of 'struct cntrl_*_lay3'
  2018-07-02 21:46 [PATCH] usb: gadget: f_uac2: fix endianness of 'struct cntrl_*_lay3' Eugeniu Rosca
@ 2018-07-02 22:36 ` Ruslan Bilovol
  2018-07-06 11:42   ` Eugeniu Rosca
  0 siblings, 1 reply; 3+ messages in thread
From: Ruslan Bilovol @ 2018-07-02 22:36 UTC (permalink / raw)
  To: Eugeniu Rosca
  Cc: Felipe Balbi, Felipe Balbi, Greg Kroah-Hartman,
	Vincent Pelletier, linux-usb, linux-kernel, Eugeniu Rosca,
	Eugeniu Rosca

On Tue, Jul 3, 2018 at 12:46 AM, Eugeniu Rosca <roscaeugeniu@gmail.com> wrote:
> The list [1] of commits doing endianness fixes in USB subsystem is long
> due to below quote from USB spec Revision 2.0 from April 27, 2000:
>
> ------------
> 8.1 Byte/Bit Ordering
>
> Multiple byte fields in standard descriptors, requests, and responses
> are interpreted as and moved over the bus in little-endian order, i.e.
> LSB to MSB.
> ------------
>
> This commit belongs to the same family.
>
> [1] Example of endianness fixes in USB subsystem:
> commit 14e1d56cbea6 ("usb: gadget: f_uac2: endianness fixes.")
> commit 42370b821168 ("usb: gadget: f_uac1: endianness fixes.")
> commit 63afd5cc7877 ("USB: chaoskey: fix Alea quirk on big-endian hosts")
> commit 74098c4ac782 ("usb: gadget: acm: fix endianness in notifications")
> commit cdd7928df0d2 ("ACM gadget: fix endianness in notifications")
> commit 323ece54e076 ("cdc-wdm: fix endianness bug in debug statements")
> commit e102609f1072 ("usb: gadget: uvc: Fix endianness mismatches")
>        list goes on
>
> Fixes: 132fcb460839 ("usb: gadget: Add Audio Class 2.0 Driver")
> Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>

Good catch!

Reviewed-by: Ruslan Bilovol <ruslan.bilovol@gmail.com>

> ---
>  drivers/usb/gadget/function/f_uac2.c | 20 ++++++++++----------
>  1 file changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/usb/gadget/function/f_uac2.c b/drivers/usb/gadget/function/f_uac2.c
> index d2dc1f00180b..540a0ce63ad4 100644
> --- a/drivers/usb/gadget/function/f_uac2.c
> +++ b/drivers/usb/gadget/function/f_uac2.c
> @@ -438,14 +438,14 @@ static struct usb_descriptor_header *hs_audio_desc[] = {
>  };
>
>  struct cntrl_cur_lay3 {
> -       __u32   dCUR;
> +       __le32  dCUR;
>  };
>
>  struct cntrl_range_lay3 {
> -       __u16   wNumSubRanges;
> -       __u32   dMIN;
> -       __u32   dMAX;
> -       __u32   dRES;
> +       __le16  wNumSubRanges;
> +       __le32  dMIN;
> +       __le32  dMAX;
> +       __le32  dRES;
>  } __packed;
>
>  static void set_ep_max_packet_size(const struct f_uac2_opts *uac2_opts,
> @@ -703,9 +703,9 @@ in_rq_cur(struct usb_function *fn, const struct usb_ctrlrequest *cr)
>                 memset(&c, 0, sizeof(struct cntrl_cur_lay3));
>
>                 if (entity_id == USB_IN_CLK_ID)
> -                       c.dCUR = p_srate;
> +                       c.dCUR = cpu_to_le32(p_srate);
>                 else if (entity_id == USB_OUT_CLK_ID)
> -                       c.dCUR = c_srate;
> +                       c.dCUR = cpu_to_le32(c_srate);
>
>                 value = min_t(unsigned, w_length, sizeof c);
>                 memcpy(req->buf, &c, value);
> @@ -742,15 +742,15 @@ in_rq_range(struct usb_function *fn, const struct usb_ctrlrequest *cr)
>
>         if (control_selector == UAC2_CS_CONTROL_SAM_FREQ) {
>                 if (entity_id == USB_IN_CLK_ID)
> -                       r.dMIN = p_srate;
> +                       r.dMIN = cpu_to_le32(p_srate);
>                 else if (entity_id == USB_OUT_CLK_ID)
> -                       r.dMIN = c_srate;
> +                       r.dMIN = cpu_to_le32(c_srate);
>                 else
>                         return -EOPNOTSUPP;
>
>                 r.dMAX = r.dMIN;
>                 r.dRES = 0;
> -               r.wNumSubRanges = 1;
> +               r.wNumSubRanges = cpu_to_le16(1);
>
>                 value = min_t(unsigned, w_length, sizeof r);
>                 memcpy(req->buf, &r, value);
> --
> 2.18.0
>

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

* Re: [PATCH] usb: gadget: f_uac2: fix endianness of 'struct cntrl_*_lay3'
  2018-07-02 22:36 ` Ruslan Bilovol
@ 2018-07-06 11:42   ` Eugeniu Rosca
  0 siblings, 0 replies; 3+ messages in thread
From: Eugeniu Rosca @ 2018-07-06 11:42 UTC (permalink / raw)
  To: Ruslan Bilovol
  Cc: Eugeniu Rosca, Felipe Balbi, Felipe Balbi, Greg Kroah-Hartman,
	Vincent Pelletier, linux-usb, linux-kernel, Eugeniu Rosca

Hello Ruslan,

On Tue, Jul 03, 2018 at 01:36:17AM +0300, Ruslan Bilovol wrote:
> On Tue, Jul 3, 2018 at 12:46 AM, Eugeniu Rosca <roscaeugeniu@gmail.com> wrote:
> > The list [1] of commits doing endianness fixes in USB subsystem is long
> > due to below quote from USB spec Revision 2.0 from April 27, 2000:
> >
> > ------------
> > 8.1 Byte/Bit Ordering
> >
> > Multiple byte fields in standard descriptors, requests, and responses
> > are interpreted as and moved over the bus in little-endian order, i.e.
> > LSB to MSB.
> > ------------
> >
> > This commit belongs to the same family.
> >
> > [1] Example of endianness fixes in USB subsystem:
> > commit 14e1d56cbea6 ("usb: gadget: f_uac2: endianness fixes.")
> > commit 42370b821168 ("usb: gadget: f_uac1: endianness fixes.")
> > commit 63afd5cc7877 ("USB: chaoskey: fix Alea quirk on big-endian hosts")
> > commit 74098c4ac782 ("usb: gadget: acm: fix endianness in notifications")
> > commit cdd7928df0d2 ("ACM gadget: fix endianness in notifications")
> > commit 323ece54e076 ("cdc-wdm: fix endianness bug in debug statements")
> > commit e102609f1072 ("usb: gadget: uvc: Fix endianness mismatches")
> >        list goes on
> >
> > Fixes: 132fcb460839 ("usb: gadget: Add Audio Class 2.0 Driver")
> > Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
> 
> Good catch!
> 
> Reviewed-by: Ruslan Bilovol <ruslan.bilovol@gmail.com>

Thanks for the review. FWIW, I've accidentally noticed post-push that
a similar fix has been incorporated by you in the UAC3 implementation
from https://lkml.org/lkml/2017/11/6/1514 ("[PATCH 1/1] usb: gadget: add
USB Audio Device Class 3.0 gadget support").

Best regards,
Eugeniu.

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

end of thread, other threads:[~2018-07-06 11:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-02 21:46 [PATCH] usb: gadget: f_uac2: fix endianness of 'struct cntrl_*_lay3' Eugeniu Rosca
2018-07-02 22:36 ` Ruslan Bilovol
2018-07-06 11:42   ` Eugeniu Rosca

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®