Skip to content

Commit 5f77eeb

Browse files
committed
drm/i915: Use BUILD_BUG if possible in the i915 WARN_ON
Faster feedback to errors is always better. This is inspired by the addition to WARN_ONs to mask/enable helpers for registers to make sure callers have the arguments ordered correctly: Pretty much always the arguments are static. We use WARN_ON(1) a lot in default switch statements though where we should always handle all cases. So add a new macro specifically for that. The idea to use __builtin_constant_p is from Chris Wilson. v2: Use the ({}) gcc-ism to avoid the static inline, suggested by Dave. My first attempt used __cond as the temp var, which is the same used by BUILD_BUG_ON, but with inverted sense. Hilarity ensued, so sprinkle i915 into the name. Also use a temporary variable to only evaluate the condition once, suggested by Damien. v3: It's crazy but apparently 32bit gcc can't compile out the BUILD_BUG_ON in a lot of cases and just falls over. I have no idea why, but until clue grows just disable this nifty idea on 32bit builds. Reported by 0-day builder. v4: Got it all wrong, apparently its the gcc version. We need 4.9+. Now reported by Imre. v5: Chris suggested to add the case to MISSING_CASE for speedier debug. v6: Even some gcc 4.9 versions don't see through the maze, so give up for now. Keep the skeleton and MISSING_CASE stuff though. Cc: Imre Deak <imre.deak@intel.com> Cc: Damien Lespiau <damien.lespiau@intel.com> Cc: Chris Wilson <chris@chris-wilson.co.uk> Cc: Jani Nikula <jani.nikula@linux.intel.com> Cc: Dave Gordon <david.s.gordon@intel.com> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
1 parent 3f7531c commit 5f77eeb

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

drivers/gpu/drm/i915/i915_debugfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2347,7 +2347,7 @@ static const char *power_domain_str(enum intel_display_power_domain domain)
23472347
case POWER_DOMAIN_INIT:
23482348
return "INIT";
23492349
default:
2350-
WARN_ON(1);
2350+
MISSING_CASE(domain);
23512351
return "?";
23522352
}
23532353
}

drivers/gpu/drm/i915/i915_drv.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,19 @@
5858
#define DRIVER_DATE "20141205"
5959

6060
#undef WARN_ON
61-
#define WARN_ON(x) WARN(x, "WARN_ON(" #x ")")
61+
/* Many gcc seem to no see through this and fall over :( */
62+
#if 0
63+
#define WARN_ON(x) ({ \
64+
bool __i915_warn_cond = (x); \
65+
if (__builtin_constant_p(__i915_warn_cond)) \
66+
BUILD_BUG_ON(__i915_warn_cond); \
67+
WARN(__i915_warn_cond, "WARN_ON(" #x ")"); })
68+
#else
69+
#define WARN_ON(x) WARN((x), "WARN_ON(" #x ")")
70+
#endif
71+
72+
#define MISSING_CASE(x) WARN(1, "Missing switch case (%lu) in %s\n", \
73+
(long) (x), __func__);
6274

6375
enum pipe {
6476
INVALID_PIPE = -1,

drivers/gpu/drm/i915/i915_gem_gtt.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ static gen6_gtt_pte_t snb_pte_encode(dma_addr_t addr,
132132
pte |= GEN6_PTE_UNCACHED;
133133
break;
134134
default:
135-
WARN_ON(1);
135+
MISSING_CASE(level);
136136
}
137137

138138
return pte;
@@ -156,7 +156,7 @@ static gen6_gtt_pte_t ivb_pte_encode(dma_addr_t addr,
156156
pte |= GEN6_PTE_UNCACHED;
157157
break;
158158
default:
159-
WARN_ON(1);
159+
MISSING_CASE(level);
160160
}
161161

162162
return pte;
@@ -1146,7 +1146,7 @@ int i915_ppgtt_init_hw(struct drm_device *dev)
11461146
else if (INTEL_INFO(dev)->gen >= 8)
11471147
gen8_ppgtt_enable(dev);
11481148
else
1149-
WARN_ON(1);
1149+
MISSING_CASE(INTEL_INFO(dev)->gen);
11501150

11511151
if (ppgtt) {
11521152
for_each_ring(ring, dev_priv, i) {

drivers/gpu/drm/i915/intel_display.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4847,7 +4847,7 @@ static void cherryview_set_cdclk(struct drm_device *dev, int cdclk)
48474847
cmd = 0;
48484848
break;
48494849
default:
4850-
WARN_ON(1);
4850+
MISSING_CASE(cdclk);
48514851
return;
48524852
}
48534853

@@ -8224,7 +8224,7 @@ static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
82248224
cntl |= CURSOR_MODE_256_ARGB_AX;
82258225
break;
82268226
default:
8227-
WARN_ON(1);
8227+
MISSING_CASE(intel_crtc->cursor_width);
82288228
return;
82298229
}
82308230
cntl |= pipe << 28; /* Connect to correct pipe */

drivers/gpu/drm/i915/intel_uncore.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@ void intel_uncore_init(struct drm_device *dev)
12021202

12031203
switch (INTEL_INFO(dev)->gen) {
12041204
default:
1205-
WARN_ON(1);
1205+
MISSING_CASE(INTEL_INFO(dev)->gen);
12061206
return;
12071207
case 9:
12081208
ASSIGN_WRITE_MMIO_VFUNCS(gen9);
@@ -1300,7 +1300,7 @@ int i915_reg_read_ioctl(struct drm_device *dev,
13001300
reg->val = I915_READ8(reg->offset);
13011301
break;
13021302
default:
1303-
WARN_ON(1);
1303+
MISSING_CASE(entry->size);
13041304
ret = -EINVAL;
13051305
goto out;
13061306
}

0 commit comments

Comments
 (0)