diff mbox series

slimbus: qcom-ctrl: fix possible memory leak in qcom_slim_probe()

Message ID 20221207083634.1759211-1-cuigaosheng1@huawei.com (mailing list archive)
State New, archived
Headers show
Series slimbus: qcom-ctrl: fix possible memory leak in qcom_slim_probe() | expand

Commit Message

cuigaosheng Dec. 7, 2022, 8:36 a.m. UTC
The kfree() should be called to free ctrl->wr_comp when something
fails, we should also free it in qcom_slim_remove(), otherwise
there will be a memory leak, so use devm_kcalloc instead of kcalloc
to fix it.

Fixes: ad7fcbc308b0 ("slimbus: qcom: Add Qualcomm Slimbus controller driver")
Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
---
 drivers/slimbus/qcom-ctrl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/slimbus/qcom-ctrl.c b/drivers/slimbus/qcom-ctrl.c
index 400b7b385a44..e4d92ce52c41 100644
--- a/drivers/slimbus/qcom-ctrl.c
+++ b/drivers/slimbus/qcom-ctrl.c
@@ -529,8 +529,8 @@  static int qcom_slim_probe(struct platform_device *pdev)
 	ctrl->tx.sl_sz = SLIM_MSGQ_BUF_LEN;
 	ctrl->rx.n = QCOM_RX_MSGS;
 	ctrl->rx.sl_sz = SLIM_MSGQ_BUF_LEN;
-	ctrl->wr_comp = kcalloc(QCOM_TX_MSGS, sizeof(struct completion *),
-				GFP_KERNEL);
+	ctrl->wr_comp = devm_kcalloc(&pdev->dev, QCOM_TX_MSGS, sizeof(struct completion *),
+				     GFP_KERNEL);
 	if (!ctrl->wr_comp)
 		return -ENOMEM;