Skip to contentSkip to conversation

usb: gadget: ncm: correct endianess conversion

PATCH In review Dmytro Milinevskyy 3 participants 12 messages Nov 1, 2012 – Nov 10, 2012 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: gadget: ncm: correct endianess conversion

Convert USB descriptor's fields to CPU byte order before using locally in USB NCM gadget driver. Tested on MIPS32 big-endian device.

---
 drivers/usb/gadget/f_ncm.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/usb/gadget/f_ncm.c +7 -4
index b651b52..a7cdd47 100644
@@ -102,7 +102,7 @@ static inline unsigned ncm_bitrate(struct usb_gadget *g)
 				 USB_CDC_NCM_NTB32_SUPPORTED)
  static struct usb_cdc_ncm_ntb_parameters ntb_parameters = {
-	.wLength = sizeof ntb_parameters,
+	.wLength = cpu_to_le16(sizeof(ntb_parameters)),
 	.bmNtbFormatsSupported = cpu_to_le16(FORMATS_SUPPORTED),
 	.dwNtbInMaxSize = cpu_to_le32(NTB_DEFAULT_IN_SIZE),
 	.wNdpInDivisor = cpu_to_le16(4),
@@ -869,15 +869,19 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port,
 	struct sk_buff	*skb2;
 	int		ncb_len = 0;
 	__le16		*tmp;
-	int		div = ntb_parameters.wNdpInDivisor;
-	int		rem = ntb_parameters.wNdpInPayloadRemainder;
+	int		div;
+	int		rem;
 	int		pad;
-	int		ndp_align = ntb_parameters.wNdpInAlignment;
+	int		ndp_align;
 	int		ndp_pad;
 	unsigned	max_size = ncm->port.fixed_in_len;
 	struct ndp_parser_opts *opts = ncm->parser_opts;
 	unsigned	crc_len = ncm->is_crc ? sizeof(uint32_t) : 0;
 +	div = le16_to_cpu(ntb_parameters.wNdpInDivisor);
+	rem = le16_to_cpu(ntb_parameters.wNdpInPayloadRemainder);
+	ndp_align = le16_to_cpu(ntb_parameters.wNdpInAlignment);
+
 	ncb_len += opts->nth_size;
 	ndp_pad = ALIGN(ncb_len, ndp_align) - ncb_len;
 	ncb_len += ndp_pad;
Signature · 1 line
1.8.0
#1 lore raw

Hello.

Quoted 13 lines · Dmytro Milinevskyy

Convert USB descriptor's fields to CPU byte order before using locally in USB NCM gadget driver.
Tested on MIPS32 big-endian device.

---
  drivers/usb/gadget/f_ncm.c | 12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)
drivers/usb/gadget/f_ncm.c +0 -0
index b651b52..a7cdd47 100644

[...]

Quoted 6 lines
drivers/usb/gadget/f_ncm.c +0 -2
@@ -869,15 +869,19 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port,
      struct sk_buff    *skb2;
      int        ncb_len = 0;
      __le16        *tmp;
-    int        div = ntb_parameters.wNdpInDivisor;
-    int        rem = ntb_parameters.wNdpInPayloadRemainder;

drivers/usb/gadget/f_ncm.c static struct sk_buff *ncm_wrap_ntb(struct gether *port, · line 880

Quoted 10 lines
drivers/usb/gadget/f_ncm.c +3 -1
+    int        div;
+    int        rem;
      int        pad;
-    int        ndp_align = ntb_parameters.wNdpInAlignment;
+    int        ndp_align;
      int        ndp_pad;
      unsigned    max_size = ncm->port.fixed_in_len;
      struct ndp_parser_opts *opts = ncm->parser_opts;
      unsigned    crc_len = ncm->is_crc ? sizeof(uint32_t) : 0;
  +    div = le16_to_cpu(ntb_parameters.wNdpInDivisor);

Probably corrupt patch -- there shouldn't be spaces before '+'.

WBR, Sergei

#2 lore raw

Hum, you are right. It's pain to send anything via thunderbird. Resending.

br,
-- dmytro

Quoted 51 lines · Sergei Shtylyov

Hello.

Quoted 17 lines · Dmytro Milinevskyy

Convert USB descriptor's fields to CPU byte order before using locally in USB
NCM gadget driver.
Tested on MIPS32 big-endian device.

---
  drivers/usb/gadget/f_ncm.c | 12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)
drivers/usb/gadget/f_ncm.c +0 -0
index b651b52..a7cdd47 100644

[...]

Quoted 11 lines
drivers/usb/gadget/f_ncm.c +2 -2
@@ -869,15 +869,19 @@ static struct sk_buff *ncm_wrap_ntb(struct gether
 *port,
 
      struct sk_buff    *skb2;
      int        ncb_len = 0;
      __le16        *tmp;
-    int        div = ntb_parameters.wNdpInDivisor;
-    int        rem = ntb_parameters.wNdpInPayloadRemainder;
+    int        div;
+    int        rem;

drivers/usb/gadget/f_ncm.c static struct sk_buff *ncm_wrap_ntb(struct gether · line 880

Quoted 10 lines
drivers/usb/gadget/f_ncm.c +1 -1
 
      int        pad;
-    int        ndp_align = ntb_parameters.wNdpInAlignment;
+    int        ndp_align;
      int        ndp_pad;
 
      unsigned    max_size = ncm->port.fixed_in_len;
      struct ndp_parser_opts *opts = ncm->parser_opts;
      unsigned    crc_len = ncm->is_crc ? sizeof(uint32_t) : 0;
  +    div = le16_to_cpu(ntb_parameters.wNdpInDivisor);

Probably corrupt patch -- there shouldn't be spaces before '+'.

WBR, Sergei

#3 lore raw

PATCH 1/1 usb: gadget: ncm: correct endianess conversion

In reply to Dmytro Milinevskyy

Convert USB descriptor's fields to CPU byte order before using locally in USB NCM gadget driver. Tested on MIPS32 big-endian device.

---
 drivers/usb/gadget/f_ncm.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/usb/gadget/f_ncm.c +8 -4
index b651b52..a7cdd47 100644
@@ -102,7 +102,7 @@ static inline unsigned ncm_bitrate(struct usb_gadget *g)
 				 USB_CDC_NCM_NTB32_SUPPORTED)
 
 static struct usb_cdc_ncm_ntb_parameters ntb_parameters = {
-	.wLength = sizeof ntb_parameters,
+	.wLength = cpu_to_le16(sizeof(ntb_parameters)),
 	.bmNtbFormatsSupported = cpu_to_le16(FORMATS_SUPPORTED),
 	.dwNtbInMaxSize = cpu_to_le32(NTB_DEFAULT_IN_SIZE),
 	.wNdpInDivisor = cpu_to_le16(4),
@@ -869,15 +869,19 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port,
 	struct sk_buff	*skb2;
 	int		ncb_len = 0;
 	__le16		*tmp;
-	int		div = ntb_parameters.wNdpInDivisor;
-	int		rem = ntb_parameters.wNdpInPayloadRemainder;
+	int		div;
+	int		rem;
 	int		pad;
-	int		ndp_align = ntb_parameters.wNdpInAlignment;
+	int		ndp_align;
 	int		ndp_pad;
 	unsigned	max_size = ncm->port.fixed_in_len;
 	struct ndp_parser_opts *opts = ncm->parser_opts;
 	unsigned	crc_len = ncm->is_crc ? sizeof(uint32_t) : 0;
 
+	div = le16_to_cpu(ntb_parameters.wNdpInDivisor);
+	rem = le16_to_cpu(ntb_parameters.wNdpInPayloadRemainder);
+	ndp_align = le16_to_cpu(ntb_parameters.wNdpInAlignment);
+
 	ncb_len += opts->nth_size;
 	ndp_pad = ALIGN(ncb_len, ndp_align) - ncb_len;
 	ncb_len += ndp_pad;
Signature · 1 line
1.8.0
#4 lore raw
Quoted 4 lines · Dmytro Milinevskyy

Convert USB descriptor's fields to CPU byte order before using locally in USB NCM gadget driver. Tested on MIPS32 big-endian device.

doesn't apply:

$ patch -p1 --dry-run < patch.diff
patching file drivers/usb/gadget/f_ncm.c
patch: **** malformed patch at line 31: @@ -869,15 +869,19 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port,

can you use git-send-email ?

Quoted 42 lines
---
 drivers/usb/gadget/f_ncm.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/usb/gadget/f_ncm.c +8 -4
index b651b52..a7cdd47 100644
@@ -102,7 +102,7 @@ static inline unsigned ncm_bitrate(struct usb_gadget *g)
 				 USB_CDC_NCM_NTB32_SUPPORTED)
 static struct usb_cdc_ncm_ntb_parameters ntb_parameters = {
-	.wLength = sizeof ntb_parameters,
+	.wLength = cpu_to_le16(sizeof(ntb_parameters)),
 	.bmNtbFormatsSupported = cpu_to_le16(FORMATS_SUPPORTED),
 	.dwNtbInMaxSize = cpu_to_le32(NTB_DEFAULT_IN_SIZE),
 	.wNdpInDivisor = cpu_to_le16(4),
@@ -869,15 +869,19 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port,
 	struct sk_buff	*skb2;
 	int		ncb_len = 0;
 	__le16		*tmp;
-	int		div = ntb_parameters.wNdpInDivisor;
-	int		rem = ntb_parameters.wNdpInPayloadRemainder;
+	int		div;
+	int		rem;
 	int		pad;
-	int		ndp_align = ntb_parameters.wNdpInAlignment;
+	int		ndp_align;
 	int		ndp_pad;
 	unsigned	max_size = ncm->port.fixed_in_len;
 	struct ndp_parser_opts *opts = ncm->parser_opts;
 	unsigned	crc_len = ncm->is_crc ? sizeof(uint32_t) : 0;
+	div = le16_to_cpu(ntb_parameters.wNdpInDivisor);
+	rem = le16_to_cpu(ntb_parameters.wNdpInPayloadRemainder);
+	ndp_align = le16_to_cpu(ntb_parameters.wNdpInAlignment);
+
 	ncb_len += opts->nth_size;
 	ndp_pad = ALIGN(ncb_len, ndp_align) - ncb_len;
 	ncb_len += ndp_pad;
Signature · 1 line
1.8.0
Signature · 1 line
balbi
#5 lore raw

Unfortunately I have some issues with git send-email. I've attached the patch itself ..

regards,
-- dmytro

Quoted 51 lines · Felipe Balbi
Quoted 4 lines · Dmytro Milinevskyy

Convert USB descriptor's fields to CPU byte order before using locally in USB NCM gadget driver. Tested on MIPS32 big-endian device.

doesn't apply:

$ patch -p1 --dry-run < patch.diff
patching file drivers/usb/gadget/f_ncm.c
patch: **** malformed patch at line 31: @@ -869,15 +869,19 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port,

can you use git-send-email ?

Quoted 37 lines
---
 drivers/usb/gadget/f_ncm.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/usb/gadget/f_ncm.c +8 -4
index b651b52..a7cdd47 100644
@@ -102,7 +102,7 @@ static inline unsigned ncm_bitrate(struct usb_gadget *g)
                               USB_CDC_NCM_NTB32_SUPPORTED)
 static struct usb_cdc_ncm_ntb_parameters ntb_parameters = {
-     .wLength = sizeof ntb_parameters,
+     .wLength = cpu_to_le16(sizeof(ntb_parameters)),
      .bmNtbFormatsSupported = cpu_to_le16(FORMATS_SUPPORTED),
      .dwNtbInMaxSize = cpu_to_le32(NTB_DEFAULT_IN_SIZE),
      .wNdpInDivisor = cpu_to_le16(4),
@@ -869,15 +869,19 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port,
      struct sk_buff  *skb2;
      int             ncb_len = 0;
      __le16          *tmp;
-     int             div = ntb_parameters.wNdpInDivisor;
-     int             rem = ntb_parameters.wNdpInPayloadRemainder;
+     int             div;
+     int             rem;
      int             pad;
-     int             ndp_align = ntb_parameters.wNdpInAlignment;
+     int             ndp_align;
      int             ndp_pad;
      unsigned        max_size = ncm->port.fixed_in_len;
      struct ndp_parser_opts *opts = ncm->parser_opts;
      unsigned        crc_len = ncm->is_crc ? sizeof(uint32_t) : 0;
+     div = le16_to_cpu(ntb_parameters.wNdpInDivisor);
+     rem = le16_to_cpu(ntb_parameters.wNdpInPayloadRemainder);
+     ndp_align = le16_to_cpu(ntb_parameters.wNdpInAlignment);
+
      ncb_len += opts->nth_size;
      ndp_pad = ALIGN(ncb_len, ndp_align) - ncb_len;
Quoted 8 lines
Quoted 5 lines
drivers/usb/gadget/f_ncm.c +0 -1
      ncb_len += ndp_pad;
--

1.8.0

--
balbi

From ac5b5aa01c070e5ca9001905732fa9ea96112787 Mon Sep 17 00:00:00 2001
From: Dmytro Milinevskyy <[email protected]>
Date: Fri, 5 Oct 2012 01:44:04 +0300
Subject: [PATCH] usb: gadget: ncm: correct endianess conversion

Convert USB descriptor's fields to CPU byte order before using locally in USB NCM gadget driver. Tested on MIPS32 big-endian device.

---
 drivers/usb/gadget/f_ncm.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/usb/gadget/f_ncm.c +8 -4
index b651b52..a7cdd47 100644
@@ -102,7 +102,7 @@ static inline unsigned ncm_bitrate(struct usb_gadget *g)
 				 USB_CDC_NCM_NTB32_SUPPORTED)
 
 static struct usb_cdc_ncm_ntb_parameters ntb_parameters = {
-	.wLength = sizeof ntb_parameters,
+	.wLength = cpu_to_le16(sizeof(ntb_parameters)),
 	.bmNtbFormatsSupported = cpu_to_le16(FORMATS_SUPPORTED),
 	.dwNtbInMaxSize = cpu_to_le32(NTB_DEFAULT_IN_SIZE),
 	.wNdpInDivisor = cpu_to_le16(4),
@@ -869,15 +869,19 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port,
 	struct sk_buff	*skb2;
 	int		ncb_len = 0;
 	__le16		*tmp;
-	int		div = ntb_parameters.wNdpInDivisor;
-	int		rem = ntb_parameters.wNdpInPayloadRemainder;
+	int		div;
+	int		rem;
 	int		pad;
-	int		ndp_align = ntb_parameters.wNdpInAlignment;
+	int		ndp_align;
 	int		ndp_pad;
 	unsigned	max_size = ncm->port.fixed_in_len;
 	struct ndp_parser_opts *opts = ncm->parser_opts;
 	unsigned	crc_len = ncm->is_crc ? sizeof(uint32_t) : 0;
 
+	div = le16_to_cpu(ntb_parameters.wNdpInDivisor);
+	rem = le16_to_cpu(ntb_parameters.wNdpInPayloadRemainder);
+	ndp_align = le16_to_cpu(ntb_parameters.wNdpInAlignment);
+
 	ncb_len += opts->nth_size;
 	ndp_pad = ALIGN(ncb_len, ndp_align) - ncb_len;
 	ncb_len += ndp_pad;
Signature · 1 line
1.8.0
#6 lore raw

Hi,

(please, never top-post)

Quoted 2 lines · Dmytro Milinevskyy

Unfortunately I have some issues with git send-email. I've attached the patch itself ..

I'll apply it like that this time, but try to figure out how to send patches properly. We have some very helpful hints on Documentation/email-clients.txt which are hugely underused ;-)

Signature · 1 line
balbi
#7 lore raw
Quoted 4 lines · Felipe Balbi

Hi,

(please, never top-post)

got it!

Quoted 8 lines · Dmytro Milinevskyy
Quoted 2 lines

Unfortunately I have some issues with git send-email. I've attached the patch itself ..

I'll apply it like that this time, but try to figure out how to send patches properly. We have some very helpful hints on Documentation/email-clients.txt which are hugely underused ;-)

well, I try to follow the rules as much as possible as long as tools work ... =)

regards,
-- dmytro

Quoted 2 lines

--
balbi

#8 lore raw

Hi,

Quoted 10 lines · Dmytro Milinevskyy
Quoted 8 lines · Dmytro Milinevskyy
Quoted 2 lines

Unfortunately I have some issues with git send-email. I've attached the patch itself ..

I'll apply it like that this time, but try to figure out how to send patches properly. We have some very helpful hints on Documentation/email-clients.txt which are hugely underused ;-)

well, I try to follow the rules as much as possible as long as tools work ... =)

git send-email has thousands of users and it works fine for them (including myself). Maybe you just misconfigured it ?!? ;-)

cheers

Signature · 1 line
balbi
#9 lore raw

Hi Felipe,

Quoted 11 lines · Felipe Balbi

Hi,

Quoted 8 lines · Dmytro Milinevskyy
Quoted 8 lines · Dmytro Milinevskyy
Quoted 2 lines

Unfortunately I have some issues with git send-email. I've attached the patch itself ..

I'll apply it like that this time, but try to figure out how to send patches properly. We have some very helpful hints on Documentation/email-clients.txt which are hugely underused ;-)

Quoted 6 lines
Quoted 2 lines

well, I try to follow the rules as much as possible as long as tools work ... =)

git send-email has thousands of users and it works fine for them (including myself). Maybe you just misconfigured it ?!? ;-)

No, I was using it in the past w/o any issue.
In fact initial versions of the patch were sent exactly with git-send-email.

However I lost my internet connection at home(some issues with ISP) and at work place network environment somehow blocks git-send-email(though thunderbird still can connect to the smtp server ..).

thanks,
-- dmytro

Quoted 4 lines

cheers

--
balbi

#10 lore raw

Hi,

Quoted 20 lines · Dmytro Milinevskyy

Hi Felipe,

Quoted 11 lines · Felipe Balbi

Hi,

Quoted 8 lines · Dmytro Milinevskyy
Quoted 8 lines · Dmytro Milinevskyy
Quoted 2 lines

Unfortunately I have some issues with git send-email. I've attached the patch itself ..

I'll apply it like that this time, but try to figure out how to send patches properly. We have some very helpful hints on Documentation/email-clients.txt which are hugely underused ;-)

Quoted 6 lines
Quoted 2 lines

well, I try to follow the rules as much as possible as long as tools work ... =)

git send-email has thousands of users and it works fine for them (including myself). Maybe you just misconfigured it ?!? ;-)

Quoted 7 lines

No, I was using it in the past w/o any issue.
In fact initial versions of the patch were sent exactly with git-send-email.

However I lost my internet connection at home(some issues with ISP) and at work place network environment somehow blocks git-send-email(though thunderbird still can connect to the smtp server ..).

I don't think smtp server can make that distinction. Except for the message-id, there's nothing there which would help smtp server to figure out you're using git send-email. On top of that, it would be just extra work to maintain rules to block a tool which is essentially just sending an email.

Make sure you're not missing some authentication with the mail server on your git send-email configuration.

my 2 cents.

Signature · 1 line
balbi
#11 lore raw

Hi,

Quoted 37 lines · Felipe Balbi

Hi,

Quoted 20 lines · Dmytro Milinevskyy

Hi Felipe,

Quoted 11 lines · Felipe Balbi

Hi,

Quoted 8 lines · Dmytro Milinevskyy
Quoted 8 lines · Dmytro Milinevskyy
Quoted 2 lines

Unfortunately I have some issues with git send-email. I've attached the patch itself ..

I'll apply it like that this time, but try to figure out how to send patches properly. We have some very helpful hints on Documentation/email-clients.txt which are hugely underused ;-)

Quoted 6 lines
Quoted 2 lines

well, I try to follow the rules as much as possible as long as tools work ... =)

git send-email has thousands of users and it works fine for them (including myself). Maybe you just misconfigured it ?!? ;-)

Quoted 7 lines

No, I was using it in the past w/o any issue.
In fact initial versions of the patch were sent exactly with git-send-email.

However I lost my internet connection at home(some issues with ISP) and at work place network environment somehow blocks git-send-email(though thunderbird still can connect to the smtp server ..).

I don't think smtp server can make that distinction. Except for the message-id, there's nothing there which would help smtp server to figure out you're using git send-email. On top of that, it would be just extra work to maintain rules to block a tool which is essentially just sending an email.

Quoted 4 lines

Make sure you're not missing some authentication with the mail server on your git send-email configuration.

my 2 cents.

Thanks a lot, I very appreciate your help.
I even tried to use same laptop with same version of git I used to send the patch for the first time but it didn't help. Likely there's a network configuration that is blocking git-send-email. I will try to figure it out with our system administrators.

cheers,
-- dmytro

Quoted 2 lines

--
balbi