Skip to content

Commit 97242d7

Browse files
6by9popcornmix
authored andcommitted
staging: mmal-vchiq: Fix memory leak in error path
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 <[email protected]>
1 parent cea4f88 commit 97242d7

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,9 +1847,26 @@ static void free_event_context(struct vchiq_mmal_port *port)
18471847
{
18481848
struct mmal_msg_context *ctx = port->event_context;
18491849

1850+
if (!ctx)
1851+
return;
1852+
18501853
kfree(ctx->u.bulk.buffer->buffer);
18511854
kfree(ctx->u.bulk.buffer);
18521855
release_msg_context(ctx);
1856+
port->event_context = NULL;
1857+
}
1858+
1859+
static void release_all_event_contexts(struct vchiq_mmal_component *component)
1860+
{
1861+
int idx;
1862+
1863+
for (idx = 0; idx < component->inputs; idx++)
1864+
free_event_context(&component->input[idx]);
1865+
for (idx = 0; idx < component->outputs; idx++)
1866+
free_event_context(&component->output[idx]);
1867+
for (idx = 0; idx < component->clocks; idx++)
1868+
free_event_context(&component->clock[idx]);
1869+
free_event_context(&component->control);
18531870
}
18541871

18551872
/* Initialise a mmal component and its ports
@@ -1947,6 +1964,7 @@ int vchiq_mmal_component_init(struct vchiq_mmal_instance *instance,
19471964

19481965
release_component:
19491966
destroy_component(instance, component);
1967+
release_all_event_contexts(component);
19501968
unlock:
19511969
if (component)
19521970
component->in_use = 0;
@@ -1962,7 +1980,7 @@ EXPORT_SYMBOL_GPL(vchiq_mmal_component_init);
19621980
int vchiq_mmal_component_finalise(struct vchiq_mmal_instance *instance,
19631981
struct vchiq_mmal_component *component)
19641982
{
1965-
int ret, idx;
1983+
int ret;
19661984

19671985
if (mutex_lock_interruptible(&instance->vchiq_mutex))
19681986
return -EINTR;
@@ -1974,14 +1992,7 @@ int vchiq_mmal_component_finalise(struct vchiq_mmal_instance *instance,
19741992

19751993
component->in_use = 0;
19761994

1977-
for (idx = 0; idx < component->inputs; idx++)
1978-
free_event_context(&component->input[idx]);
1979-
for (idx = 0; idx < component->outputs; idx++)
1980-
free_event_context(&component->output[idx]);
1981-
for (idx = 0; idx < component->clocks; idx++)
1982-
free_event_context(&component->clock[idx]);
1983-
1984-
free_event_context(&component->control);
1995+
release_all_event_contexts(component);
19851996

19861997
mutex_unlock(&instance->vchiq_mutex);
19871998

0 commit comments

Comments
 (0)