Skip to content

Commit 9dc2924

Browse files
Krishna Kurapatigregkh
authored andcommitted
usb: gadget: ncm: Fix endianness of wMaxSegmentSize variable in ecm_desc
Recent commit [1] added support for changing max segment size of the NCM interface via configfs. But the value of segment size value stored in ncm_opts need to be converted to little endian before saving it in ecm_desc. Also while initialising the value of segment size in opts during instance allocation, the value ETH_FRAME_LEN needs to be assigned directly without any conversion as ETH_FRAME_LEN and the variable max_segment_size are native endian. The current implementaion modifies it into little endian thus breaking things for big endian targets. Fix endianness while assigning these variables. While at it, fix up some stray spaces in comments added in code. [1]: https://lore.kernel.org/all/[email protected]/ Fixes: 1900dae ("usb: gadget: ncm: Add support to update wMaxSegmentSize via configfs") Signed-off-by: Krishna Kurapati <[email protected]> Reviewed-by: Maciej Żenczykowski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 520b391 commit 9dc2924

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/usb/gadget/function/f_ncm.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ static inline struct f_ncm *func_to_ncm(struct usb_function *f)
105105

106106
/*
107107
* Although max mtu as dictated by u_ether is 15412 bytes, setting
108-
* max_segment_sizeto 15426 would not be efficient. If user chooses segment
109-
* size to be (>= 8192), then we can't aggregate more than one buffer in each
108+
* max_segment_size to 15426 would not be efficient. If user chooses segment
109+
* size to be (>= 8192), then we can't aggregate more than one buffer in each
110110
* NTB (assuming each packet coming from network layer is >= 8192 bytes) as ep
111111
* maxpacket limit is 16384. So let max_segment_size be limited to 8000 to allow
112112
* at least 2 packets to be aggregated reducing wastage of NTB buffer space
@@ -1489,7 +1489,7 @@ static int ncm_bind(struct usb_configuration *c, struct usb_function *f)
14891489
ncm_data_intf.bInterfaceNumber = status;
14901490
ncm_union_desc.bSlaveInterface0 = status;
14911491

1492-
ecm_desc.wMaxSegmentSize = ncm_opts->max_segment_size;
1492+
ecm_desc.wMaxSegmentSize = cpu_to_le16(ncm_opts->max_segment_size);
14931493

14941494
status = -ENODEV;
14951495

@@ -1685,7 +1685,7 @@ static struct usb_function_instance *ncm_alloc_inst(void)
16851685
kfree(opts);
16861686
return ERR_CAST(net);
16871687
}
1688-
opts->max_segment_size = cpu_to_le16(ETH_FRAME_LEN);
1688+
opts->max_segment_size = ETH_FRAME_LEN;
16891689
INIT_LIST_HEAD(&opts->ncm_os_desc.ext_prop);
16901690

16911691
descs[0] = &opts->ncm_os_desc;

0 commit comments

Comments
 (0)