staging: vchiq-mmal: Fix memory leak of vchiq instance
authorDave Stevenson <dave.stevenson@raspberrypi.org>
Fri, 3 May 2019 12:27:51 +0000 (13:27 +0100)
committerpopcornmix <popcornmix@gmail.com>
Mon, 13 May 2019 23:08:33 +0000 (00:08 +0100)
The vchiq instance was allocated from vchiq_mmal_init via
vchi_initialise, but was never released with vchi_disconnect.

Retain the handle and release it from vchiq_mmal_finalise.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c

index c82fb0f..5bfba5b 100644 (file)
@@ -176,6 +176,7 @@ struct mmal_msg_context {
 };
 
 struct vchiq_mmal_instance {
+       VCHI_INSTANCE_T vchi_instance;
        VCHI_SERVICE_HANDLE_T handle;
 
        /* ensure serialised access to service */
@@ -1981,7 +1982,7 @@ EXPORT_SYMBOL_GPL(vchiq_mmal_component_init);
 int vchiq_mmal_component_finalise(struct vchiq_mmal_instance *instance,
                                  struct vchiq_mmal_component *component)
 {
-       int ret, idx;
+       int ret;
 
        if (mutex_lock_interruptible(&instance->vchiq_mutex))
                return -EINTR;
@@ -2094,6 +2095,8 @@ int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance)
 
        idr_destroy(&instance->context_map);
 
+       vchi_disconnect(instance->vchi_instance);
+
        kfree(instance);
 
        return status;
@@ -2105,7 +2108,7 @@ int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
        int status;
        struct vchiq_mmal_instance *instance;
        static VCHI_CONNECTION_T *vchi_connection;
-       static VCHI_INSTANCE_T vchi_instance;
+       VCHI_INSTANCE_T vchi_instance;
        SERVICE_CREATION_T params = {
                .version                = VCHI_VERSION_EX(VC_MMAL_VER, VC_MMAL_MIN_VER),
                .service_id             = VC_MMAL_SERVER_NAME,
@@ -2151,6 +2154,8 @@ int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
        if (!instance)
                return -ENOMEM;
 
+       instance->vchi_instance = vchi_instance;
+
        mutex_init(&instance->vchiq_mutex);
 
        instance->bulk_scratch = vmalloc(PAGE_SIZE);