Skip to content

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

Closed

Conversation

jfischer-no
Copy link
Collaborator

Fix unaligned access to interface and device descriptor.

see #4661 (review)

Fix unaligned access to interface and device descriptor.

Signed-off-by: Johann Fischer <[email protected]>
@jfischer-no jfischer-no added the area: USB Universal Serial Bus label Jun 20, 2018
@jfischer-no jfischer-no requested a review from finikorg as a code owner June 20, 2018 16:34
@codecov-io
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (master@06f4daf). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #8495   +/-   ##
=========================================
  Coverage          ?   64.61%           
=========================================
  Files             ?      421           
  Lines             ?    40296           
  Branches          ?     6803           
=========================================
  Hits              ?    26037           
  Misses            ?    11126           
  Partials          ?     3133

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 06f4daf...54b46df. Read the comment docs.

@aurel32
Copy link
Collaborator

aurel32 commented Jun 20, 2018

Hmm the structures are correctly marked as __packed, and the access is not done through a pointer of a different type, so GCC should generate unaligned access code itself. That looks like a compiler bug to me, that said, the workaround is correct.

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);
}
Copy link
Collaborator

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()

Copy link
Collaborator Author

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?

@@ -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);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not need alignment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

finikorg added a commit to finikorg/zephyr that referenced this pull request Nov 23, 2018
Use sys_put_le16() for unaligned access, this is refactored work of
PR zephyrproject-rtos#8495
PR zephyrproject-rtos#11432

Signed-off-by: Andrei Emeltchenko <[email protected]>
andrewboie pushed a commit that referenced this pull request Nov 26, 2018
Use sys_put_le16() for unaligned access, this is refactored work of
PR #8495
PR #11432

Signed-off-by: Andrei Emeltchenko <[email protected]>
@jfischer-no
Copy link
Collaborator Author

revised in #11619

@jfischer-no jfischer-no deleted the fix-usb-unaligned branch November 28, 2018 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: USB Universal Serial Bus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants