[PATCH libdrm 4.1/17] intel: introduce to_bo_gem() helper

Emil Velikov emil.l.velikov at gmail.com
Mon Aug 31 12:47:17 PDT 2015


...to minimise misuse of bo_gem.
If the variable is declared at the top of the function and then used
for two (or more) different contexts this can cause confusion and errors.

Just introduce a wrapper, which can be used in a once off situations.

Suggested-by: Chris Wilson <chris at chris-wilson.co.uk>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---
 intel/intel_bufmgr_gem.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/intel/intel_bufmgr_gem.c b/intel/intel_bufmgr_gem.c
index 5287419..63122d0 100644
--- a/intel/intel_bufmgr_gem.c
+++ b/intel/intel_bufmgr_gem.c
@@ -276,6 +276,11 @@ static void drm_intel_gem_bo_unreference(drm_intel_bo *bo);
 
 static void drm_intel_gem_bo_free(drm_intel_bo *bo);
 
+static inline drm_intel_bo_gem *to_bo_gem(drm_intel_bo *bo)
+{
+        return (drm_intel_bo_gem *)bo;
+}
+
 static unsigned long
 drm_intel_gem_bo_tile_size(drm_intel_bufmgr_gem *bufmgr_gem, unsigned long size,
 			   uint32_t *tiling_mode)
@@ -2116,11 +2121,10 @@ drm_intel_gem_bo_exec(drm_intel_bo *bo, int used,
 		      drm_clip_rect_t * cliprects, int num_cliprects, int DR4)
 {
 	drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bo->bufmgr;
-	drm_intel_bo_gem *bo_gem = (drm_intel_bo_gem *) bo;
 	struct drm_i915_gem_execbuffer execbuf;
 	int ret, i;
 
-	if (bo_gem->has_error)
+	if (to_bo_gem(bo)->has_error)
 		return -ENOMEM;
 
 	pthread_mutex_lock(&bufmgr_gem->lock);
@@ -2165,7 +2169,7 @@ drm_intel_gem_bo_exec(drm_intel_bo *bo, int used,
 		drm_intel_gem_dump_validation_list(bufmgr_gem);
 
 	for (i = 0; i < bufmgr_gem->exec_count; i++) {
-		bo_gem = (drm_intel_bo_gem *) bufmgr_gem->exec_bos[i];
+		drm_intel_bo_gem *bo_gem = to_bo_gem(bufmgr_gem->exec_bos[i]);
 
 		bo_gem->idle = false;
 
@@ -2185,12 +2189,11 @@ do_exec2(drm_intel_bo *bo, int used, drm_intel_context *ctx,
 	 unsigned int flags)
 {
 	drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *)bo->bufmgr;
-	drm_intel_bo_gem *bo_gem = (drm_intel_bo_gem *) bo;
 	struct drm_i915_gem_execbuffer2 execbuf;
 	int ret = 0;
 	int i;
 
-	if (bo_gem->has_error)
+	if (to_bo_gem(bo)->has_error)
 		return -ENOMEM;
 
 	switch (flags & 0x7) {
@@ -2263,7 +2266,7 @@ skip_execution:
 		drm_intel_gem_dump_validation_list(bufmgr_gem);
 
 	for (i = 0; i < bufmgr_gem->exec_count; i++) {
-		bo_gem = (drm_intel_bo_gem *) bufmgr_gem->exec_bos[i];
+		drm_intel_bo_gem *bo_gem = to_bo_gem(bufmgr_gem->exec_bos[i]);
 
 		bo_gem->idle = false;
 
-- 
2.5.0



More information about the dri-devel mailing list