From 2eae84f039304bfbfa80920a9d43b1f5abe746ca Mon Sep 17 00:00:00 2001 From: Sanjay Singh Date: Wed, 9 Jan 2019 16:11:36 +0530 Subject: [PATCH] msm: vidc: Correct error handling for allocation failure cases In error handling, trying to free memory which is not yet allocated. Fix is added to correct this error handling. Change-Id: I4e91a95f7ebd9132141d8686ae2bdfaed3a9a8c1 Signed-off-by: Sanjay Singh Signed-off-by: Vasantha Balla --- drivers/media/platform/msm/vidc/msm_vidc_common.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/media/platform/msm/vidc/msm_vidc_common.c b/drivers/media/platform/msm/vidc/msm_vidc_common.c index ee3cfb88855c..c3f558b4334e 100644 --- a/drivers/media/platform/msm/vidc/msm_vidc_common.c +++ b/drivers/media/platform/msm/vidc/msm_vidc_common.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved. +/* Copyright (c) 2012-2019, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and @@ -1478,7 +1478,7 @@ void validate_output_buffers(struct msm_vidc_inst *inst) } mutex_lock(&inst->outputbufs.lock); list_for_each_entry(binfo, &inst->outputbufs.list, list) { - if (binfo->buffer_ownership != DRIVER) { + if (binfo && binfo->buffer_ownership != DRIVER) { dprintk(VIDC_DBG, "This buffer is with FW %pa\n", &binfo->handle->device_addr); @@ -3175,8 +3175,7 @@ static int set_output_buffers(struct msm_vidc_inst *inst, if (!handle) { dprintk(VIDC_ERR, "Failed to allocate output memory\n"); - rc = -ENOMEM; - goto err_no_mem; + return -ENOMEM; } rc = msm_comm_smem_cache_operations(inst, handle, SMEM_CACHE_CLEAN, -1); @@ -3228,10 +3227,9 @@ static int set_output_buffers(struct msm_vidc_inst *inst, } return rc; fail_set_buffers: - msm_comm_smem_free(inst, handle); -err_no_mem: kfree(binfo); fail_kzalloc: + msm_comm_smem_free(inst, handle); return rc; }