1 From 250db0df9643d122e00313313102c642f1adac72 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.org>
3 Date: Thu, 2 May 2019 15:50:01 +0100
4 Subject: [PATCH] staging: mmal-vchiq: Fix memory leak in error path
6 On error, vchiq_mmal_component_init could leave the
7 event context allocated for ports.
8 Clean them up in the error path.
10 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
12 .../vc04_services/vchiq-mmal/mmal-vchiq.c | 27 +++++++++++++------
13 1 file changed, 19 insertions(+), 8 deletions(-)
15 --- a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
16 +++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
17 @@ -1848,9 +1848,26 @@ static void free_event_context(struct vc
19 struct mmal_msg_context *ctx = port->event_context;
24 kfree(ctx->u.bulk.buffer->buffer);
25 kfree(ctx->u.bulk.buffer);
26 release_msg_context(ctx);
27 + port->event_context = NULL;
30 +static void release_all_event_contexts(struct vchiq_mmal_component *component)
34 + for (idx = 0; idx < component->inputs; idx++)
35 + free_event_context(&component->input[idx]);
36 + for (idx = 0; idx < component->outputs; idx++)
37 + free_event_context(&component->output[idx]);
38 + for (idx = 0; idx < component->clocks; idx++)
39 + free_event_context(&component->clock[idx]);
40 + free_event_context(&component->control);
43 /* Initialise a mmal component and its ports
44 @@ -1948,6 +1965,7 @@ int vchiq_mmal_component_init(struct vch
47 destroy_component(instance, component);
48 + release_all_event_contexts(component);
51 component->in_use = 0;
52 @@ -1975,14 +1993,7 @@ int vchiq_mmal_component_finalise(struct
54 component->in_use = 0;
56 - for (idx = 0; idx < component->inputs; idx++)
57 - free_event_context(&component->input[idx]);
58 - for (idx = 0; idx < component->outputs; idx++)
59 - free_event_context(&component->output[idx]);
60 - for (idx = 0; idx < component->clocks; idx++)
61 - free_event_context(&component->clock[idx]);
63 - free_event_context(&component->control);
64 + release_all_event_contexts(component);
66 mutex_unlock(&instance->vchiq_mutex);