bcm27xx: add support for linux v5.15
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.15 / 950-0138-staging-mmal-vchiq-Fix-memory-leak-in-error-path.patch
1 From bd1a7a80ea59c30541a9ec12eb953068d49f7855 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 | 29 +++++++++++++------
13 1 file changed, 20 insertions(+), 9 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 @@ -1767,9 +1767,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 @@ -1867,6 +1884,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 @@ -1882,7 +1900,7 @@ EXPORT_SYMBOL_GPL(vchiq_mmal_component_i
53 int vchiq_mmal_component_finalise(struct vchiq_mmal_instance *instance,
54 struct vchiq_mmal_component *component)
55 {
56 - int ret, idx;
57 + int ret;
58
59 if (mutex_lock_interruptible(&instance->vchiq_mutex))
60 return -EINTR;
61 @@ -1894,14 +1912,7 @@ int vchiq_mmal_component_finalise(struct
62
63 component->in_use = 0;
64
65 - for (idx = 0; idx < component->inputs; idx++)
66 - free_event_context(&component->input[idx]);
67 - for (idx = 0; idx < component->outputs; idx++)
68 - free_event_context(&component->output[idx]);
69 - for (idx = 0; idx < component->clocks; idx++)
70 - free_event_context(&component->clock[idx]);
71 -
72 - free_event_context(&component->control);
73 + release_all_event_contexts(component);
74
75 mutex_unlock(&instance->vchiq_mutex);
76