Skip to content

Commit 14e1d56

Browse files
rbilovolFelipe Balbi
authored andcommitted
usb: gadget: f_uac2: endianness fixes.
As per USB spec, multiple-bytes fields are stored in little-endian order. Use CPU<->LE helpers for such fields. Signed-off-by: Ruslan Bilovol <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
1 parent 42370b8 commit 14e1d56

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

drivers/usb/gadget/function/f_uac2.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ static struct uac2_input_terminal_descriptor usb_out_it_desc = {
168168
.bAssocTerminal = 0,
169169
.bCSourceID = USB_OUT_CLK_ID,
170170
.iChannelNames = 0,
171-
.bmControls = (CONTROL_RDWR << COPY_CTRL),
171+
.bmControls = cpu_to_le16(CONTROL_RDWR << COPY_CTRL),
172172
};
173173

174174
/* Input Terminal for I/O-In */
@@ -182,7 +182,7 @@ static struct uac2_input_terminal_descriptor io_in_it_desc = {
182182
.bAssocTerminal = 0,
183183
.bCSourceID = USB_IN_CLK_ID,
184184
.iChannelNames = 0,
185-
.bmControls = (CONTROL_RDWR << COPY_CTRL),
185+
.bmControls = cpu_to_le16(CONTROL_RDWR << COPY_CTRL),
186186
};
187187

188188
/* Ouput Terminal for USB_IN */
@@ -196,7 +196,7 @@ static struct uac2_output_terminal_descriptor usb_in_ot_desc = {
196196
.bAssocTerminal = 0,
197197
.bSourceID = IO_IN_IT_ID,
198198
.bCSourceID = USB_IN_CLK_ID,
199-
.bmControls = (CONTROL_RDWR << COPY_CTRL),
199+
.bmControls = cpu_to_le16(CONTROL_RDWR << COPY_CTRL),
200200
};
201201

202202
/* Ouput Terminal for I/O-Out */
@@ -210,7 +210,7 @@ static struct uac2_output_terminal_descriptor io_out_ot_desc = {
210210
.bAssocTerminal = 0,
211211
.bSourceID = USB_OUT_IT_ID,
212212
.bCSourceID = USB_OUT_CLK_ID,
213-
.bmControls = (CONTROL_RDWR << COPY_CTRL),
213+
.bmControls = cpu_to_le16(CONTROL_RDWR << COPY_CTRL),
214214
};
215215

216216
static struct uac2_ac_header_descriptor ac_hdr_desc = {
@@ -220,9 +220,10 @@ static struct uac2_ac_header_descriptor ac_hdr_desc = {
220220
.bDescriptorSubtype = UAC_MS_HEADER,
221221
.bcdADC = cpu_to_le16(0x200),
222222
.bCategory = UAC2_FUNCTION_IO_BOX,
223-
.wTotalLength = sizeof in_clk_src_desc + sizeof out_clk_src_desc
224-
+ sizeof usb_out_it_desc + sizeof io_in_it_desc
225-
+ sizeof usb_in_ot_desc + sizeof io_out_ot_desc,
223+
.wTotalLength = cpu_to_le16(sizeof in_clk_src_desc
224+
+ sizeof out_clk_src_desc + sizeof usb_out_it_desc
225+
+ sizeof io_in_it_desc + sizeof usb_in_ot_desc
226+
+ sizeof io_out_ot_desc),
226227
.bmControls = 0,
227228
};
228229

@@ -569,10 +570,12 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
569570
return ret;
570571
}
571572

572-
agdev->in_ep_maxpsize = max(fs_epin_desc.wMaxPacketSize,
573-
hs_epin_desc.wMaxPacketSize);
574-
agdev->out_ep_maxpsize = max(fs_epout_desc.wMaxPacketSize,
575-
hs_epout_desc.wMaxPacketSize);
573+
agdev->in_ep_maxpsize = max_t(u16,
574+
le16_to_cpu(fs_epin_desc.wMaxPacketSize),
575+
le16_to_cpu(hs_epin_desc.wMaxPacketSize));
576+
agdev->out_ep_maxpsize = max_t(u16,
577+
le16_to_cpu(fs_epout_desc.wMaxPacketSize),
578+
le16_to_cpu(hs_epout_desc.wMaxPacketSize));
576579

577580
hs_epout_desc.bEndpointAddress = fs_epout_desc.bEndpointAddress;
578581
hs_epin_desc.bEndpointAddress = fs_epin_desc.bEndpointAddress;

0 commit comments

Comments
 (0)