[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <b176520b-5578-40b0-9d68-b1051810c5bb@gmx.net>
Date: Sun, 13 Oct 2024 22:29:16 +0200
From: Stefan Wahren <wahrenst@....net>
To: Umang Jain <umang.jain@...asonboard.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Broadcom internal kernel review list <bcm-kernel-feedback-list@...adcom.com>
Cc: linux-rpi-kernel@...ts.infradead.org,
linux-arm-kernel@...ts.infradead.org, linux-staging@...ts.linux.dev,
linux-kernel@...r.kernel.org,
Kieran Bingham <kieran.bingham@...asonboard.com>,
Dan Carpenter <dan.carpenter@...aro.org>,
Laurent Pinchart <laurent.pinchart@...asonboard.com>,
kernel-list@...pberrypi.com, Javier Carrasco
<javier.carrasco.cruz@...il.com>, stable@...r.kernel.org
Subject: Re: [PATCH] staging: vchiq_arm: Utilize devm_kzalloc in the probe()
function
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@...r.kernel.org
> Fixes: 1c9e16b73166 ("staging: vc04_services: vchiq_arm: Split driver static and runtime data")
> Signed-off-by: Umang Jain <umang.jain@...asonboard.com>
> ---
> .../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 = {
Powered by blists - more mailing lists