linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/2] staging: staging: vchiq_arm: Two memory leak fixes
@ 2024-10-14 10:06 Umang Jain
  2024-10-14 10:06 ` [PATCH v3 1/2] staging: vchiq_arm: Utilise devm_kzalloc() for allocation Umang Jain
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Umang Jain @ 2024-10-14 10:06 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, Umang Jain

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

Changes in v3:
- Add Fixes tag to 1/2 as well.
  (Suggestion by Dan Carpenter)

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] 5+ messages in thread

* [PATCH v3 1/2] staging: vchiq_arm: Utilise devm_kzalloc() for allocation
  2024-10-14 10:06 [PATCH v3 0/2] staging: staging: vchiq_arm: Two memory leak fixes Umang Jain
@ 2024-10-14 10:06 ` Umang Jain
  2024-10-14 10:06 ` [PATCH v3 2/2] staging: vchiq_arm: Utilize " Umang Jain
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Umang Jain @ 2024-10-14 10:06 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, 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.

Fixes: 71bad7f08641 ("staging: add bcm2708 vchiq driver")
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 af623ad87c15..7ece82c361ee 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 related	[flat|nested] 5+ messages in thread

* [PATCH v3 2/2] staging: vchiq_arm: Utilize devm_kzalloc() for allocation
  2024-10-14 10:06 [PATCH v3 0/2] staging: staging: vchiq_arm: Two memory leak fixes Umang Jain
  2024-10-14 10:06 ` [PATCH v3 1/2] staging: vchiq_arm: Utilise devm_kzalloc() for allocation Umang Jain
@ 2024-10-14 10:06 ` Umang Jain
  2024-10-14 10:11 ` [PATCH v3 0/2] staging: staging: vchiq_arm: Two memory leak fixes Dan Carpenter
  2024-10-16  7:58 ` Greg Kroah-Hartman
  3 siblings, 0 replies; 5+ messages in thread
From: Umang Jain @ 2024-10-14 10:06 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, 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 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



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

* Re: [PATCH v3 0/2] staging: staging: vchiq_arm: Two memory leak fixes
  2024-10-14 10:06 [PATCH v3 0/2] staging: staging: vchiq_arm: Two memory leak fixes Umang Jain
  2024-10-14 10:06 ` [PATCH v3 1/2] staging: vchiq_arm: Utilise devm_kzalloc() for allocation Umang Jain
  2024-10-14 10:06 ` [PATCH v3 2/2] staging: vchiq_arm: Utilize " Umang Jain
@ 2024-10-14 10:11 ` Dan Carpenter
  2024-10-16  7:58 ` Greg Kroah-Hartman
  3 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2024-10-14 10:11 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

On Mon, Oct 14, 2024 at 03:36:22PM +0530, Umang Jain wrote:
> Two memory leaks were identified and this series addresses those leaks.
> 
> Changes in v3:
> - Add Fixes tag to 1/2 as well.
>   (Suggestion by Dan Carpenter)

Thanks.

Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>

regards,
dan carpenter



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

* Re: [PATCH v3 0/2] staging: staging: vchiq_arm: Two memory leak fixes
  2024-10-14 10:06 [PATCH v3 0/2] staging: staging: vchiq_arm: Two memory leak fixes Umang Jain
                   ` (2 preceding siblings ...)
  2024-10-14 10:11 ` [PATCH v3 0/2] staging: staging: vchiq_arm: Two memory leak fixes Dan Carpenter
@ 2024-10-16  7:58 ` Greg Kroah-Hartman
  3 siblings, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2024-10-16  7:58 UTC (permalink / raw)
  To: Umang Jain
  Cc: Broadcom internal kernel review list, linux-rpi-kernel,
	linux-arm-kernel, linux-staging, linux-kernel, Kieran Bingham,
	Dan Carpenter, Laurent Pinchart, kernel-list, Stefan Wahren

On Mon, Oct 14, 2024 at 03:36:22PM +0530, Umang Jain wrote:
> Two memory leaks were identified and this series addresses those leaks.
> 
> Changes in v3:
> - Add Fixes tag to 1/2 as well.
>   (Suggestion by Dan Carpenter)
> 
> 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

You have two commits with almost identical commit messages (one with a
spelling mistake.)  Please fix this up to have them be unique not in a
way with a misspelling :)

thanks,

greg k-h


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

end of thread, other threads:[~2024-10-16  8:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-14 10:06 [PATCH v3 0/2] staging: staging: vchiq_arm: Two memory leak fixes Umang Jain
2024-10-14 10:06 ` [PATCH v3 1/2] staging: vchiq_arm: Utilise devm_kzalloc() for allocation Umang Jain
2024-10-14 10:06 ` [PATCH v3 2/2] staging: vchiq_arm: Utilize " Umang Jain
2024-10-14 10:11 ` [PATCH v3 0/2] staging: staging: vchiq_arm: Two memory leak fixes Dan Carpenter
2024-10-16  7:58 ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).