Skip to contentSkip to conversation

usb: gadget: ncm: correct endianess conversion

PATCH In review Dmytro Milinevskyy 2 participants 3 messages Oct 30, 2012 – Nov 1, 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, 6 insertions(+), 6 deletions(-)
drivers/usb/gadget/f_ncm.c +6 -6
index b651b52..0b9e2ad 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,15 @@ 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		pad;
-	int		ndp_align = ntb_parameters.wNdpInAlignment;
-	int		ndp_pad;
+	int		div, rem, pad, ndp_align, 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

Hi,

Quoted 21 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, 6 insertions(+), 6 deletions(-)
drivers/usb/gadget/f_ncm.c +1 -1
index b651b52..0b9e2ad 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),

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

Quoted 9 lines
drivers/usb/gadget/f_ncm.c +1 -5
@@ -869,15 +869,15 @@ 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		pad;
-	int		ndp_align = ntb_parameters.wNdpInAlignment;
-	int		ndp_pad;
+	int		div, rem, pad, ndp_align, ndp_pad;

I would not combine them in a single line. Keep them one per line.

cheers

Signature · 1 line
balbi
#2 lore raw

Hi Felipe,
resent with requested formatting changes.

cheers,
-- dmytro

Quoted 40 lines · Felipe Balbi

Hi,

Quoted 21 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, 6 insertions(+), 6 deletions(-)
drivers/usb/gadget/f_ncm.c +1 -1
index b651b52..0b9e2ad 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),

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

Quoted 9 lines
drivers/usb/gadget/f_ncm.c +1 -5
@@ -869,15 +869,15 @@ 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             pad;
-     int             ndp_align = ntb_parameters.wNdpInAlignment;
-     int             ndp_pad;
+     int             div, rem, pad, ndp_align, ndp_pad;

I would not combine them in a single line. Keep them one per line.

cheers

--
balbi