Skip to content

Commit 575bd0b

Browse files
finikorgandrewboie
authored andcommitted
usb: Fix unaligned access
Use sys_put_le16() for unaligned access, this is refactored work of PR #8495 PR #11432 Signed-off-by: Andrei Emeltchenko <[email protected]>
1 parent 6c3aefa commit 575bd0b

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

subsys/usb/class/hid/core.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ static struct hid_device_info {
8989
const struct hid_ops *ops;
9090
} hid_device;
9191

92-
static void usb_set_hid_report_size(u16_t report_desc_size)
92+
static void usb_set_hid_report_size(u16_t size)
9393
{
94-
UNALIGNED_PUT(sys_cpu_to_le16(report_desc_size),
95-
&(hid_cfg.if0_hid.subdesc[0].wDescriptorLength));
94+
sys_put_le16(size,
95+
(u8_t *)&(hid_cfg.if0_hid.subdesc[0].wDescriptorLength));
9696
}
9797

9898
static void hid_status_cb(enum usb_dc_status_code status, const u8_t *param)

subsys/usb/usb_descriptor.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,8 @@ static int usb_fix_descriptor(struct usb_desc_header *head)
409409

410410
LOG_DBG("Now the wTotalLength is %d",
411411
(u8_t *)head - (u8_t *)cfg_descr);
412-
cfg_descr->wTotalLength =
413-
sys_cpu_to_le16((u8_t *)head -
414-
(u8_t *)cfg_descr);
412+
sys_put_le16((u8_t *)head - (u8_t *)cfg_descr,
413+
(u8_t *)&cfg_descr->wTotalLength);
415414
cfg_descr->bNumInterfaces = numof_ifaces;
416415
}
417416

0 commit comments

Comments
 (0)