mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/2] staging: vchiq_arm: Two memory leak fixes
@ 2024-10-14  6:12 Umang Jain
  2024-10-14  6:12 ` [PATCH v2 1/2] staging: vchiq_arm: Utilise devm_kzalloc() for allocation Umang Jain
  2024-10-14  6:12 ` [PATCH v2 2/2] staging: vchiq_arm: Utilize " Umang Jain
  0 siblings, 2 replies; 4+ messages in thread
From: Umang Jain @ 2024-10-14  6:12 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Broadcom internal kernel review list
  Cc: linux-rpi-kernel, linux-arm-kernel, linux-staging, linux-kernel,
	Kieran Bingham, Dan Carpenter, Laurent Pinchart, kernel-list,
	Stefan Wahren, Javier Carrasco, Umang Jain

Two memory leaks were identified and this series addresses those leaks.

changes in v2:
- Split patches into two

v1:
- https://lore.kernel.org/linux-staging/b176520b-5578-40b0-9d68-b1051810c5bb@gmx.net/T/#t

Umang Jain (2):
  staging: vchiq_arm: Utilise devm_kzalloc() for allocation
  staging: vchiq_arm: Utilize devm_kzalloc() for allocation

 .../staging/vc04_services/interface/vchiq_arm/vchiq_arm.c   | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

-- 
2.45.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/2] staging: vchiq_arm: Utilise devm_kzalloc() for allocation
  2024-10-14  6:12 [PATCH v2 0/2] staging: vchiq_arm: Two memory leak fixes Umang Jain
@ 2024-10-14  6:12 ` Umang Jain
  2024-10-14  6:39   ` Dan Carpenter
  2024-10-14  6:12 ` [PATCH v2 2/2] staging: vchiq_arm: Utilize " Umang Jain
  1 sibling, 1 reply; 4+ messages in thread
From: Umang Jain @ 2024-10-14  6:12 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Broadcom internal kernel review list
  Cc: linux-rpi-kernel, linux-arm-kernel, linux-staging, linux-kernel,
	Kieran Bingham, Dan Carpenter, Laurent Pinchart, kernel-list,
	Stefan Wahren, Javier Carrasco, Umang Jain, stable

The struct vchiq_arm_state 'platform_state' is currently allocated
dynamically using kzalloc(). Unfortunately, it is never freed and is
subjected to memory leaks in the error handling paths of the probe()
function.

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

Cc: stable@vger.kernel.org
Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
---
 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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..146442a3552c 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);
 	if (!platform_state)
 		return -ENOMEM;
 
-- 
2.45.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] staging: vchiq_arm: Utilize devm_kzalloc() for allocation
  2024-10-14  6:12 [PATCH v2 0/2] staging: vchiq_arm: Two memory leak fixes Umang Jain
  2024-10-14  6:12 ` [PATCH v2 1/2] staging: vchiq_arm: Utilise devm_kzalloc() for allocation Umang Jain
@ 2024-10-14  6:12 ` Umang Jain
  1 sibling, 0 replies; 4+ messages in thread
From: Umang Jain @ 2024-10-14  6:12 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Broadcom internal kernel review list
  Cc: linux-rpi-kernel, linux-arm-kernel, linux-staging, linux-kernel,
	Kieran Bingham, Dan Carpenter, Laurent Pinchart, kernel-list,
	Stefan Wahren, Javier Carrasco, Umang Jain, stable

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@vger.kernel.org
Fixes: 1c9e16b73166 ("staging: vc04_services: vchiq_arm: Split driver static and runtime data")
Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
---
 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 146442a3552c..373cfdd5b020 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
@@ -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 = {
-- 
2.45.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/2] staging: vchiq_arm: Utilise devm_kzalloc() for allocation
  2024-10-14  6:12 ` [PATCH v2 1/2] staging: vchiq_arm: Utilise devm_kzalloc() for allocation Umang Jain
@ 2024-10-14  6:39   ` Dan Carpenter
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2024-10-14  6:39 UTC (permalink / raw)
  To: Umang Jain
  Cc: Greg Kroah-Hartman, Broadcom internal kernel review list,
	linux-rpi-kernel, linux-arm-kernel, linux-staging, linux-kernel,
	Kieran Bingham, Laurent Pinchart, kernel-list, Stefan Wahren,
	Javier Carrasco, stable

On Mon, Oct 14, 2024 at 11:42:55AM +0530, Umang Jain wrote:
> The struct vchiq_arm_state 'platform_state' is currently allocated
> dynamically using kzalloc(). Unfortunately, it is never freed and is
> subjected to memory leaks in the error handling paths of the probe()
> function.
> 
> To address the issue, use device resource management helper
> devm_kzalloc(), to ensure cleanup after its allocation.
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
> ---

Checkpatch warns that:

WARNING: The commit message has 'stable@', perhaps it also needs a 'Fixes:' tag?

(I'm the person who created this checkpatch warning.)  Fixes tags aren't just
for regressions they're for any bug fixes.  So the Fixes tag here should point
to when the driver was introduced.

Even if the Fixes tag points to the first git commit, it's useful information
so, please, always include it.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-10-14  6:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-14  6:12 [PATCH v2 0/2] staging: vchiq_arm: Two memory leak fixes Umang Jain
2024-10-14  6:12 ` [PATCH v2 1/2] staging: vchiq_arm: Utilise devm_kzalloc() for allocation Umang Jain
2024-10-14  6:39   ` Dan Carpenter
2024-10-14  6:12 ` [PATCH v2 2/2] staging: vchiq_arm: Utilize " Umang Jain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®