提交 13884b11 编写于 作者: D Dave Stevenson 提交者: Zheng Zengkai

staging: mmal-vchiq: Fix memory leak in error path

raspberrypi inclusion
category: feature
bugzilla: 50432

--------------------------------

On error, vchiq_mmal_component_init could leave the
event context allocated for ports.
Clean them up in the error path.
Signed-off-by: NDave Stevenson <dave.stevenson@raspberrypi.org>
Signed-off-by: NFang Yafen <yafen@iscas.ac.cn>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 8db84eb9
...@@ -1767,9 +1767,26 @@ static void free_event_context(struct vchiq_mmal_port *port) ...@@ -1767,9 +1767,26 @@ static void free_event_context(struct vchiq_mmal_port *port)
{ {
struct mmal_msg_context *ctx = port->event_context; struct mmal_msg_context *ctx = port->event_context;
if (!ctx)
return;
kfree(ctx->u.bulk.buffer->buffer); kfree(ctx->u.bulk.buffer->buffer);
kfree(ctx->u.bulk.buffer); kfree(ctx->u.bulk.buffer);
release_msg_context(ctx); 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 /* Initialise a mmal component and its ports
...@@ -1867,6 +1884,7 @@ int vchiq_mmal_component_init(struct vchiq_mmal_instance *instance, ...@@ -1867,6 +1884,7 @@ int vchiq_mmal_component_init(struct vchiq_mmal_instance *instance,
release_component: release_component:
destroy_component(instance, component); destroy_component(instance, component);
release_all_event_contexts(component);
unlock: unlock:
if (component) if (component)
component->in_use = 0; component->in_use = 0;
...@@ -1882,7 +1900,7 @@ EXPORT_SYMBOL_GPL(vchiq_mmal_component_init); ...@@ -1882,7 +1900,7 @@ EXPORT_SYMBOL_GPL(vchiq_mmal_component_init);
int vchiq_mmal_component_finalise(struct vchiq_mmal_instance *instance, int vchiq_mmal_component_finalise(struct vchiq_mmal_instance *instance,
struct vchiq_mmal_component *component) struct vchiq_mmal_component *component)
{ {
int ret, idx; int ret;
if (mutex_lock_interruptible(&instance->vchiq_mutex)) if (mutex_lock_interruptible(&instance->vchiq_mutex))
return -EINTR; return -EINTR;
...@@ -1894,14 +1912,7 @@ int vchiq_mmal_component_finalise(struct vchiq_mmal_instance *instance, ...@@ -1894,14 +1912,7 @@ int vchiq_mmal_component_finalise(struct vchiq_mmal_instance *instance,
component->in_use = 0; component->in_use = 0;
for (idx = 0; idx < component->inputs; idx++) release_all_event_contexts(component);
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);
mutex_unlock(&instance->vchiq_mutex); mutex_unlock(&instance->vchiq_mutex);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册