From: Salah Triki salah.triki@gmail.com
[ Upstream commit 63a9a727d373fa5b8ce509eef50dbc45e0f745b9 ]
Add usb_free_urb() in the error path to prevent memory leak.
Signed-off-by: Salah Triki salah.triki@gmail.com Link: https://patch.msgid.link/aA3_maPlEJzO7wrL@pc [fix subject] Signed-off-by: Johannes Berg johannes.berg@intel.com Signed-off-by: Sasha Levin sashal@kernel.org ---
**YES** This commit should be backported to stable kernel trees. Here's my extensive analysis: ## Code Analysis The commit fixes a clear memory leak in the `plfxlc_usb_wreq_async()` function in the pureLiFi wireless driver. Specifically: **The Bug:** - The function calls `usb_alloc_urb(0, GFP_ATOMIC)` to allocate a USB URB (USB Request Block) - If `usb_submit_urb()` fails, the function returns the error code but never frees the allocated URB - This creates a memory leak every time USB submission fails **The Fix:** The fix adds a simple but crucial cleanup path: ```c r = usb_submit_urb(urb, GFP_ATOMIC); -if (r) +if (r) { + usb_free_urb(urb); dev_err(&udev->dev, "Async write submit failed (%d)\n", r); +} ``` ## Timeline and Impact From examining the git history: 1. **Bug Introduction:** The bug was introduced in commit `68d57a07bfe5` when the driver was first added 2. **Bug Duration:** This memory leak has existed since the driver's introduction 3. **Impact:** Every failed USB submission would leak memory, potentially causing system instability over time ## Comparison with Similar Commits This commit matches the pattern of all 5 similar commits marked as "Backport Status: YES": 1. **Similar Commit #2** - Also fixes missing allocation failure check in the same function (`plfxlc_usb_wreq_async`) 2. **Similar Commit #1** - Fixes memory leak in the same driver (`__lf_x_usb_enable_rx`) 3. **Similar Commits #3-5** - All fix memory leaks in wireless drivers with small, contained changes ## Backport Criteria Met ✅ **Fixes important bug:** Memory leaks can cause system instability ✅ **Small and contained:** Only adds 2 lines of code in error path ✅ **No architectural changes:** Simple cleanup fix ✅ **Minimal regression risk:** Standard USB cleanup pattern ✅ **Clear scope:** Limited to specific function in wireless driver ✅ **Follows stable rules:** Important bugfix with minimal impact ## Additional Considerations - The fix follows standard kernel patterns for USB URB cleanup - The same driver has had multiple similar memory leak fixes (commit `895b3b06efc2`) - The change is identical in nature to Similar Commit #2, which was also in this exact function and marked YES for backporting - No side effects beyond fixing the memory leak - The function is called from transmit path, so failures could be relatively common under stress This is a textbook example of a stable tree candidate: a clear, important bug fix with minimal code changes and no risk of regression.
drivers/net/wireless/purelifi/plfxlc/usb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/net/wireless/purelifi/plfxlc/usb.c b/drivers/net/wireless/purelifi/plfxlc/usb.c index 56d1139ba8bcc..7e7bfa532ed25 100644 --- a/drivers/net/wireless/purelifi/plfxlc/usb.c +++ b/drivers/net/wireless/purelifi/plfxlc/usb.c @@ -503,8 +503,10 @@ int plfxlc_usb_wreq_async(struct plfxlc_usb *usb, const u8 *buffer, (void *)buffer, buffer_len, complete_fn, context);
r = usb_submit_urb(urb, GFP_ATOMIC); - if (r) + if (r) { + usb_free_urb(urb); dev_err(&udev->dev, "Async write submit failed (%d)\n", r); + }
return r; }