From: Maarten <maarten@rmail.be>
To: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
Cc: Raspberry Pi Kernel Maintenance <kernel-list@raspberrypi.com>,
linux-media@vger.kernel.org, Kieran Bingham <kbingham@kernel.org>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Umang Jain <umang.jain@ideasonboard.com>,
Dave Stevenson <dave.stevenson@raspberrypi.org>
Subject: Re: [RFC PATCH 03/13] staging: mmal-vchiq: Fix memory leak in error path
Date: Tue, 05 Mar 2024 19:02:20 +0100 [thread overview]
Message-ID: <cf98c79782d53d44d7f8be182aff8a57@rmail.be> (raw)
In-Reply-To: <00f3c02e-a71b-4e41-a50b-f0494ce1a73d@collabora.com>
Andrzej Pietrasiewicz schreef op 2024-03-04 08:38:
> Hi Maarten,
>
> W dniu 3.03.2024 o 16:09, Maarten Vanraes pisze:
>> From: Dave Stevenson <dave.stevenson@raspberrypi.org>
>>
>> On error, vchiq_mmal_component_init could leave the
>> event context allocated for ports.
>> Clean them up in the error path.
>>
>> Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
>>
>> staging: mmal-vchiq: Free the event context for control ports
>>
>> vchiq_mmal_component_init calls init_event_context for the
>> control port, but vchiq_mmal_component_finalise didn't free
>> it, causing a memory leak..
>>
>> Add the free call.
>>
>> Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
>> Signed-off-by: Maarten Vanraes <maarten@rmail.be>
>> ---
>> .../vc04_services/vchiq-mmal/mmal-vchiq.c | 29
>> ++++++++++++++-----
>> 1 file changed, 22 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
>> b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
>> index 2e616604943d..1209b7db8f30 100644
>> --- a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
>> +++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
>> @@ -1825,9 +1825,26 @@ static void free_event_context(struct
>> vchiq_mmal_port *port)
>> {
>> struct mmal_msg_context *ctx = port->event_context;
>> + if (!ctx)
>> + return;
>> +
>> kfree(ctx->u.bulk.buffer->buffer);
>> kfree(ctx->u.bulk.buffer);
>> release_msg_context(ctx);
>> + port->event_context = NULL;
>> +}
>> +
>> +static void release_all_event_contexts(struct vchiq_mmal_component
>> *component)
>> +{
>> + int idx;
>> +
>> + for (idx = 0; idx < component->inputs; idx++)
>> + free_event_context(&component->input[idx]);
>> + for (idx = 0; idx < component->outputs; idx++)
>> + free_event_context(&component->output[idx]);
>> + for (idx = 0; idx < component->clocks; idx++)
>> + free_event_context(&component->clock[idx]);
>> + free_event_context(&component->control);
>> }
>> /* Initialise a mmal component and its ports
>> @@ -1925,6 +1942,7 @@ int vchiq_mmal_component_init(struct
>> vchiq_mmal_instance *instance,
>> release_component:
>> destroy_component(instance, component);
>> + release_all_event_contexts(component);
>> unlock:
>> if (component)
>> component->in_use = false;
>> @@ -1940,7 +1958,7 @@ EXPORT_SYMBOL_GPL(vchiq_mmal_component_init);
>> int vchiq_mmal_component_finalise(struct vchiq_mmal_instance
>> *instance,
>> struct vchiq_mmal_component *component)
>> {
>> - int ret, idx;
>> + int ret;
>> if (mutex_lock_interruptible(&instance->vchiq_mutex))
>> return -EINTR;
>> @@ -1952,12 +1970,9 @@ int vchiq_mmal_component_finalise(struct
>> vchiq_mmal_instance *instance,
>> component->in_use = false;
>> - for (idx = 0; idx < component->inputs; idx++)
>> - free_event_context(&component->input[idx]);
>> - for (idx = 0; idx < component->outputs; idx++)
>> - free_event_context(&component->output[idx]);
>> - for (idx = 0; idx < component->clocks; idx++)
>> - free_event_context(&component->clock[idx]);
>> + release_all_event_contexts(component);
>
> The way I understand this chunk is that you factor out the 3 "for"
> loops into
> the new function "release_all_event_contexts()", because it is then
> reused elsewhere. "release_all_event_contexts()" already contains
> invocation of
> "free_event_context(&component->control)"...
>
>> +
>> + free_event_context(&component->control);
>
> ... but it is repeated here. Why?
I'm sorry, I messed up in squashing 2 patches, that definately does not
belong there, will fix in v2.
Thanks!
next prev parent reply other threads:[~2024-03-05 18:02 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-03 15:09 [RFC PATCH 00/13] bcm2835-codec: driver for HW codecs Maarten Vanraes
2024-03-03 15:09 ` [RFC PATCH 01/13] staging: mmal-vchiq: Avoid use of bool in structures Maarten Vanraes
2024-03-04 7:30 ` Andrzej Pietrasiewicz
2024-03-05 18:00 ` Maarten
2024-03-03 15:09 ` [RFC PATCH 02/13] staging: mmal-vchiq: Update mmal_parameters.h with recently defined params Maarten Vanraes
2024-03-03 15:09 ` [RFC PATCH 03/13] staging: mmal-vchiq: Fix memory leak in error path Maarten Vanraes
2024-03-04 7:38 ` Andrzej Pietrasiewicz
2024-03-05 18:02 ` Maarten [this message]
2024-03-03 15:09 ` [RFC PATCH 04/13] media: videodev2.h: Add a format for column YUV4:2:0 modes Maarten Vanraes
2024-03-04 18:10 ` Nicolas Dufresne
2024-03-05 18:14 ` Maarten
2024-03-06 20:46 ` Nicolas Dufresne
2024-03-05 18:53 ` Dave Stevenson
2024-03-05 19:43 ` Maarten
2024-03-10 12:42 ` Maarten
2024-03-10 12:54 ` Maarten
2024-03-03 15:10 ` [RFC PATCH 05/13] staging: vchiq_arm: Add 36-bit address support Maarten Vanraes
2024-03-07 10:19 ` Krzysztof Kozlowski
2024-03-07 10:23 ` Maarten
2024-03-03 15:10 ` [RFC PATCH 06/13] staging: vchiq_arm: Usa a DMA pool for small bulks Maarten Vanraes
2024-03-03 15:10 ` [RFC PATCH 07/13] staging/vchiq-mmal: Add buffer flags for interlaced video Maarten Vanraes
2024-03-03 15:10 ` [RFC PATCH 08/13] staging/vchiq-mmal: Add parameters for interlaced video support Maarten Vanraes
2024-03-03 15:10 ` [RFC PATCH 09/13] staging/vchiq-mmal: Add the deinterlace image effects enums Maarten Vanraes
2024-03-03 15:10 ` [RFC PATCH 10/13] staging/mmal-vchiq: Rationalise included headers Maarten Vanraes
2024-03-03 15:10 ` [RFC PATCH 11/13] staging: mmal-vchiq: Reset buffers_with_vpu on port_enable Maarten Vanraes
2024-03-03 15:10 ` [RFC PATCH 12/13] vc04_services: vchiq-mmal: Add defines for mmal_es_format flags Maarten Vanraes
2024-03-03 15:10 ` [RFC PATCH 13/13] staging: vc04_services: Add a V4L2 M2M codec driver Maarten Vanraes
2024-03-04 17:58 ` Nicolas Dufresne
2024-03-05 19:35 ` Maarten
2024-03-06 21:14 ` Nicolas Dufresne
2024-03-24 12:35 ` Maarten
2024-04-01 9:45 ` Maarten
2024-04-01 9:56 ` Maarten
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cf98c79782d53d44d7f8be182aff8a57@rmail.be \
--to=maarten@rmail.be \
--cc=andrzej.p@collabora.com \
--cc=dave.stevenson@raspberrypi.org \
--cc=kbingham@kernel.org \
--cc=kernel-list@raspberrypi.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=umang.jain@ideasonboard.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).