Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

USB: add rationale on why usb descriptor structures have to be packed

Add argumentation in defense of using __attribute__((packed)) in USB
descriptors authored by Dave Brownell. Necessary as in some cases it
seems superfluous.

Signed-off-by: Inaky Perez-Gonzalez <inaky@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Inaky Perez-Gonzalez and committed by
Greg Kroah-Hartman
672027a3 822c7ef4

+18 -4
+18 -4
include/linux/usb/ch9.h
··· 1 1 /* 2 - * This file holds USB constants and structures that are needed for USB 3 - * device APIs. These are used by the USB device model, which is defined 4 - * in chapter 9 of the USB 2.0 specification. Linux has several APIs in C 5 - * that need these: 2 + * This file holds USB constants and structures that are needed for 3 + * USB device APIs. These are used by the USB device model, which is 4 + * defined in chapter 9 of the USB 2.0 specification and in the 5 + * Wireless USB 1.0 (spread around). Linux has several APIs in C that 6 + * need these: 6 7 * 7 8 * - the master/host side Linux-USB kernel driver API; 8 9 * - the "usbfs" user space API; and ··· 15 14 * 16 15 * There's also "Wireless USB", using low power short range radios for 17 16 * peripheral interconnection but otherwise building on the USB framework. 17 + * 18 + * Note all descriptors are declared '__attribute__((packed))' so that: 19 + * 20 + * [a] they never get padded, either internally (USB spec writers 21 + * probably handled that) or externally; 22 + * 23 + * [b] so that accessing bigger-than-a-bytes fields will never 24 + * generate bus errors on any platform, even when the location of 25 + * its descriptor inside a bundle isn't "naturally aligned", and 26 + * 27 + * [c] for consistency, removing all doubt even when it appears to 28 + * someone that the two other points are non-issues for that 29 + * particular descriptor type. 18 30 */ 19 31 20 32 #ifndef __LINUX_USB_CH9_H