Skip to content
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

usb: device: fix unaligned memory access in Audio class #79491

Merged

Conversation

LuoZhongYao
Copy link
Contributor

Use UNALIGNED_*, sys_get_* to fix unaligned memory access issues
fix #78920

@@ -53,7 +53,7 @@ static void feature_update(const struct device *dev,
case USB_AUDIO_FU_MUTE_CONTROL:
break;
case USB_AUDIO_FU_VOLUME_CONTROL:
volume = *((int16_t *)(evt->val));
volume = UNALIGNED_GET((int16_t *)evt->val);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it work with clang and why not just memcpy(&volume, evt->val, sizeof(volume));?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My development environment is not convenient for testing clang (soc is a customized mips), but zephyr also uses UNALIGNED_GET in many places, and include/zephyr/toolchain/llvm.h includes include/zephyr/toolchain/gcc.h, so clang should also be able to use it. If you have any doubts about this, I can resubmit using memcpy

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like the typeof should work there too https://clang.llvm.org/docs/UsersManual.html

Copy link
Collaborator

@jfischer-no jfischer-no left a comment

Choose a reason for hiding this comment

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

@LuoZhongYao Please fix compliance issues, you commit title should be like: usb: device: fix unaligned memory access in Audio class

@LuoZhongYao LuoZhongYao changed the title USB:Audio: fix unaligned memory access usb: device: fix unaligned memory access in Audio class Oct 8, 2024
@LuoZhongYao LuoZhongYao force-pushed the fix_usb_audio_unaligned_access branch from 9bd8e37 to 8d75232 Compare October 8, 2024 09:55
Use UNALIGNED_*, sys_get_* to fix unaligned memory
access issues

Signed-off-by: ZhongYao Luo <[email protected]>
@kartben
Copy link
Collaborator

kartben commented Nov 26, 2024

@LuoZhongYao Please fix compliance issues, you commit title should be like: usb: device: fix unaligned memory access in Audio class

@jfischer-no this has been addressed - please revisit

@nashif nashif merged commit 188a42b into zephyrproject-rtos:main Nov 26, 2024
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Samples Samples area: USB Universal Serial Bus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

USB Audio: Unaligned address data access
6 participants