Skip to contentSkip to conversation

soc: qcom: wcnss_ctrl: fix firmware leak on req allocation failure

PATCH In review Felix Gu 3 participants 4 messages Apr 17

Subsystems (2)
lore
Share & tools
lore

Felix Gu

author
#0 lore raw

PATCH 1/1 soc: qcom: wcnss_ctrl: fix firmware leak on req allocation failure

In wcnss_download_nv(), if kzalloc_flex() fails, the current code returns -ENOMEM directly and leaves the firmware reference unreleased.

Fixes 908061f0ad30 ("soc: qcom: wcnss: simplify allocation of req")
---
 drivers/soc/qcom/wcnss_ctrl.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/soc/qcom/wcnss_ctrl.c +7 -4
index ffb31a049d4a..f046d0248306 100644
@@ -221,8 +221,10 @@ static int wcnss_download_nv(struct wcnss_ctrl *wcnss, bool *expect_cbc)
 	left = fw->size;
 
 	req = kzalloc_flex(*req, fragment, NV_FRAGMENT_SIZE);
-	if (!req)
-		return -ENOMEM;
+	if (!req) {
+		ret = -ENOMEM;
+		goto release_fw;
+	}
 
 	req->frag_size = NV_FRAGMENT_SIZE;
 	req->hdr.type = WCNSS_DOWNLOAD_NV_REQ;
@@ -243,7 +245,7 @@ static int wcnss_download_nv(struct wcnss_ctrl *wcnss, bool *expect_cbc)
 		ret = rpmsg_send(wcnss->channel, req, req->hdr.len);
 		if (ret < 0) {
 			dev_err(dev, "failed to send smd packet\n");
-			goto release_fw;
+			goto free_req;
 		}
 
 		/* Increment for next fragment */
@@ -262,9 +264,10 @@ static int wcnss_download_nv(struct wcnss_ctrl *wcnss, bool *expect_cbc)
 		ret = 0;
 	}
 
+free_req:
+	kfree(req);
 release_fw:
 	release_firmware(fw);
-	kfree(req);
 
 	return ret;
 }

---
base-commit: 452c3b1ea875276105ac90ba474f72b4cd9b77a2
change-id: 20260417-wcnss_ctrl-43783099258e

Best regards,

Signature · 1 line
Felix Gu <[email protected]>
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Felix Gu

In wcnss_download_nv(), if kzalloc_flex() fails, the current code returns -ENOMEM directly and leaves the firmware reference unreleased.

Fixes 908061f0ad30 ("soc: qcom: wcnss: simplify allocation of req")
---
 drivers/soc/qcom/wcnss_ctrl.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
Quoted 1 line
Signature · 2 lines
With best wishes
Dmitry
#2 lore raw
Quoted 7 lines · Dmitry Baryshkov
Quoted 5 lines · Felix Gu

In wcnss_download_nv(), if kzalloc_flex() fails, the current code returns -ENOMEM directly and leaves the firmware reference unreleased.

Fixes 908061f0ad30 ("soc: qcom: wcnss: simplify allocation of req")

Same as
https://lore.kernel.org/linux-arm-msm/[email protected]/

Quoted 10 lines
Quoted 3 lines
---
 drivers/soc/qcom/wcnss_ctrl.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
Quoted 1 line

--
With best wishes
Dmitry

#3 lore raw
Quoted 11 lines · Rosen Penev
Quoted 7 lines · Dmitry Baryshkov
Quoted 5 lines · Felix Gu

In wcnss_download_nv(), if kzalloc_flex() fails, the current code returns -ENOMEM directly and leaves the firmware reference unreleased.

Fixes 908061f0ad30 ("soc: qcom: wcnss: simplify allocation of req")

Same as
https://lore.kernel.org/linux-arm-msm/[email protected]/

Indeed!

Quoted 10 lines
Quoted 10 lines
Quoted 3 lines
---
 drivers/soc/qcom/wcnss_ctrl.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
Quoted 1 line

--
With best wishes
Dmitry

Signature · 2 lines
With best wishes
Dmitry