[PATCH v3 2/2] staging: vchiq_arm: Utilize devm_kzalloc() for allocation

From: Umang Jain
Date: Mon Oct 14 2024 - 06:07:11 EST


The struct drv_mgmt 'mgmt' is currently allocated dynamically using
kzalloc(). Unfortunately, it is subjected to memory leaks in the error
handling paths of the probe() function.

To address this issue, use device resource management
helper devm_kzalloc(), to ensure cleanup after the allocation.

Cc: stable@xxxxxxxxxxxxxxx
Fixes: 1c9e16b73166 ("staging: vc04_services: vchiq_arm: Split driver static and runtime data")
Signed-off-by: Umang Jain <umang.jain@xxxxxxxxxxxxxxxx>
---
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
index 7ece82c361ee..8412be7183fc 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
@@ -1343,7 +1343,7 @@ static int vchiq_probe(struct platform_device *pdev)
return -ENOENT;
}

- mgmt = kzalloc(sizeof(*mgmt), GFP_KERNEL);
+ mgmt = devm_kzalloc(&pdev->dev, sizeof(*mgmt), GFP_KERNEL);
if (!mgmt)
return -ENOMEM;

@@ -1397,8 +1397,6 @@ static void vchiq_remove(struct platform_device *pdev)

arm_state = vchiq_platform_get_arm_state(&mgmt->state);
kthread_stop(arm_state->ka_thread);
-
- kfree(mgmt);
}

static struct platform_driver vchiq_driver = {
--
2.45.2