diff mbox series

[v2,4/6] media: coda: split marking last meta into helper function

Message ID 20200318183536.15779-5-p.zabel@pengutronix.de
State New
Headers show
Series [v2,1/6] media: coda: round up decoded buffer size for all codecs | expand

Commit Message

Philipp Zabel March 18, 2020, 6:35 p.m. UTC
Split marking the last metadata entry into a helper function to simplify
coda_decoder_cmd.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
New in v2.
---
 drivers/media/platform/coda/coda-common.c | 36 ++++++++++++++---------
 1 file changed, 22 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
index 09244696f132..a06765e69d63 100644
--- a/drivers/media/platform/coda/coda-common.c
+++ b/drivers/media/platform/coda/coda-common.c
@@ -1152,6 +1152,26 @@  static int coda_try_decoder_cmd(struct file *file, void *fh,
 	return v4l2_m2m_ioctl_try_decoder_cmd(file, fh, dc);
 }
 
+static bool coda_mark_last_meta(struct coda_ctx *ctx)
+{
+	struct coda_buffer_meta *meta;
+
+	coda_dbg(1, ctx, "marking last meta\n");
+
+	spin_lock(&ctx->buffer_meta_lock);
+	if (list_empty(&ctx->buffer_meta_list)) {
+		spin_unlock(&ctx->buffer_meta_lock);
+		return false;
+	}
+
+	meta = list_last_entry(&ctx->buffer_meta_list, struct coda_buffer_meta,
+			       list);
+	meta->last = true;
+
+	spin_unlock(&ctx->buffer_meta_lock);
+	return true;
+}
+
 static int coda_decoder_cmd(struct file *file, void *fh,
 			    struct v4l2_decoder_cmd *dc)
 {
@@ -1196,22 +1216,10 @@  static int coda_decoder_cmd(struct file *file, void *fh,
 				stream_end = true;
 			}
 		} else {
-			coda_dbg(1, ctx, "marking last meta\n");
-
-			/* Mark last meta */
-			spin_lock(&ctx->buffer_meta_lock);
-			if (!list_empty(&ctx->buffer_meta_list)) {
-				struct coda_buffer_meta *meta;
-
-				meta = list_last_entry(&ctx->buffer_meta_list,
-						       struct coda_buffer_meta,
-						       list);
-				meta->last = true;
+			if (coda_mark_last_meta(ctx))
 				stream_end = true;
-			} else {
+			else
 				wakeup = true;
-			}
-			spin_unlock(&ctx->buffer_meta_lock);
 		}
 
 		if (stream_end) {