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

Commit f666ecbd authored by annamraj's avatar annamraj Committed by Gerrit - the friendly Code Review server
Browse files

msm: camera: Avoid deadlock for vb2 operations using separate lock



Use mutex lock for all VB2 operations, and use separatelock other
than used for stop streaming operation to avoid dead lock.

Change-Id: Idba956e5e3bce48ee57eaa5984786ded218e32d5
Signed-off-by: default avatarannamraj <annamraj@codeaurora.org>
parent c3cad444
Loading
Loading
Loading
Loading
+15 −6
Original line number Diff line number Diff line
@@ -432,6 +432,7 @@ static int msm_fd_open(struct file *file)
	ctx->vb2_q.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
	ctx->vb2_q.io_modes = VB2_USERPTR;
	ctx->vb2_q.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
	mutex_init(&ctx->lock);
	ret = vb2_queue_init(&ctx->vb2_q);
	if (ret < 0) {
		dev_err(device->dev, "Error queue init\n");
@@ -482,7 +483,9 @@ static int msm_fd_release(struct file *file)
	msm_cpp_vbif_register_error_handler((void *)ctx,
		VBIF_CLIENT_FD, NULL);

	mutex_lock(&ctx->lock);
	vb2_queue_release(&ctx->vb2_q);
	mutex_unlock(&ctx->lock);

	vfree(ctx->stats);

@@ -512,7 +515,9 @@ static unsigned int msm_fd_poll(struct file *file,
	struct fd_ctx *ctx = msm_fd_ctx_from_fh(file->private_data);
	unsigned int ret;

	mutex_lock(&ctx->lock);
	ret = vb2_poll(&ctx->vb2_q, file, wait);
	mutex_unlock(&ctx->lock);

	if (atomic_read(&ctx->subscribed_for_event)) {
		poll_wait(file, &ctx->fh.wait, wait);
@@ -750,9 +755,9 @@ static int msm_fd_reqbufs(struct file *file,
	int ret;
	struct fd_ctx *ctx = msm_fd_ctx_from_fh(fh);

	mutex_lock(&ctx->fd_device->recovery_lock);
	mutex_lock(&ctx->lock);
	ret = vb2_reqbufs(&ctx->vb2_q, req);
	mutex_unlock(&ctx->fd_device->recovery_lock);
	mutex_unlock(&ctx->lock);
	return ret;
}

@@ -768,9 +773,9 @@ static int msm_fd_qbuf(struct file *file, void *fh,
	int ret;
	struct fd_ctx *ctx = msm_fd_ctx_from_fh(fh);

	mutex_lock(&ctx->fd_device->recovery_lock);
	mutex_lock(&ctx->lock);
	ret = vb2_qbuf(&ctx->vb2_q, pb);
	mutex_unlock(&ctx->fd_device->recovery_lock);
	mutex_unlock(&ctx->lock);
	return ret;

}
@@ -787,9 +792,9 @@ static int msm_fd_dqbuf(struct file *file,
	int ret;
	struct fd_ctx *ctx = msm_fd_ctx_from_fh(fh);

	mutex_lock(&ctx->fd_device->recovery_lock);
	mutex_lock(&ctx->lock);
	ret = vb2_dqbuf(&ctx->vb2_q, pb, file->f_flags & O_NONBLOCK);
	mutex_unlock(&ctx->fd_device->recovery_lock);
	mutex_unlock(&ctx->lock);
	return ret;
}

@@ -805,7 +810,9 @@ static int msm_fd_streamon(struct file *file,
	struct fd_ctx *ctx = msm_fd_ctx_from_fh(fh);
	int ret;

	mutex_lock(&ctx->lock);
	ret = vb2_streamon(&ctx->vb2_q, buf_type);
	mutex_unlock(&ctx->lock);
	if (ret < 0)
		dev_err(ctx->fd_device->dev, "Stream on fails\n");

@@ -824,7 +831,9 @@ static int msm_fd_streamoff(struct file *file,
	struct fd_ctx *ctx = msm_fd_ctx_from_fh(fh);
	int ret;

	mutex_lock(&ctx->lock);
	ret = vb2_streamoff(&ctx->vb2_q, buf_type);
	mutex_unlock(&ctx->lock);
	if (ret < 0)
		dev_err(ctx->fd_device->dev, "Stream off fails\n");

+2 −1
Original line number Diff line number Diff line
/* Copyright (c) 2014-2016, The Linux Foundation. All rights reserved.
/* Copyright (c) 2014-2017, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -161,6 +161,7 @@ struct fd_ctx {
	struct msm_fd_mem_pool mem_pool;
	struct msm_fd_stats *stats;
	struct msm_fd_buf_handle work_buf;
	struct mutex lock;
};

/*