All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: Dave Gordon <david.s.gordon@intel.com>
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH 3/9] drm/i915: Wrap drm_gem_object_lookup in i915_gem_object_lookup
Date: Wed, 20 Jul 2016 12:38:20 +0100	[thread overview]
Message-ID: <20160720113820.GO17604@nuc-i3427.alporthouse.com> (raw)
In-Reply-To: <578F6050.7090701@intel.com>

On Wed, Jul 20, 2016 at 12:28:16PM +0100, Dave Gordon wrote:
> On 20/07/16 09:59, Chris Wilson wrote:
> >For symmetry with a forthcoming i915_gem_object_get() and
> >i915_gem_object_pu().
> >
> >Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> >---
> >  drivers/gpu/drm/i915/i915_drv.h        | 20 +++++++++++-
> >  drivers/gpu/drm/i915/i915_gem.c        | 58 +++++++++++++++++-----------------
> >  drivers/gpu/drm/i915/i915_gem_tiling.c |  8 ++---
> >  drivers/gpu/drm/i915/intel_display.c   |  4 +--
> >  drivers/gpu/drm/i915/intel_overlay.c   |  5 ++-
> >  5 files changed, 56 insertions(+), 39 deletions(-)
> >
> >diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> >index 2131e7f1e57a..47f244f9c64e 100644
> >--- a/drivers/gpu/drm/i915/i915_drv.h
> >+++ b/drivers/gpu/drm/i915/i915_drv.h
> >@@ -2286,7 +2286,25 @@ struct drm_i915_gem_object {
> >  		} userptr;
> >  	};
> >  };
> >-#define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
> >+
> >+static inline struct drm_i915_gem_object *
> >+to_intel_bo(struct drm_gem_object *gem)
> >+{
> >+	/* Assert that to_intel_bo(NULL) == NULL */
> >+	BUILD_BUG_ON(offsetof(struct drm_i915_gem_object, base));
> >+
> >+	return container_of(gem, struct drm_i915_gem_object, base);
> >+}
> 
> Yes, I think this is a much better way of doing the conversion, 'cos
> it's type-safe and we get that all-important check that 'base' is
> still at offset 0.
> 
> In my variant on this, I also introduced the reverse mapping,
> to_gem_object(), so that we could completely abstract away the
> conversion back-and-forth between the two classes. Do you think that
> would be worth adding here too?

The convention is that the downcast is tidied away, but as the upcast is
just &foo->bar that is easy enough on the eyes. There is also the
problem of a limited namespace, so picking who should be to_foo() and
to_bar() is tricky. (Without delving into huge polymorphic macros.)
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2016-07-20 11:38 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-20  8:59 A simple batch of churn to make reference handling look consistent Chris Wilson
2016-07-20  8:59 ` [PATCH 1/9] drm/i915: Rename request reference/unreference to get/put Chris Wilson
2016-07-20  8:59 ` [PATCH 2/9] drm/i915: Rename i915_gem_context_reference/unreference() Chris Wilson
2016-07-20  8:59 ` [PATCH 3/9] drm/i915: Wrap drm_gem_object_lookup in i915_gem_object_lookup Chris Wilson
2016-07-20 11:28   ` Dave Gordon
2016-07-20 11:38     ` Chris Wilson [this message]
2016-07-20 11:38   ` Joonas Lahtinen
2016-07-20 12:03     ` Chris Wilson
2016-07-20  8:59 ` [PATCH 4/9] drm/i915: Wrap drm_gem_object_reference in i915_gem_object_get Chris Wilson
2016-07-20 11:38   ` Dave Gordon
2016-07-20 11:45     ` Chris Wilson
2016-07-20 11:45   ` Joonas Lahtinen
2016-07-20  8:59 ` [PATCH 5/9] drm/i915: Rename drm_gem_object_unreference in preparation for lockless free Chris Wilson
2016-07-20 11:43   ` Joonas Lahtinen
2016-07-20 11:51     ` Dave Gordon
2016-07-20 12:11       ` Chris Wilson
2016-07-21 16:58   ` [PATCH] drm/i915: use i915_gem_object_put_unlocked() after releasing mutex Dave Gordon
2016-07-21 17:25     ` Chris Wilson
2016-07-20  8:59 ` [PATCH 6/9] drm/i915: Rename drm_gem_object_unreference_unlocked in preparation for lockless free Chris Wilson
2016-07-20 12:04   ` Joonas Lahtinen
2016-07-20  9:00 ` [PATCH 7/9] drm/i915: Treat ringbuffer writes as write to normal memory Chris Wilson
2016-07-20  9:00 ` [PATCH 8/9] drm/i915: Rename ring->virtual_start as ring->vaddr Chris Wilson
2016-07-20 11:54   ` Dave Gordon
2016-07-20 12:07   ` Joonas Lahtinen
2016-07-20  9:00 ` [PATCH 9/9] drm/i915: Convert i915_semaphores_is_enabled over to early sanitize Chris Wilson
2016-07-20 12:18   ` Joonas Lahtinen
2016-07-20  9:38 ` ✗ Ro.CI.BAT: failure for series starting with [1/9] drm/i915: Rename request reference/unreference to get/put Patchwork
2016-07-22  5:28 ` ✗ Ro.CI.BAT: failure for series starting with [1/9] drm/i915: Rename request reference/unreference to get/put (rev2) Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160720113820.GO17604@nuc-i3427.alporthouse.com \
    --to=chris@chris-wilson.co.uk \
    --cc=david.s.gordon@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.