Skip to contentSkip to conversation

need for packed attribute

DISCUSSION Oliver Neukum 3 participants 3 messages Jan 6, 2006 – Jan 12, 2006

lore
Share & tools
lore
#0 lore raw

Hi,

is there any architecture for which packed is required in structures like this:

/* All standard descriptors have these 2 fields at the beginning */

struct usb_descriptor_header {
	__u8  bLength;
	__u8  bDescriptorType;
};

Regards
Oliver

#1 lore raw
Quoted 9 lines · Oliver Neukum

Hi,

is there any architecture for which packed is required in structures like this:

/* All standard descriptors have these 2 fields at the beginning */

struct usb_descriptor_header {
	__u8  bLength;
	__u8  bDescriptorType;
};

sizeof(struct usb_descriptor_header) will be 4 on ARM. If this concerns you, you need to pack the structure thusly:

struct usb_descriptor_header {
	__u8  bLength;
	__u8  bDescriptorType;
} __attribute__((packed));
Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core
#2 lore raw
Quoted 8 lines · Russell King
Quoted 5 lines

/* All standard descriptors have these 2 fields at the beginning */

struct usb_descriptor_header {
	__u8  bLength;
	__u8  bDescriptorType;
};

sizeof(struct usb_descriptor_header) will be 4 on ARM. If this concerns you, you need to pack the structure thusly:

Interesting. Perhaps we should add -Wpadded to CFLAGS in order to remind people, although that might take a fair bit of work to clean up existing structure definitions.

-ben

Signature · 2 lines
"You know, I've seen some crystals do some pretty trippy shit, man."
Don't Email: <[email protected]>.