Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: mediatek: vcodec: Only free buffer VA that is not NULL

In the MediaTek vcodec driver, while mtk_vcodec_mem_free() is mostly
called only when the buffer to free exists, there are some instances
that didn't do the check and triggered warnings in practice.

We believe those checks were forgotten unintentionally. Add the checks
back to fix the warnings.

Signed-off-by: Fei Shao <fshao@chromium.org>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
Signed-off-by: Sebastian Fricke <sebastian.fricke@collabora.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>

authored by

Fei Shao and committed by
Mauro Carvalho Chehab
eb005c80 f19a771a

+18 -9
+15 -7
drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_av1_req_lat_if.c
··· 1023 1023 int i; 1024 1024 1025 1025 for (i = 0; i < ARRAY_SIZE(instance->mv); i++) 1026 - mtk_vcodec_mem_free(ctx, &instance->mv[i]); 1026 + if (instance->mv[i].va) 1027 + mtk_vcodec_mem_free(ctx, &instance->mv[i]); 1027 1028 1028 1029 for (i = 0; i < ARRAY_SIZE(instance->seg); i++) 1029 - mtk_vcodec_mem_free(ctx, &instance->seg[i]); 1030 + if (instance->seg[i].va) 1031 + mtk_vcodec_mem_free(ctx, &instance->seg[i]); 1030 1032 1031 1033 for (i = 0; i < ARRAY_SIZE(instance->cdf); i++) 1032 - mtk_vcodec_mem_free(ctx, &instance->cdf[i]); 1034 + if (instance->cdf[i].va) 1035 + mtk_vcodec_mem_free(ctx, &instance->cdf[i]); 1033 1036 1034 - mtk_vcodec_mem_free(ctx, &instance->tile); 1035 - mtk_vcodec_mem_free(ctx, &instance->cdf_temp); 1036 - mtk_vcodec_mem_free(ctx, &instance->cdf_table); 1037 - mtk_vcodec_mem_free(ctx, &instance->iq_table); 1037 + 1038 + if (instance->tile.va) 1039 + mtk_vcodec_mem_free(ctx, &instance->tile); 1040 + if (instance->cdf_temp.va) 1041 + mtk_vcodec_mem_free(ctx, &instance->cdf_temp); 1042 + if (instance->cdf_table.va) 1043 + mtk_vcodec_mem_free(ctx, &instance->cdf_table); 1044 + if (instance->iq_table.va) 1045 + mtk_vcodec_mem_free(ctx, &instance->iq_table); 1038 1046 1039 1047 instance->level = AV1_RES_NONE; 1040 1048 }
+3 -2
drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.c
··· 301 301 * other buffers need to be freed by AP. 302 302 */ 303 303 for (i = 0; i < VENC_H264_VPU_WORK_BUF_MAX; i++) { 304 - if (i != VENC_H264_VPU_WORK_BUF_SKIP_FRAME) 304 + if (i != VENC_H264_VPU_WORK_BUF_SKIP_FRAME && inst->work_bufs[i].va) 305 305 mtk_vcodec_mem_free(inst->ctx, &inst->work_bufs[i]); 306 306 } 307 307 308 - mtk_vcodec_mem_free(inst->ctx, &inst->pps_buf); 308 + if (inst->pps_buf.va) 309 + mtk_vcodec_mem_free(inst->ctx, &inst->pps_buf); 309 310 } 310 311 311 312 static int h264_enc_alloc_work_buf(struct venc_h264_inst *inst, bool is_34bit)