From 48d13824d3bdf668798acd8880c75b056324606f Mon Sep 17 00:00:00 2001 From: "Guoniu.Zhou" Date: Mon, 12 Nov 2018 16:17:44 +0800 Subject: [PATCH] MLK-20325: ISI: fix reference count error when camera is not connected If camera is not connected and user try to use mem2mem function, driver will return error but isi channel0 reference counter is still increased by one. This will lead to mem2mem driver return EBUSY error when user open mem2mem device, so correct this bug in this patch. Signed-off-by: Guoniu.Zhou --- drivers/media/platform/imx8/mxc-isi-cap.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/imx8/mxc-isi-cap.c b/drivers/media/platform/imx8/mxc-isi-cap.c index 0c1a4433411e..f6f057b1b5f3 100644 --- a/drivers/media/platform/imx8/mxc-isi-cap.c +++ b/drivers/media/platform/imx8/mxc-isi-cap.c @@ -663,14 +663,14 @@ static int mxc_isi_capture_open(struct file *file) source_pad = mxc_isi_get_remote_source_pad(mxc_isi); if (source_pad == NULL) { v4l2_err(mxc_isi->v4l2_dev, "%s, No remote pad found!\n", __func__); - return -EINVAL; + goto fail; } /* Get remote source pad subdev */ sd = media_entity_to_v4l2_subdev(source_pad->entity); if (sd == NULL) { v4l2_err(mxc_isi->v4l2_dev, "%s, No remote subdev found!\n", __func__); - return -EINVAL; + goto fail; } mutex_lock(&mxc_isi->lock); @@ -683,10 +683,14 @@ static int mxc_isi_capture_open(struct file *file) if (ret) { v4l2_err(mxc_isi->v4l2_dev, "%s, Call subdev s_power fail!\n", __func__); pm_runtime_put(dev); - return ret; + goto fail; } return 0; + +fail: + atomic_dec(&mxc_isi->open_count); + return -EINVAL; } static int mxc_isi_capture_release(struct file *file) @@ -724,7 +728,8 @@ static int mxc_isi_capture_release(struct file *file) } mutex_unlock(&mxc_isi->lock); - if (atomic_dec_and_test(&mxc_isi->open_count)) + if (atomic_read(&mxc_isi->open_count) > 0 && + atomic_dec_and_test(&mxc_isi->open_count)) mxc_isi_channel_deinit(mxc_isi); ret = v4l2_subdev_call(sd, core, s_power, 0); -- 2.17.1