video: tegra: host: fix memory leaks with firmware
Deepak Nibade [Wed, 26 Mar 2014 13:23:14 +0000 (18:23 +0530)]
Pointer variables to store fecs and gpccs firmwares are local
variables.
Once firmwares are copied to local buffer, we can release
them with release_firmware() call before returning from function.

Release fecs and gpccs firmwares after copying to
fix memroy leak

Bug 1484645

Change-Id: I118874d65e30b6966f83d35347132d8f764bab8d
Signed-off-by: Deepak Nibade <dnibade@nvidia.com>
Reviewed-on: http://git-master/r/387139
(cherry picked from commit d7cac8dd9a5d3f6cb44348a9698d0a6aefa80737)
Reviewed-on: http://git-master/r/407188
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Reviewed-by: Matthew Pedro <mapedro@nvidia.com>
Tested-by: Matthew Pedro <mapedro@nvidia.com>
Reviewed-by: Prabhu Kuttiyam <pkuttiyam@nvidia.com>
Tested-by: Prabhu Kuttiyam <pkuttiyam@nvidia.com>
Reviewed-by: Winnie Hsu <whsu@nvidia.com>

drivers/video/tegra/host/gk20a/gr_gk20a.c

index 6280928..b4da945 100644 (file)
@@ -1887,10 +1887,9 @@ static int gr_gk20a_init_ctxsw_ucode(struct gk20a *g)
 
        p_buf = (u8 *)p_ucode_info->surface_desc.cpuva;
        if (!p_buf) {
-               release_firmware(fecs_fw);
-               release_firmware(gpccs_fw);
                nvhost_err(d, "failed to map surface desc buffer");
-               return -ENOMEM;
+               err = -ENOMEM;
+               goto clean_up;
        }
 
        gr_gk20a_copy_ctxsw_ucode_inst(p_buf, &p_ucode_info->fecs,
@@ -1898,11 +1897,17 @@ static int gr_gk20a_init_ctxsw_ucode(struct gk20a *g)
                g->gr.ctx_vars.ucode.fecs.inst.l,
                g->gr.ctx_vars.ucode.fecs.data.l);
 
+       release_firmware(fecs_fw);
+       fecs_fw = NULL;
+
        gr_gk20a_copy_ctxsw_ucode_inst(p_buf, &p_ucode_info->gpcs,
                p_gpcs_boot_desc, p_gpcs_boot_image,
                g->gr.ctx_vars.ucode.gpccs.inst.l,
                g->gr.ctx_vars.ucode.gpccs.data.l);
 
+       release_firmware(gpccs_fw);
+       gpccs_fw = NULL;
+
        err = gr_gk20a_init_ctxsw_ucode_vaspace(g);
        if (err)
                goto clean_up;
@@ -1925,6 +1930,11 @@ static int gr_gk20a_init_ctxsw_ucode(struct gk20a *g)
        p_ucode_info->surface_desc.cpuva = NULL;
        p_ucode_info->surface_desc.iova = 0;
 
+       release_firmware(gpccs_fw);
+       gpccs_fw = NULL;
+       release_firmware(fecs_fw);
+       fecs_fw = NULL;
+
        return err;
 }