]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
media: amphion: Guard memory allocation to catch failures
authorMing Qian <ming.qian@nxp.com>
Wed, 28 Aug 2024 13:01:24 +0000 (16:01 +0300)
committerHans Verkuil <hverkuil-cisco@xs4all.nl>
Sat, 12 Oct 2024 14:28:24 +0000 (16:28 +0200)
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>
drivers/media/platform/amphion/venc.c

index 351b4edc8742718d56059bf69e8b4a90d0500f1b..c5c1f1fbaa80366d5b18b8f24699eb9c3a18ef92 100644 (file)
@@ -52,6 +52,7 @@ struct venc_t {
        u32 ready_count;
        u32 enable;
        u32 stopped;
+       u32 memory_resource_configured;
 
        u32 skipped_count;
        u32 skipped_bytes;
@@ -943,10 +944,19 @@ static int venc_start_session(struct vpu_inst *inst, u32 type)
        ret = vpu_iface_set_encode_params(inst, &venc->params, 0);
        if (ret)
                goto error;
+
+       venc->memory_resource_configured = false;
        ret = vpu_session_configure_codec(inst);
        if (ret)
                goto error;
 
+       if (!venc->memory_resource_configured) {
+               vb2_queue_error(v4l2_m2m_get_src_vq(inst->fh.m2m_ctx));
+               vb2_queue_error(v4l2_m2m_get_dst_vq(inst->fh.m2m_ctx));
+               ret = -ENOMEM;
+               goto error;
+       }
+
        inst->state = VPU_CODEC_STATE_CONFIGURED;
        /*vpu_iface_config_memory_resource*/
 
@@ -985,6 +995,7 @@ static void venc_cleanup_mem_resource(struct vpu_inst *inst)
        u32 i;
 
        venc = inst->priv;
+       venc->memory_resource_configured = false;
 
        for (i = 0; i < ARRAY_SIZE(venc->enc); i++)
                vpu_free_dma(&venc->enc[i]);
@@ -1048,6 +1059,7 @@ static void venc_request_mem_resource(struct vpu_inst *inst,
                vpu_iface_config_memory_resource(inst, MEM_RES_REF, i, &venc->ref[i]);
        for (i = 0; i < act_frame_num; i++)
                vpu_iface_config_memory_resource(inst, MEM_RES_ACT, i, &venc->act[i]);
+       venc->memory_resource_configured = true;
 }
 
 static void venc_cleanup_frames(struct venc_t *venc)