Linux-Media Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v4l-utils] v4l-helpers.h: count mappings separately from buffers
@ 2019-08-13 13:14 Philipp Zabel
  0 siblings, 0 replies; only message in thread
From: Philipp Zabel @ 2019-08-13 13:14 UTC (permalink / raw)
  To: linux-media

This is required to avoid leaking mapped buffers when trying to unmap
after reqbufs(0), to test buffer orphaning.

Fixes: 6300b376cb3e ("v4l2-compliance: test orphaned buffer support");
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 utils/common/v4l-helpers.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/utils/common/v4l-helpers.h b/utils/common/v4l-helpers.h
index d12f2745ef23..c37124e41efe 100644
--- a/utils/common/v4l-helpers.h
+++ b/utils/common/v4l-helpers.h
@@ -1406,6 +1406,7 @@ struct v4l_queue {
 	unsigned type;
 	unsigned memory;
 	unsigned buffers;
+	unsigned mappings;
 	unsigned num_planes;
 	unsigned capabilities;
 
@@ -1432,6 +1433,7 @@ static inline void v4l_queue_init(struct v4l_queue *q,
 static inline unsigned v4l_queue_g_type(const struct v4l_queue *q) { return q->type; }
 static inline unsigned v4l_queue_g_memory(const struct v4l_queue *q) { return q->memory; }
 static inline unsigned v4l_queue_g_buffers(const struct v4l_queue *q) { return q->buffers; }
+static inline unsigned v4l_queue_g_mappings(const struct v4l_queue *q) { return q->mappings; }
 static inline unsigned v4l_queue_g_num_planes(const struct v4l_queue *q) { return q->num_planes; }
 static inline unsigned v4l_queue_g_capabilities(const struct v4l_queue *q) { return q->capabilities; }
 
@@ -1452,7 +1454,7 @@ static inline void v4l_queue_s_mmapping(struct v4l_queue *q, unsigned index, uns
 
 static inline void *v4l_queue_g_mmapping(const struct v4l_queue *q, unsigned index, unsigned plane)
 {
-	if (index >= v4l_queue_g_buffers(q) || plane >= v4l_queue_g_num_planes(q))
+	if (index >= v4l_queue_g_mappings(q) || plane >= v4l_queue_g_num_planes(q))
 		return NULL;
 	return q->mmappings[index][plane];
 }
@@ -1591,6 +1593,7 @@ static inline int v4l_queue_mmap_bufs(struct v4l_fd *f,
 			v4l_queue_s_mmapping(q, b, p, m);
 		}
 	}
+	q->mappings = b;
 	return 0;
 }
 static inline int v4l_queue_munmap_bufs(struct v4l_fd *f, struct v4l_queue *q,
@@ -1602,7 +1605,7 @@ static inline int v4l_queue_munmap_bufs(struct v4l_fd *f, struct v4l_queue *q,
 	if (q->memory != V4L2_MEMORY_MMAP && q->memory != V4L2_MEMORY_DMABUF)
 		return 0;
 
-	for (b = from; b < v4l_queue_g_buffers(q); b++) {
+	for (b = from; b < v4l_queue_g_mappings(q); b++) {
 		for (p = 0; p < v4l_queue_g_num_planes(q); p++) {
 			void *m = v4l_queue_g_mmapping(q, b, p);
 
@@ -1618,6 +1621,7 @@ static inline int v4l_queue_munmap_bufs(struct v4l_fd *f, struct v4l_queue *q,
 			v4l_queue_s_mmapping(q, b, p, NULL);
 		}
 	}
+	q->mappings = from;
 	return 0;
 }
 
-- 
2.20.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-13 13:14 [PATCH v4l-utils] v4l-helpers.h: count mappings separately from buffers Philipp Zabel

Linux-Media Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-media/0 linux-media/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-media linux-media/ https://lore.kernel.org/linux-media \
		linux-media@vger.kernel.org linux-media@archiver.kernel.org
	public-inbox-index linux-media


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-media


AGPL code for this site: git clone https://public-inbox.org/ public-inbox