-
Notifications
You must be signed in to change notification settings - Fork 7.4k
usb: fix unaligned access to interface and device descriptor #8495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,8 +68,8 @@ USBD_CLASS_DESCR_DEFINE(primary) struct usb_hid_config hid_cfg = { | |
|
||
static void usb_set_hid_report_size(u16_t report_desc_size) | ||
{ | ||
hid_cfg.if0_hid.subdesc[0].wDescriptorLength = | ||
sys_cpu_to_le16(report_desc_size); | ||
UNALIGNED_PUT(sys_cpu_to_le16(report_desc_size), | ||
&hid_cfg.if0_hid.subdesc[0].wDescriptorLength); | ||
} | ||
|
||
static struct hid_device_info { | ||
|
@@ -211,7 +211,8 @@ static struct usb_ep_cfg_data hid_ep_data[] = { | |
|
||
static void hid_interface_config(u8_t bInterfaceNumber) | ||
{ | ||
hid_cfg.if0.bInterfaceNumber = bInterfaceNumber; | ||
UNALIGNED_PUT(bInterfaceNumber, | ||
&hid_cfg.if0.bInterfaceNumber); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does not need alignment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might be right, I have no knowledge about how Intel S1000 supports unaligned accesses |
||
|
||
USBD_CFG_DATA_DEFINE(hid) struct usb_cfg_data hid_config = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -367,29 +367,42 @@ static void netusb_interface_config(u8_t bInterfaceNumber) | |
|
||
if (idx) { | ||
SYS_LOG_DBG("fixup string %d", idx); | ||
cdc_ecm_cfg.if0_netfun_ecm.iMACAddress = idx; | ||
UNALIGNED_PUT(idx, | ||
&cdc_ecm_cfg.if0_netfun_ecm.iMACAddress); | ||
} | ||
|
||
cdc_ecm_cfg.if0.bInterfaceNumber = bInterfaceNumber; | ||
cdc_ecm_cfg.if0_union.bControlInterface = bInterfaceNumber; | ||
cdc_ecm_cfg.if0_union.bSubordinateInterface0 = bInterfaceNumber + 1; | ||
cdc_ecm_cfg.if1_0.bInterfaceNumber = bInterfaceNumber + 1; | ||
cdc_ecm_cfg.if1_1.bInterfaceNumber = bInterfaceNumber + 1; | ||
UNALIGNED_PUT(bInterfaceNumber, | ||
&cdc_ecm_cfg.if0.bInterfaceNumber); | ||
UNALIGNED_PUT(bInterfaceNumber, | ||
&cdc_ecm_cfg.if0_union.bControlInterface); | ||
UNALIGNED_PUT((bInterfaceNumber + 1), | ||
&cdc_ecm_cfg.if0_union.bSubordinateInterface0); | ||
UNALIGNED_PUT((bInterfaceNumber + 1), | ||
&cdc_ecm_cfg.if1_0.bInterfaceNumber); | ||
UNALIGNED_PUT((bInterfaceNumber + 1), | ||
&cdc_ecm_cfg.if1_1.bInterfaceNumber); | ||
#ifdef CONFIG_USB_COMPOSITE_DEVICE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
cdc_ecm_cfg.iad.bFirstInterface = bInterfaceNumber; | ||
UNALIGNED_PUT(bInterfaceNumber, | ||
&cdc_ecm_cfg.iad.bFirstInterface); | ||
#endif | ||
#endif | ||
#ifdef CONFIG_USB_DEVICE_NETWORK_RNDIS | ||
rndis_cfg.if0.bInterfaceNumber = bInterfaceNumber; | ||
rndis_cfg.if0_union.bControlInterface = bInterfaceNumber; | ||
rndis_cfg.if0_union.bSubordinateInterface0 = bInterfaceNumber + 1; | ||
rndis_cfg.if1.bInterfaceNumber = bInterfaceNumber + 1; | ||
UNALIGNED_PUT(bInterfaceNumber, | ||
&rndis_cfg.if0.bInterfaceNumber); | ||
UNALIGNED_PUT(bInterfaceNumber, | ||
&rndis_cfg.if0_union.bControlInterface); | ||
UNALIGNED_PUT((bInterfaceNumber + 1), | ||
&rndis_cfg.if0_union.bSubordinateInterface0); | ||
UNALIGNED_PUT((bInterfaceNumber + 1), | ||
&rndis_cfg.if1.bInterfaceNumber); | ||
#ifdef CONFIG_USB_COMPOSITE_DEVICE | ||
rndis_cfg.iad.bFirstInterface = bInterfaceNumber; | ||
UNALIGNED_PUT(bInterfaceNumber, | ||
&rndis_cfg.iad.bFirstInterface); | ||
#endif | ||
#endif | ||
#ifdef CONFIG_USB_DEVICE_NETWORK_EEM | ||
cdc_eem_cfg.if0.bInterfaceNumber = bInterfaceNumber; | ||
UNALIGNED_PUT(bInterfaceNumber, | ||
&cdc_eem_cfg.if0.bInterfaceNumber); | ||
#endif | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder could we use here sys_put_le16()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see it now, should work, @SavinayDharmappa can you try it?