Skip to content

Commit 2bb6b10

Browse files
keesgregkh
authored andcommitted
usb: gadget: Use u16 types for 16-bit fields
Since the beginning of time, struct usb_ep::maxpacket was a bitfield, and when new 16-bit members were added, the convention was followed: 1da177e (Linus Torvalds 2005-04-16 236) unsigned maxpacket:16; e117e74 (Robert Baldyga 2013-12-13 237) unsigned maxpacket_limit:16; a59d6b9 (Tatyana Brokhman 2011-06-28 238) unsigned max_streams:16; However, there is no need for this as a simple u16 can be used instead, simplifying the struct and the resulting compiler binary output. Switch to u16 for all three, and rearrange struct slightly to minimize holes. No change in the final size of the struct results; the 2 byte gap is just moved to the end, as seen with pahole: - /* XXX 2 bytes hole, try to pack */ ... /* size: 72, cachelines: 2, members: 15 */ ... + /* padding: 2 */ Changing this simplifies future introspection[1] of maxpacket's type during allocations: drivers/usb/gadget/function/f_tcm.c:330:24: error: 'typeof' applied to a bit-field 330 | fu->cmd.buf = kmalloc(fu->ep_out->maxpacket, GFP_KERNEL); Link: https://lore.kernel.org/all/[email protected] [1] Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 3eb27d3 commit 2bb6b10

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

include/linux/usb/gadget.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,18 +229,18 @@ struct usb_ep {
229229

230230
const char *name;
231231
const struct usb_ep_ops *ops;
232+
const struct usb_endpoint_descriptor *desc;
233+
const struct usb_ss_ep_comp_descriptor *comp_desc;
232234
struct list_head ep_list;
233235
struct usb_ep_caps caps;
234236
bool claimed;
235237
bool enabled;
236-
unsigned maxpacket:16;
237-
unsigned maxpacket_limit:16;
238-
unsigned max_streams:16;
239238
unsigned mult:2;
240239
unsigned maxburst:5;
241240
u8 address;
242-
const struct usb_endpoint_descriptor *desc;
243-
const struct usb_ss_ep_comp_descriptor *comp_desc;
241+
u16 maxpacket;
242+
u16 maxpacket_limit;
243+
u16 max_streams;
244244
};
245245

246246
/*-------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)