media: amphion: cancel vpu before release instance
authorMing Qian <ming.qian@nxp.com>
Mon, 21 Nov 2022 06:34:07 +0000 (06:34 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 31 Dec 2022 12:32:17 +0000 (13:32 +0100)
[ Upstream commit b3dd974af9de342c733492565ad02d7e23372876 ]

Revert "media: amphion: release m2m ctx when releasing vpu instance"
This reverts commit d91d7bc85062309aae6d8064563ddf17947cb6bc.

Call v4l2_m2m_ctx_release() to cancel vpu,
afterwards release the vpu instance.

Fixes: d91d7bc85062 ("media: amphion: release m2m ctx when releasing vpu instance")
Signed-off-by: Ming Qian <ming.qian@nxp.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/media/platform/amphion/vpu_v4l2.c

index 4b714fa..a24e2d0 100644 (file)
@@ -596,10 +596,6 @@ static int vpu_v4l2_release(struct vpu_inst *inst)
                inst->workqueue = NULL;
        }
 
-       if (inst->fh.m2m_ctx) {
-               v4l2_m2m_ctx_release(inst->fh.m2m_ctx);
-               inst->fh.m2m_ctx = NULL;
-       }
        v4l2_ctrl_handler_free(&inst->ctrl_handler);
        mutex_destroy(&inst->lock);
        v4l2_fh_del(&inst->fh);
@@ -682,6 +678,13 @@ int vpu_v4l2_close(struct file *file)
 
        vpu_trace(vpu->dev, "tgid = %d, pid = %d, inst = %p\n", inst->tgid, inst->pid, inst);
 
+       vpu_inst_lock(inst);
+       if (inst->fh.m2m_ctx) {
+               v4l2_m2m_ctx_release(inst->fh.m2m_ctx);
+               inst->fh.m2m_ctx = NULL;
+       }
+       vpu_inst_unlock(inst);
+
        call_void_vop(inst, release);
        vpu_inst_unregister(inst);
        vpu_inst_put(inst);