Commit 47aa866f authored by Ming Qian's avatar Ming Qian Committed by Mauro Carvalho Chehab
Browse files

media: amphion: cleanup media device if register it fail



there is issue that driver forget to
call media_device_cleanup if media_device_register fail,
it will led to memory leak.
Also driver should check the return value of vpu_add_func.

Signed-off-by: default avatarMing Qian <ming.qian@nxp.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
parent a9f7224c
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -128,8 +128,12 @@ static int vpu_probe(struct platform_device *pdev)
	vpu->encoder.function = MEDIA_ENT_F_PROC_VIDEO_ENCODER;
	vpu->decoder.type = VPU_CORE_TYPE_DEC;
	vpu->decoder.function = MEDIA_ENT_F_PROC_VIDEO_DECODER;
	vpu_add_func(vpu, &vpu->decoder);
	vpu_add_func(vpu, &vpu->encoder);
	ret = vpu_add_func(vpu, &vpu->decoder);
	if (ret)
		goto err_add_decoder;
	ret = vpu_add_func(vpu, &vpu->encoder);
	if (ret)
		goto err_add_encoder;
	ret = media_device_register(&vpu->mdev);
	if (ret)
		goto err_vpu_media;
@@ -141,7 +145,10 @@ static int vpu_probe(struct platform_device *pdev)

err_vpu_media:
	vpu_remove_func(&vpu->encoder);
err_add_encoder:
	vpu_remove_func(&vpu->decoder);
err_add_decoder:
	media_device_cleanup(&vpu->mdev);
	v4l2_device_unregister(&vpu->v4l2_dev);
err_vpu_deinit:
	pm_runtime_set_suspended(dev);