On 7.1.2020 9.24, Sajja, Venkateswara Rao wrote:
Hi, This is SVR from AMD, I'm facing memory leak issue with in USB Host driver with the following patches, patch1: "https://www.yoctoproject.org/pipermail/linux-yocto/2016-June/005558.html", this patch is doing the "parse xhci protocol speed ID list for usb 3.1 usage" but memory leak is happening at, */rhub->psi = kcalloc(rhub->psi_count, sizeof(*rhub->psi), GFP_KERNEL);/* This is because of "xhci_add_in_port" is getting called from a loop, i.e, patch2: "rework xhci extended capability list parsing functions": https://www.yoctoproject.org/pipermail/linux-yocto/2016-June/005559.html" /*while (offset) { xhci_add_in_port(xhci, num_ports, base + offset, cap_count); if (xhci->num_usb2_ports + xhci->num_usb3_ports == num_ports) break; offset = xhci_find_next_ext_cap(base, offset, XHCI_EXT_CAPS_PROTOCOL); }*/ From the above loop "*xhci_add_in_port*"function is called more than once for USB 3.1. So the memory allocation for *psi (**/rhub->psi/**)* is happening more than once and /rhub->psi /is overridden without freeing the previously allocated memory. This is causing the memory leak. The following "[PATCH 1/6] xhci: Fix memory leak in xhci_add_in_port() <https://lore.kernel.org/linux-usb/20191211142007.8847-2-mathias.nyman@xxxxxxxxxxxxxxx/#r>"patch is not solving the memory leak issue, https://lore.kernel.org/linux-usb/20191211142007.8847-2-mathias.nyman@xxxxxxxxxxxxxxx/#r Could somebody suggest me the alternative patch to fix this memory leak issue.
Thanks, true, the original code falsely assumes there are only two xHCI supported Protocol Capabilities with psic entries in the list of extended capabilities, one for usb 2 ports and one for usb 3.x ports I'll look into this -Mathias