[Intel-gfx] [PATCH] drm/i915: Use GEM_WARN_ON to catch invalid engine indices.
Michal Wajdeczko
michal.wajdeczko at intel.com
Wed Mar 1 20:27:08 UTC 2017
Engine related definitions are located in different files
and it is easy to break their cross dependency.
v2: compare against array size
v3: don't use BUILD_BUG (Tvrtko)
Signed-off-by: Michal Wajdeczko <michal.wajdeczko at intel.com>
Cc: Jani Nikula <jani.nikula at intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen at linux.intel.com>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
---
drivers/gpu/drm/i915/intel_engine_cs.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/i915/intel_engine_cs.c b/drivers/gpu/drm/i915/intel_engine_cs.c
index a238304..8675164 100644
--- a/drivers/gpu/drm/i915/intel_engine_cs.c
+++ b/drivers/gpu/drm/i915/intel_engine_cs.c
@@ -89,7 +89,11 @@ intel_engine_setup(struct drm_i915_private *dev_priv,
const struct engine_info *info = &intel_engines[id];
struct intel_engine_cs *engine;
- GEM_BUG_ON(dev_priv->engine[id]);
+ if (GEM_WARN_ON((unsigned)id >= ARRAY_SIZE(intel_engines)))
+ return -EINVAL;
+ if (GEM_WARN_ON((unsigned)id >= ARRAY_SIZE(dev_priv->engine)))
+ return -EINVAL;
+
engine = kzalloc(sizeof(*engine), GFP_KERNEL);
if (!engine)
return -ENOMEM;
@@ -105,6 +109,7 @@ intel_engine_setup(struct drm_i915_private *dev_priv,
/* Nothing to do here, execute in order of dependencies */
engine->schedule = NULL;
+ GEM_BUG_ON(dev_priv->engine[id]);
dev_priv->engine[id] = engine;
return 0;
}
--
2.7.4
More information about the Intel-gfx
mailing list