[Intel-gfx] [PATCH] drm/i915: Convert dev_priv->dev backpointers to dev_priv->drm

Dave Gordon david.s.gordon at intel.com
Tue Jul 5 13:53:03 UTC 2016


On 05/07/16 09:51, Chris Wilson wrote:
> Since drm_i915_private is now a subclass of drm_device we do not need to
> chase the drm_i915_private->dev backpointer and can instead simply
> access drm_i915_private->drm directly.
>
>     text	   data	    bss	    dec	    hex	filename
> 1068757	   4565	    416	1073738	 10624a	drivers/gpu/drm/i915/i915.ko
> 1066949	   4565	    416	1071930	 105b3a	drivers/gpu/drm/i915/i915.ko
>
> Created by the coccinelle script:
> @@
> struct drm_i915_private *d;
> identifier i;
> @@
> (
> - d->dev->i
> + d->drm.i
> |
> - d->dev
> + &d->drm
> )
>
> and for good measure the dev_priv->dev backpointer was removed entirely.
>
> Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

How about doing this with a macro, to isolate the users of the 
conversion from the actual layout of the drm/private pair? The caller 
need not know how one actually gets from one to the other, whether it's 
by following a pointer, finding a containing parent, locating a member, 
or just casting the pointer; the conversion macro encapsulates all that.

#define	to_drm(dev_priv)	(&dev_priv->drm)

and thus at the point of use:

-	struct drm_device *dev = dev_priv->dev;
+	struct drm_device *dev = to_drm(dev_priv);

etc. And the even simpler Cocci:

@@
struct drm_i915_private *d;
@@
- d->dev
+ to_drm(d)

.Dave.


More information about the Intel-gfx mailing list