diff mbox

[v2,1/8] drm/atomic: Avoid connector to writeback_connector casts

Message ID 20180629111722.20299-2-boris.brezillon@bootlin.com (mailing list archive)
State New, archived
Headers show

Commit Message

Boris Brezillon June 29, 2018, 11:17 a.m. UTC
Use container_of() instead of type casting so that it keeps working
even if base is moved inside the drm_writeback_connector struct.

Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
---
 drivers/gpu/drm/drm_atomic.c | 4 +++-
 include/drm/drm_writeback.h  | 6 ++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

Comments

Daniel Vetter July 2, 2018, 7:49 a.m. UTC | #1
On Fri, Jun 29, 2018 at 01:17:14PM +0200, Boris Brezillon wrote:
> Use container_of() instead of type casting so that it keeps working
> even if base is moved inside the drm_writeback_connector struct.
> 
> Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>

Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> ---
>  drivers/gpu/drm/drm_atomic.c | 4 +++-
>  include/drm/drm_writeback.h  | 6 ++++++
>  2 files changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index 178842380f75..6ea20d5dee66 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -2423,6 +2423,7 @@ static int prepare_signaling(struct drm_device *dev,
>  	}
>  
>  	for_each_new_connector_in_state(state, conn, conn_state, i) {
> +		struct drm_writeback_connector *wb_conn;
>  		struct drm_writeback_job *job;
>  		struct drm_out_fence_state *f;
>  		struct dma_fence *fence;
> @@ -2446,7 +2447,8 @@ static int prepare_signaling(struct drm_device *dev,
>  		f[*num_fences].out_fence_ptr = fence_ptr;
>  		*fence_state = f;
>  
> -		fence = drm_writeback_get_out_fence((struct drm_writeback_connector *)conn);
> +		wb_conn = drm_connector_to_writeback(conn);
> +		fence = drm_writeback_get_out_fence(wb_conn);
>  		if (!fence)
>  			return -ENOMEM;
>  
> diff --git a/include/drm/drm_writeback.h b/include/drm/drm_writeback.h
> index a10fe556dfd4..23df9d463003 100644
> --- a/include/drm/drm_writeback.h
> +++ b/include/drm/drm_writeback.h
> @@ -110,6 +110,12 @@ struct drm_writeback_job {
>  	struct dma_fence *out_fence;
>  };
>  
> +static inline struct drm_writeback_connector *
> +drm_connector_to_writeback(struct drm_connector *connector)
> +{
> +	return container_of(connector, struct drm_writeback_connector, base);
> +}
> +
>  int drm_writeback_connector_init(struct drm_device *dev,
>  				 struct drm_writeback_connector *wb_connector,
>  				 const struct drm_connector_funcs *con_funcs,
> -- 
> 2.14.1
>
diff mbox

Patch

diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index 178842380f75..6ea20d5dee66 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -2423,6 +2423,7 @@  static int prepare_signaling(struct drm_device *dev,
 	}
 
 	for_each_new_connector_in_state(state, conn, conn_state, i) {
+		struct drm_writeback_connector *wb_conn;
 		struct drm_writeback_job *job;
 		struct drm_out_fence_state *f;
 		struct dma_fence *fence;
@@ -2446,7 +2447,8 @@  static int prepare_signaling(struct drm_device *dev,
 		f[*num_fences].out_fence_ptr = fence_ptr;
 		*fence_state = f;
 
-		fence = drm_writeback_get_out_fence((struct drm_writeback_connector *)conn);
+		wb_conn = drm_connector_to_writeback(conn);
+		fence = drm_writeback_get_out_fence(wb_conn);
 		if (!fence)
 			return -ENOMEM;
 
diff --git a/include/drm/drm_writeback.h b/include/drm/drm_writeback.h
index a10fe556dfd4..23df9d463003 100644
--- a/include/drm/drm_writeback.h
+++ b/include/drm/drm_writeback.h
@@ -110,6 +110,12 @@  struct drm_writeback_job {
 	struct dma_fence *out_fence;
 };
 
+static inline struct drm_writeback_connector *
+drm_connector_to_writeback(struct drm_connector *connector)
+{
+	return container_of(connector, struct drm_writeback_connector, base);
+}
+
 int drm_writeback_connector_init(struct drm_device *dev,
 				 struct drm_writeback_connector *wb_connector,
 				 const struct drm_connector_funcs *con_funcs,