diff mbox

[PATCHv16,28/34] v4l2-mem2mem: Simplify exiting the function in v4l2_m2m_try_schedule

Message ID e42d2233aa2395b10d3b59e43b7b224e2105d94f.camel@collabora.com (mailing list archive)
State New, archived
Headers show

Commit Message

Ezequiel Garcia July 11, 2018, 11:26 p.m. UTC
Hi Hans, Sakari:

On Thu, 2018-07-05 at 18:03 +0200, Hans Verkuil wrote:
> From: Sakari Ailus <sakari.ailus@linux.intel.com>
> 
> The v4l2_m2m_try_schedule function acquires and releases multiple
> spinlocks; simplify unlocking the job lock by adding a label to unlock the
> job lock and exit the function.
> 
> 

Why not just going the whole way and do the same for the other spinlocks?

Something along these lines:
diff mbox

Patch

diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c
index 114d50cf22c5..565b5946d907 100644
--- a/drivers/media/v4l2-core/v4l2-mem2mem.c
+++ b/drivers/media/v4l2-core/v4l2-mem2mem.c
@@ -253,31 +253,25 @@  void v4l2_m2m_try_schedule(struct v4l2_m2m_ctx *m2m_ctx)
 	/* If the context is aborted then don't schedule it */
 	if (m2m_ctx->job_flags & TRANS_ABORT) {
 		dprintk("Aborted context\n");
-		goto out_unlock;
+		goto job_unlock;
 	}
 
 	if (m2m_ctx->job_flags & TRANS_QUEUED) {
 		dprintk("On job queue already\n");
-		goto out_unlock;
+		goto job_unlock;
 	}
 
 	spin_lock_irqsave(&m2m_ctx->out_q_ctx.rdy_spinlock, flags_out);
 	if (list_empty(&m2m_ctx->out_q_ctx.rdy_queue)
 	    && !m2m_ctx->out_q_ctx.buffered) {
-		spin_unlock_irqrestore(&m2m_ctx->out_q_ctx.rdy_spinlock,
-					flags_out);
 		dprintk("No input buffers available\n");
 		goto out_unlock;
 	}
 	spin_lock_irqsave(&m2m_ctx->cap_q_ctx.rdy_spinlock, flags_cap);
 	if (list_empty(&m2m_ctx->cap_q_ctx.rdy_queue)
 	    && !m2m_ctx->cap_q_ctx.buffered) {
-		spin_unlock_irqrestore(&m2m_ctx->cap_q_ctx.rdy_spinlock,
-					flags_cap);
-		spin_unlock_irqrestore(&m2m_ctx->out_q_ctx.rdy_spinlock,
-					flags_out);
 		dprintk("No output buffers available\n");
-		goto out_unlock;
+		goto cap_unlock;
 	}
 	spin_unlock_irqrestore(&m2m_ctx->cap_q_ctx.rdy_spinlock, flags_cap);
 	spin_unlock_irqrestore(&m2m_ctx->out_q_ctx.rdy_spinlock, flags_out);
@@ -297,7 +291,11 @@  void v4l2_m2m_try_schedule(struct v4l2_m2m_ctx *m2m_ctx)
 
 	return;
 
+cap_unlock:
+	spin_unlock_irqrestore(&m2m_ctx->cap_q_ctx.rdy_spinlock, flags_cap);
 out_unlock:
+	spin_unlock_irqrestore(&m2m_ctx->out_q_ctx.rdy_spinlock, flags_out);
+job_unlock:
 	spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags_job);
 
 	return;