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

media: amphion: Guard memory allocation to catch failures

The firmware will ask the driver for memory allocation, but it will not
check the completeness of the task. Therefore, the vpu will crash until
reboot. This code will guard this bug and make the driver fail gracefully
when memory allocation cannot be completed.

Signed-off-by: Ming Qian <ming.qian@nxp.com>
Reviewed-by: Zhou Peng <eagle.zhou@nxp.com>
Signed-off-by: Mihai Despotovici <mihai.despotovici@nxp.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>

authored by

Ming Qian and committed by
Hans Verkuil
7ade9353 9d31522a

+12
+12
drivers/media/platform/amphion/venc.c
··· 52 52 u32 ready_count; 53 53 u32 enable; 54 54 u32 stopped; 55 + u32 memory_resource_configured; 55 56 56 57 u32 skipped_count; 57 58 u32 skipped_bytes; ··· 944 943 ret = vpu_iface_set_encode_params(inst, &venc->params, 0); 945 944 if (ret) 946 945 goto error; 946 + 947 + venc->memory_resource_configured = false; 947 948 ret = vpu_session_configure_codec(inst); 948 949 if (ret) 949 950 goto error; 951 + 952 + if (!venc->memory_resource_configured) { 953 + vb2_queue_error(v4l2_m2m_get_src_vq(inst->fh.m2m_ctx)); 954 + vb2_queue_error(v4l2_m2m_get_dst_vq(inst->fh.m2m_ctx)); 955 + ret = -ENOMEM; 956 + goto error; 957 + } 950 958 951 959 inst->state = VPU_CODEC_STATE_CONFIGURED; 952 960 /*vpu_iface_config_memory_resource*/ ··· 995 985 u32 i; 996 986 997 987 venc = inst->priv; 988 + venc->memory_resource_configured = false; 998 989 999 990 for (i = 0; i < ARRAY_SIZE(venc->enc); i++) 1000 991 vpu_free_dma(&venc->enc[i]); ··· 1059 1048 vpu_iface_config_memory_resource(inst, MEM_RES_REF, i, &venc->ref[i]); 1060 1049 for (i = 0; i < act_frame_num; i++) 1061 1050 vpu_iface_config_memory_resource(inst, MEM_RES_ACT, i, &venc->act[i]); 1051 + venc->memory_resource_configured = true; 1062 1052 } 1063 1053 1064 1054 static void venc_cleanup_frames(struct venc_t *venc)