All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/vc4: Rework the structure convertion functions
@ 2020-10-28 12:37 Maxime Ripard
  2020-10-28 13:49 ` Dave Stevenson
  0 siblings, 1 reply; 3+ messages in thread
From: Maxime Ripard @ 2020-10-28 12:37 UTC (permalink / raw)
  To: Daniel Vetter, David Airlie, Maarten Lankhorst,
	Thomas Zimmermann, Maxime Ripard, Eric Anholt
  Cc: dri-devel, Dave Stevenson

Most of the helpers to retrieve vc4 structures from the DRM base structures
rely on the fact that the first member of the vc4 structure is the DRM one
and just cast the pointers between them.

However, this is pretty fragile especially since there's no check to make
sure that the DRM structure is indeed at the offset 0 in the structure, so
let's use container_of to make it more robust.

Signed-off-by: Maxime Ripard <maxime@cerno.tech>
---
 drivers/gpu/drm/vc4/vc4_drv.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/vc4/vc4_drv.h b/drivers/gpu/drm/vc4/vc4_drv.h
index 236dde0bb9a1..836fdca5e643 100644
--- a/drivers/gpu/drm/vc4/vc4_drv.h
+++ b/drivers/gpu/drm/vc4/vc4_drv.h
@@ -287,7 +287,7 @@ struct vc4_bo {
 static inline struct vc4_bo *
 to_vc4_bo(struct drm_gem_object *bo)
 {
-	return (struct vc4_bo *)bo;
+	return container_of(to_drm_gem_cma_obj(bo), struct vc4_bo, base);
 }
 
 struct vc4_fence {
@@ -300,7 +300,7 @@ struct vc4_fence {
 static inline struct vc4_fence *
 to_vc4_fence(struct dma_fence *fence)
 {
-	return (struct vc4_fence *)fence;
+	return container_of(fence, struct vc4_fence, base);
 }
 
 struct vc4_seqno_cb {
@@ -347,7 +347,7 @@ struct vc4_plane {
 static inline struct vc4_plane *
 to_vc4_plane(struct drm_plane *plane)
 {
-	return (struct vc4_plane *)plane;
+	return container_of(plane, struct vc4_plane, base);
 }
 
 enum vc4_scaling_mode {
@@ -423,7 +423,7 @@ struct vc4_plane_state {
 static inline struct vc4_plane_state *
 to_vc4_plane_state(struct drm_plane_state *state)
 {
-	return (struct vc4_plane_state *)state;
+	return container_of(state, struct vc4_plane_state, base);
 }
 
 enum vc4_encoder_type {
@@ -499,7 +499,7 @@ struct vc4_crtc {
 static inline struct vc4_crtc *
 to_vc4_crtc(struct drm_crtc *crtc)
 {
-	return (struct vc4_crtc *)crtc;
+	return container_of(crtc, struct vc4_crtc, base);
 }
 
 static inline const struct vc4_crtc_data *
@@ -537,7 +537,7 @@ struct vc4_crtc_state {
 static inline struct vc4_crtc_state *
 to_vc4_crtc_state(struct drm_crtc_state *crtc_state)
 {
-	return (struct vc4_crtc_state *)crtc_state;
+	return container_of(crtc_state, struct vc4_crtc_state, base);
 }
 
 #define V3D_READ(offset) readl(vc4->v3d->regs + offset)
-- 
2.26.2

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/vc4: Rework the structure convertion functions
  2020-10-28 12:37 [PATCH] drm/vc4: Rework the structure convertion functions Maxime Ripard
@ 2020-10-28 13:49 ` Dave Stevenson
  2020-10-29  9:26   ` Maxime Ripard
  0 siblings, 1 reply; 3+ messages in thread
From: Dave Stevenson @ 2020-10-28 13:49 UTC (permalink / raw)
  To: Maxime Ripard
  Cc: David Airlie, DRI Development, Thomas Zimmermann, Daniel Vetter

s/convertion/conversion in subject line

On Wed, 28 Oct 2020 at 12:37, Maxime Ripard <maxime@cerno.tech> wrote:
>
> Most of the helpers to retrieve vc4 structures from the DRM base structures
> rely on the fact that the first member of the vc4 structure is the DRM one
> and just cast the pointers between them.
>
> However, this is pretty fragile especially since there's no check to make
> sure that the DRM structure is indeed at the offset 0 in the structure, so
> let's use container_of to make it more robust.
>
> Signed-off-by: Maxime Ripard <maxime@cerno.tech>

Otherwise
Reviewed-by: Dave Stevenson <dave.stevenson@raspberrypi.com>

> ---
>  drivers/gpu/drm/vc4/vc4_drv.h | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/vc4/vc4_drv.h b/drivers/gpu/drm/vc4/vc4_drv.h
> index 236dde0bb9a1..836fdca5e643 100644
> --- a/drivers/gpu/drm/vc4/vc4_drv.h
> +++ b/drivers/gpu/drm/vc4/vc4_drv.h
> @@ -287,7 +287,7 @@ struct vc4_bo {
>  static inline struct vc4_bo *
>  to_vc4_bo(struct drm_gem_object *bo)
>  {
> -       return (struct vc4_bo *)bo;
> +       return container_of(to_drm_gem_cma_obj(bo), struct vc4_bo, base);
>  }
>
>  struct vc4_fence {
> @@ -300,7 +300,7 @@ struct vc4_fence {
>  static inline struct vc4_fence *
>  to_vc4_fence(struct dma_fence *fence)
>  {
> -       return (struct vc4_fence *)fence;
> +       return container_of(fence, struct vc4_fence, base);
>  }
>
>  struct vc4_seqno_cb {
> @@ -347,7 +347,7 @@ struct vc4_plane {
>  static inline struct vc4_plane *
>  to_vc4_plane(struct drm_plane *plane)
>  {
> -       return (struct vc4_plane *)plane;
> +       return container_of(plane, struct vc4_plane, base);
>  }
>
>  enum vc4_scaling_mode {
> @@ -423,7 +423,7 @@ struct vc4_plane_state {
>  static inline struct vc4_plane_state *
>  to_vc4_plane_state(struct drm_plane_state *state)
>  {
> -       return (struct vc4_plane_state *)state;
> +       return container_of(state, struct vc4_plane_state, base);
>  }
>
>  enum vc4_encoder_type {
> @@ -499,7 +499,7 @@ struct vc4_crtc {
>  static inline struct vc4_crtc *
>  to_vc4_crtc(struct drm_crtc *crtc)
>  {
> -       return (struct vc4_crtc *)crtc;
> +       return container_of(crtc, struct vc4_crtc, base);
>  }
>
>  static inline const struct vc4_crtc_data *
> @@ -537,7 +537,7 @@ struct vc4_crtc_state {
>  static inline struct vc4_crtc_state *
>  to_vc4_crtc_state(struct drm_crtc_state *crtc_state)
>  {
> -       return (struct vc4_crtc_state *)crtc_state;
> +       return container_of(crtc_state, struct vc4_crtc_state, base);
>  }
>
>  #define V3D_READ(offset) readl(vc4->v3d->regs + offset)
> --
> 2.26.2
>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/vc4: Rework the structure convertion functions
  2020-10-28 13:49 ` Dave Stevenson
@ 2020-10-29  9:26   ` Maxime Ripard
  0 siblings, 0 replies; 3+ messages in thread
From: Maxime Ripard @ 2020-10-29  9:26 UTC (permalink / raw)
  To: Dave Stevenson
  Cc: David Airlie, DRI Development, Thomas Zimmermann, Daniel Vetter


[-- Attachment #1.1: Type: text/plain, Size: 801 bytes --]

On Wed, Oct 28, 2020 at 01:49:29PM +0000, Dave Stevenson wrote:
> s/convertion/conversion in subject line
> 
> On Wed, 28 Oct 2020 at 12:37, Maxime Ripard <maxime@cerno.tech> wrote:
> >
> > Most of the helpers to retrieve vc4 structures from the DRM base structures
> > rely on the fact that the first member of the vc4 structure is the DRM one
> > and just cast the pointers between them.
> >
> > However, this is pretty fragile especially since there's no check to make
> > sure that the DRM structure is indeed at the offset 0 in the structure, so
> > let's use container_of to make it more robust.
> >
> > Signed-off-by: Maxime Ripard <maxime@cerno.tech>
> 
> Otherwise
> Reviewed-by: Dave Stevenson <dave.stevenson@raspberrypi.com>

Fixed the typo and applied, thanks!
Maxime

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-10-30  8:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-28 12:37 [PATCH] drm/vc4: Rework the structure convertion functions Maxime Ripard
2020-10-28 13:49 ` Dave Stevenson
2020-10-29  9:26   ` Maxime Ripard

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.