-
Notifications
You must be signed in to change notification settings - Fork 2.1k
cpu/stm32/periph/usbdev: fix alignment issues #17154
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
Conversation
Make sure in `_usbdev_new_ep()` that `usbdev_ep_t::buf` is always aligned to 4 bytes. With this in mind, add intermediate casts to `uintptr_t` before casting `usbdev_ep_t::buf` to `uint32_t *` to silence `-Wcast-align`, as we now manually enforced correct alignment.
@@ -513,6 +523,7 @@ static usbdev_ep_t *_usbdev_new_ep(usbdev_t *dev, usb_ep_type_t type, | |||
ep->dev = dev; | |||
ep->len = buf_len; | |||
usbdev->occupied += buf_len; | |||
usbdev->occupied = _round_up_to_multiple_of_four(usbdev->occupied); |
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.
@bergzand an alternative here would be adding
assert((buf_len & 3) == 0);
Would that make more sense?
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'm fine with the current solution
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.
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.
Tested, ACK!
Contribution description
Make sure in
_usbdev_new_ep()
thatusbdev_ep_t::buf
is always aligned to 4 bytes. With this in mind, add intermediate casts touintptr_t
before castingusbdev_ep_t::buf
touint32_t *
to silence-Wcast-align
, as we now manually enforced correct alignment.Testing procedure
Everything should still work as before, but unaligned memory access should now prevented. (That is, no crash on architectures that do not support them.)
Issues/PRs references
Split out of #14955