Message ID | 20180319173720.6974-1-lucas.demarchi@intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Quoting Lucas De Marchi (2018-03-19 17:37:20) > In some places we end up converting switch statements to a series of > if/else, particularly when introducing helper functions to handle a > group of cases. It's tempting to either leave a wrong warning (since now > we don't have a switch case anymore) or to convert to WARN(1, ...), > but we can just provide a better message and avoid the doubt when such > conversions arrise. > > Introducing a warning inside i915_driver_load() just for tests we get: > > [ 4535.233717] Missing case (ret == 0) > [ 4535.233868] WARNING: CPU: 1 PID: 795 at drivers/gpu/drm/i915/i915_drv.c:1341 i915_driver_load+0x42/0x10e0 [i915] > > which is clear enough. > > v2: remove __func__ since this is already on the warning. > > Cc: Chris Wilson <chris@chris-wilson.co.uk> > Cc: Ville Syrjälä <ville.syrjala@linux.intel.com> > Cc: Daniel Vetter <daniel.vetter@ffwll.ch> > Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk> -Chris
On Mon, Mar 19, 2018 at 09:41:32PM +0000, Chris Wilson wrote: > Quoting Lucas De Marchi (2018-03-19 17:37:20) > > In some places we end up converting switch statements to a series of > > if/else, particularly when introducing helper functions to handle a > > group of cases. It's tempting to either leave a wrong warning (since now > > we don't have a switch case anymore) or to convert to WARN(1, ...), > > but we can just provide a better message and avoid the doubt when such > > conversions arrise. > > > > Introducing a warning inside i915_driver_load() just for tests we get: > > > > [ 4535.233717] Missing case (ret == 0) > > [ 4535.233868] WARNING: CPU: 1 PID: 795 at drivers/gpu/drm/i915/i915_drv.c:1341 i915_driver_load+0x42/0x10e0 [i915] > > > > which is clear enough. > > > > v2: remove __func__ since this is already on the warning. > > > > Cc: Chris Wilson <chris@chris-wilson.co.uk> > > Cc: Ville Syrjälä <ville.syrjala@linux.intel.com> > > Cc: Daniel Vetter <daniel.vetter@ffwll.ch> > > Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com> > Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk> pushed to dinq. thanks for patch and reviews. > -Chris > _______________________________________________ > Intel-gfx mailing list > Intel-gfx@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/intel-gfx
diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h index 51dbfe5bb418..0695717522ea 100644 --- a/drivers/gpu/drm/i915/i915_utils.h +++ b/drivers/gpu/drm/i915/i915_utils.h @@ -40,8 +40,8 @@ #undef WARN_ON_ONCE #define WARN_ON_ONCE(x) WARN_ONCE((x), "%s", "WARN_ON_ONCE(" __stringify(x) ")") -#define MISSING_CASE(x) WARN(1, "Missing switch case (%lu) in %s\n", \ - (long)(x), __func__) +#define MISSING_CASE(x) WARN(1, "Missing case (%s == %ld)\n", \ + __stringify(x), (long)(x)) #if GCC_VERSION >= 70000 #define add_overflows(A, B) \
In some places we end up converting switch statements to a series of if/else, particularly when introducing helper functions to handle a group of cases. It's tempting to either leave a wrong warning (since now we don't have a switch case anymore) or to convert to WARN(1, ...), but we can just provide a better message and avoid the doubt when such conversions arrise. Introducing a warning inside i915_driver_load() just for tests we get: [ 4535.233717] Missing case (ret == 0) [ 4535.233868] WARNING: CPU: 1 PID: 795 at drivers/gpu/drm/i915/i915_drv.c:1341 i915_driver_load+0x42/0x10e0 [i915] which is clear enough. v2: remove __func__ since this is already on the warning. Cc: Chris Wilson <chris@chris-wilson.co.uk> Cc: Ville Syrjälä <ville.syrjala@linux.intel.com> Cc: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com> --- drivers/gpu/drm/i915/i915_utils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)