-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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: endpoint buffer leak upon SET_CONFIGURATION, SET_INTERFACE #23178
Comments
Previously, endpoint configuration would reserve memory in the packet memory area which would never be reclaimed. After this patch, the leak still exists on SET_CONFIGURATION/SET_INTERFACE, but we will at least reclaim the memory upon reset, so disconnect/reconnect gets us back into a working state. Bug: zephyrproject-rtos#23178 Signed-off-by: Josh Gao <josh@jmgao.dev>
No need for |
Previously, endpoint configuration would reserve memory in the packet memory area which would never be reclaimed. After this patch, endpoints will reuse previously allocated memory when possible. We still leak memory when reconfiguration increases the max packet size for a given endpoint number, but this fixes the common case. Bug: zephyrproject-rtos#23178 Signed-off-by: Josh Gao <josh@jmgao.dev>
That's true of configuration right now, but interface alt setting seems to be supported today (and support for multiple configurations is something that probably needs be implemented at some point?) I switched my stm32 patch over to tracking the size of the buffer allocated and leaking/reallocating if the mps increases, which probably covers the common case? |
I dont think this is good approach as it will make an exception for those drivers which does not track the internal configurations. The case is st driver does not free the buffer which was previously allocated here. I see 2 solutions (st):
I think the 2nd option is not the greatest as it will impact all drivers with additional reset_eps() call.
To make it usefull we would first have to have multiple configuration support in the descriptors and we do not support that (and probably would never have ) so there is no need for that at all. |
nvm, I hadn't noticed You have already posted a pr for this. |
Disagree, that is disproportionate effort compared to the use case. |
Previously, endpoint configuration would reserve memory in the packet memory area which would never be reclaimed. After this patch, endpoints will reuse previously allocated memory when possible. We still leak memory when reconfiguration increases the max packet size for a given endpoint number, but this fixes the common case. Bug: #23178 Signed-off-by: Josh Gao <josh@jmgao.dev>
Previously, endpoint configuration would reserve memory in the packet memory area which would never be reclaimed. After this patch, endpoints will reuse previously allocated memory when possible. We still leak memory when reconfiguration increases the max packet size for a given endpoint number, but this fixes the common case. Bug: zephyrproject-rtos#23178 Signed-off-by: Josh Gao <josh@jmgao.dev>
@jmgao @jfischer-phytec-iot, issue is still open, but PR has been merged. |
Yes, let's close it. If there are any unresolved issue this can be reopened. |
Reopen as it still an issue on usb_dc_sam0 |
Also automatically enable the heap if the USB device is selected. Part of zephyrproject-rtos#23178 Signed-off-by: Michael Hope <mlhx@google.com>
Also automatically enable the heap if the USB device is selected. Part of #23178 Signed-off-by: Michael Hope <mlhx@google.com>
Also automatically enable the heap if the USB device is selected. Part of zephyrproject-rtos#23178 Signed-off-by: Michael Hope <mlhx@google.com>
Describe the bug
Some platforms don't use a real allocator to allocate endpoint packet buffers, and just bump a pointer into a buffer (stm32, sam0), which results in the buffer getting leaked every time an endpoint is configured as a result of SET_CONFIGURATION or SET_INTERFACE, which quickly leads to configuration failing. It looks like sam0 can be switched over to using a mempool pretty trivially, but stm32 has a dedicated region of memory for USB packets, which makes things harder. It seems to me that the simplest solution would be to add something along the lines of
usb_dc_reconfigure
to let the driver know it can throw away all of the endpoint buffers.To Reproduce
Steps to reproduce the behavior:
Build any USB sample,
pip3 install pyusb
and then run this python script:and you'll see logs that are something along the lines of the following (along with a broken USB device):
The text was updated successfully, but these errors were encountered: