Re: [PATCH] staging: vchiq_arm: Utilize devm_kzalloc in the probe() function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Umang,

Am 13.10.24 um 19:16 schrieb Umang Jain:
The two resources, 'mgmt' and 'platform_state' are currently allocated
dynamically using kzalloc(). Unfortunately, both are subject to memory
leaks in the error handling paths of the probe() function.

To address this issue, use device resource management helper devm_kzalloc()
for proper cleanup during 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>
---
  .../staging/vc04_services/interface/vchiq_arm/vchiq_arm.c   | 6 ++----
  1 file changed, 2 insertions(+), 4 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 29e78700463f..373cfdd5b020 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
@@ -285,7 +285,7 @@ vchiq_platform_init_state(struct vchiq_state *state)
  {
  	struct vchiq_arm_state *platform_state;

-	platform_state = kzalloc(sizeof(*platform_state), GFP_KERNEL);
+	platform_state = devm_kzalloc(state->dev, sizeof(*platform_state), GFP_KERNEL);
From my understand this leak has been there from the beginning and
platform_state is never freed. So I think this patch should be splitted,
because the Fixes applies only to the rest of the patch.

Regards
  	if (!platform_state)
  		return -ENOMEM;

@@ -1344,7 +1344,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;

@@ -1402,8 +1402,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 = {






[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux