Thread (51 messages) 51 messages, 9 authors, 2018-09-07

[PATCH 2/9] media: cedrus: Add wrappers around container_of for our buffers

From: Paul Kocialkowski <hidden>
Date: 2018-06-21 09:03:29
Also in: linux-media, lkml

Hi,

On Wed, 2018-06-13 at 16:07 +0200, Maxime Ripard wrote:
quoted hunk ↗ jump to hunk
The cedrus driver sub-classes the vb2_v4l2_buffer structure, but doesn't
provide any function to wrap around the proper container_of call that needs
to be duplicated in every calling site.

Add wrappers to make sure its opaque to the users and they don't have to
care anymore.

Signed-off-by: Maxime Ripard <redacted>
---
 .../platform/sunxi/cedrus/sunxi_cedrus_common.h      | 12 ++++++++++++
 .../media/platform/sunxi/cedrus/sunxi_cedrus_hw.c    |  4 ++--
 2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h
index ee6883ef9cb7..b1ed1c8cb130 100644
--- a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h
+++ b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h
@@ -89,6 +89,18 @@ struct sunxi_cedrus_buffer {
 	struct list_head list;
 };
 
+static inline
I'm not a big fan of spreading the type qualifiers on two distinct lines
instead of having a longer single line (reminds me of the GNU coding
style a bit), but this is purely cosmetic.

Cheers,

Paul
quoted hunk ↗ jump to hunk
+struct sunxi_cedrus_buffer *vb2_v4l2_to_cedrus_buffer(const struct vb2_v4l2_buffer *p)
+{
+	return container_of(p, struct sunxi_cedrus_buffer, vb);
+}
+
+static inline
+struct sunxi_cedrus_buffer *vb2_to_cedrus_buffer(const struct vb2_buffer *p)
+{
+	return vb2_v4l2_to_cedrus_buffer(to_vb2_v4l2_buffer(p));
+}
+
 struct sunxi_cedrus_dev {
 	struct v4l2_device v4l2_dev;
 	struct video_device vfd;
diff --git a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c
index 5783bd985855..fc688a5c1ea3 100644
--- a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c
+++ b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c
@@ -108,8 +108,8 @@ static irqreturn_t sunxi_cedrus_ve_irq(int irq, void *dev_id)
 		return IRQ_HANDLED;
 	}
 
-	src_buffer = container_of(src_vb, struct sunxi_cedrus_buffer, vb);
-	dst_buffer = container_of(dst_vb, struct sunxi_cedrus_buffer, vb);
+	src_buffer = vb2_v4l2_to_cedrus_buffer(src_vb);
+	dst_buffer = vb2_v4l2_to_cedrus_buffer(dst_vb);
 
 	/* First bit of MPEG_STATUS indicates success. */
 	if (ctx->job_abort || !(status & 0x01))
-- 
Paul Kocialkowski, Bootlin (formerly Free Electrons)
Embedded Linux and kernel engineering
https://bootlin.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20180621/33933c40/attachment.sig>
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help