Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8bedd401 authored by Kiran Kumar H N's avatar Kiran Kumar H N Committed by Stephen Boyd
Browse files

msm: camera: Remove duplicate video device list initialization.



When a video device is registered through video_register_device,
the fh_lock and fh_list variables are already initialized. So we
dont need to explicitly initialize them during v4l2 event queue
setup. Doing this overwrites the fh_list in some cases like
mctl pp node, where each instance can have its own eventHandle but
linked to the mctl pp video node. This can cause video device list
corruption in some usecases like HDR. Remove this extra
initialization for v4l2 nodes which register their video devices.
For native nodes using v4l2 event handles, add the initialization
before setting up the v4l2 event queue.
Move the function setup_v4l2_event_queue and
destroy_v4l2_event_queue into msm_cam_server.c for better code
organization.

Change-Id: Ifcd148d5d0187cf33a6ea49977010e88d6043698
Signed-off-by: default avatarKiran Kumar H N <hurlisal@codeaurora.org>
parent dffb050c
Loading
Loading
Loading
Loading
+6 −25
Original line number Diff line number Diff line
@@ -911,13 +911,8 @@ static int msm_open(struct file *f)
		}
		pmctl->pcam_ptr = pcam;

		rc = msm_setup_v4l2_event_queue(&pcam_inst->eventHandle,
		msm_setup_v4l2_event_queue(&pcam_inst->eventHandle,
			pcam->pvdev);
		if (rc < 0) {
			pr_err("%s: msm_setup_v4l2_event_queue failed %d",
				__func__, rc);
			goto mctl_event_q_setup_failed;
		}
	}
	pcam_inst->vbqueue_initialized = 0;
	rc = 0;
@@ -940,9 +935,8 @@ static int msm_open(struct file *f)
	return rc;

msm_send_open_server_failed:
	v4l2_fh_del(&pcam_inst->eventHandle);
	v4l2_fh_exit(&pcam_inst->eventHandle);
mctl_event_q_setup_failed:
	msm_destroy_v4l2_event_queue(&pcam_inst->eventHandle);

	if (pmctl->mctl_release)
		if (pmctl->mctl_release(pmctl) < 0)
			pr_err("%s: mctl_release failed\n", __func__);
@@ -1086,10 +1080,9 @@ static int msm_close(struct file *f)
	D("%s index %d nodeid %d count %d\n", __func__, pcam_inst->my_index,
		pcam->vnode_id, pcam->use_count);
	pcam->dev_inst[pcam_inst->my_index] = NULL;
	if (pcam_inst->my_index == 0) {
		v4l2_fh_del(&pcam_inst->eventHandle);
		v4l2_fh_exit(&pcam_inst->eventHandle);
	}
	if (pcam_inst->my_index == 0)
		msm_destroy_v4l2_event_queue(&pcam_inst->eventHandle);

	CLR_VIDEO_INST_IDX(pcam_inst->inst_handle);
	CLR_IMG_MODE(pcam_inst->inst_handle);
	mutex_unlock(&pcam_inst->inst_lock);
@@ -1174,18 +1167,6 @@ long msm_v4l2_evt_notify(struct msm_cam_media_controller *mctl,
	return 0;
}

int msm_setup_v4l2_event_queue(struct v4l2_fh *eventHandle,
	struct video_device *pvdev)
{
	int rc = 0;
	/* v4l2_fh support */
	spin_lock_init(&pvdev->fh_lock);
	INIT_LIST_HEAD(&pvdev->fh_list);

	v4l2_fh_init(eventHandle, pvdev);
	v4l2_fh_add(eventHandle);
	return rc;
}

static struct v4l2_file_operations g_msm_fops = {
	.owner   = THIS_MODULE,
+2 −1
Original line number Diff line number Diff line
@@ -652,8 +652,9 @@ int msm_mctl_pp_done(
int msm_mctl_pp_divert_done(
	struct msm_cam_media_controller *p_mctl,
	void __user *arg);
int msm_setup_v4l2_event_queue(struct v4l2_fh *eventHandle,
void msm_setup_v4l2_event_queue(struct v4l2_fh *eventHandle,
	struct video_device *pvdev);
void msm_destroy_v4l2_event_queue(struct v4l2_fh *eventHandle);
int msm_setup_mctl_node(struct msm_cam_v4l2_device *pcam);
struct msm_cam_v4l2_dev_inst *msm_mctl_get_pcam_inst(
	struct msm_cam_media_controller *pmctl,
+5 −8
Original line number Diff line number Diff line
@@ -792,12 +792,9 @@ static int msm_mctl_dev_open(struct file *f)
	}

	D("%s active %d\n", __func__, pcam->mctl_node.active);
	rc = msm_setup_v4l2_event_queue(&pcam_inst->eventHandle,
	msm_setup_v4l2_event_queue(&pcam_inst->eventHandle,
			pcam->mctl_node.pvdev);
	if (rc < 0) {
		mutex_unlock(&pcam->mctl_node.dev_lock);
		return rc;
	}

	pcam_inst->vbqueue_initialized = 0;
	kref_get(&pmctl->refcount);
	f->private_data = &pcam_inst->eventHandle;
@@ -880,10 +877,10 @@ static int msm_mctl_dev_close(struct file *f)
		vb2_queue_release(&pcam_inst->vid_bufq);
	D("%s Closing down instance %p ", __func__, pcam_inst);
	pcam->mctl_node.dev_inst[pcam_inst->my_index] = NULL;
	v4l2_fh_del(&pcam_inst->eventHandle);
	v4l2_fh_exit(&pcam_inst->eventHandle);
	msm_destroy_v4l2_event_queue(&pcam_inst->eventHandle);
	CLR_MCTLPP_INST_IDX(pcam_inst->inst_handle);
	CLR_IMG_MODE(pcam_inst->inst_handle);

	mutex_destroy(&pcam_inst->inst_lock);

	kfree(pcam_inst);
+18 −13
Original line number Diff line number Diff line
@@ -96,6 +96,19 @@ int32_t msm_find_free_queue(void)
	return -EINVAL;
}

void msm_setup_v4l2_event_queue(struct v4l2_fh *eventHandle,
	struct video_device *pvdev)
{
	v4l2_fh_init(eventHandle, pvdev);
	v4l2_fh_add(eventHandle);
}

void msm_destroy_v4l2_event_queue(struct v4l2_fh *eventHandle)
{
	v4l2_fh_del(eventHandle);
	v4l2_fh_exit(eventHandle);
}

uint32_t msm_cam_server_get_mctl_handle(void)
{
	uint32_t i;
@@ -2092,16 +2105,10 @@ static int msm_setup_server_dev(struct platform_device *pdev)
	/*initialize fake video device and event queue*/

	g_server_dev.server_command_queue.pvdev = g_server_dev.video_dev;
	rc = msm_setup_v4l2_event_queue(
	msm_setup_v4l2_event_queue(
		&g_server_dev.server_command_queue.eventHandle,
		g_server_dev.server_command_queue.pvdev);

	if (rc < 0) {
		pr_err("%s failed to initialize event queue\n", __func__);
		video_device_release(g_server_dev.server_command_queue.pvdev);
		return rc;
	}

	for (i = 0; i < MAX_NUM_ACTIVE_CAMERA; i++) {
		struct msm_cam_server_queue *queue;
		queue = &g_server_dev.server_queue[i];
@@ -2831,14 +2838,12 @@ static int msm_setup_config_dev(int node, char *device_name)
		goto config_setup_fail;
	}

	rc = msm_setup_v4l2_event_queue(
	/* v4l2_fh support */
	spin_lock_init(&config_cam->config_stat_event_queue.pvdev->fh_lock);
	INIT_LIST_HEAD(&config_cam->config_stat_event_queue.pvdev->fh_list);
	msm_setup_v4l2_event_queue(
		&config_cam->config_stat_event_queue.eventHandle,
		config_cam->config_stat_event_queue.pvdev);
	if (rc < 0) {
		pr_err("%s failed to initialize event queue\n", __func__);
		video_device_release(config_cam->config_stat_event_queue.pvdev);
		goto config_setup_fail;
	}

	return rc;