brcm2708: rename target to bcm27xx
[openwrt/staging/stintel.git] / target / linux / bcm27xx / patches-4.19 / 950-0419-staging-mmal-vchiq-Fix-memory-leak-in-error-path.patch
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
5
6 On error, vchiq_mmal_component_init could leave the
7 event context allocated for ports.
8 Clean them up in the error path.
9
10 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
11 ---
12 .../vc04_services/vchiq-mmal/mmal-vchiq.c | 27 +++++++++++++------
13 1 file changed, 19 insertions(+), 8 deletions(-)
14
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
18 {
19 struct mmal_msg_context *ctx = port->event_context;
20
21 + if (!ctx)
22 + return;
23 +
24 kfree(ctx->u.bulk.buffer->buffer);
25 kfree(ctx->u.bulk.buffer);
26 release_msg_context(ctx);
27 + port->event_context = NULL;
28 +}
29 +
30 +static void release_all_event_contexts(struct vchiq_mmal_component *component)
31 +{
32 + int idx;
33 +
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);
41 }
42
43 /* Initialise a mmal component and its ports
44 @@ -1948,6 +1965,7 @@ int vchiq_mmal_component_init(struct vch
45
46 release_component:
47 destroy_component(instance, component);
48 + release_all_event_contexts(component);
49 unlock:
50 if (component)
51 component->in_use = 0;
52 @@ -1975,14 +1993,7 @@ int vchiq_mmal_component_finalise(struct
53
54 component->in_use = 0;
55
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]);
62 -
63 - free_event_context(&component->control);
64 + release_all_event_contexts(component);
65
66 mutex_unlock(&instance->vchiq_mutex);
67