diff mbox

drm/i915: Avoid BIT(max) - 1 and use GENMASK(max, 0)

Message ID 1486475501-13541-1-git-send-email-joonas.lahtinen@linux.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Joonas Lahtinen Feb. 7, 2017, 1:51 p.m. UTC
"BIT(max) - 1" will overflow when max = 32, and GCC will complain.
We already have GENMASK for generating the mask, use it!

Signed-off-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/intel_device_info.c | 2 +-
 drivers/gpu/drm/i915/intel_fbdev.c       | 2 +-
 drivers/gpu/drm/i915/intel_runtime_pm.c  | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

Comments

Chris Wilson Feb. 7, 2017, 2:03 p.m. UTC | #1
On Tue, Feb 07, 2017 at 03:51:41PM +0200, Joonas Lahtinen wrote:
> "BIT(max) - 1" will overflow when max = 32, and GCC will complain.
> We already have GENMASK for generating the mask, use it!
> 
> Signed-off-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> ---
>  drivers/gpu/drm/i915/intel_device_info.c | 2 +-
>  drivers/gpu/drm/i915/intel_fbdev.c       | 2 +-
>  drivers/gpu/drm/i915/intel_runtime_pm.c  | 2 +-
>  3 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/intel_device_info.c b/drivers/gpu/drm/i915/intel_device_info.c
> index fcf8181..1c06fbb 100644
> --- a/drivers/gpu/drm/i915/intel_device_info.c
> +++ b/drivers/gpu/drm/i915/intel_device_info.c
> @@ -234,7 +234,7 @@ static void broadwell_sseu_info_init(struct drm_i915_private *dev_priv)
>  	 * The subslice disable field is global, i.e. it applies
>  	 * to each of the enabled slices.
>  	 */
> -	sseu->subslice_mask = BIT(ss_max) - 1;
> +	sseu->subslice_mask = GENMASK(ss_max, 0);

Too simple!

	BUILD_BUG_ON(BIT(ss_max)-1 != GENMASK(ss_max, 0));

Needs to be GENMASK(ss_max - 1, 0); the high bit is inclusive.

Otherwise, the list matches up with a quick grep for BIT*(x)-1.
-Chris
Joonas Lahtinen Feb. 7, 2017, 2:38 p.m. UTC | #2
On ti, 2017-02-07 at 14:03 +0000, Chris Wilson wrote:
> On Tue, Feb 07, 2017 at 03:51:41PM +0200, Joonas Lahtinen wrote:
> > 
> > "BIT(max) - 1" will overflow when max = 32, and GCC will complain.
> > We already have GENMASK for generating the mask, use it!
> > 
> > Signed-off-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> > Cc: Chris Wilson <chris@chris-wilson.co.uk>
> > ---
> >  drivers/gpu/drm/i915/intel_device_info.c | 2 +-
> >  drivers/gpu/drm/i915/intel_fbdev.c       | 2 +-
> >  drivers/gpu/drm/i915/intel_runtime_pm.c  | 2 +-
> >  3 files changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/i915/intel_device_info.c b/drivers/gpu/drm/i915/intel_device_info.c
> > index fcf8181..1c06fbb 100644
> > --- a/drivers/gpu/drm/i915/intel_device_info.c
> > +++ b/drivers/gpu/drm/i915/intel_device_info.c
> > @@ -234,7 +234,7 @@ static void broadwell_sseu_info_init(struct drm_i915_private *dev_priv)
> > > >  	 * The subslice disable field is global, i.e. it applies
> > > >  	 * to each of the enabled slices.
> > > >  	 */
> > > > -	sseu->subslice_mask = BIT(ss_max) - 1;
> > > > +	sseu->subslice_mask = GENMASK(ss_max, 0);
> 
> Too simple!
> 
> 	BUILD_BUG_ON(BIT(ss_max)-1 != GENMASK(ss_max, 0));
> 
> Needs to be GENMASK(ss_max - 1, 0); the high bit is inclusive.
> 
> Otherwise, the list matches up with a quick grep for BIT*(x)-1.

Whoop, seem to have nucleared my kernel config. I think better check if
the same warning is triggered too, with GENMASK :)

Regards, Joonas
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/intel_device_info.c b/drivers/gpu/drm/i915/intel_device_info.c
index fcf8181..1c06fbb 100644
--- a/drivers/gpu/drm/i915/intel_device_info.c
+++ b/drivers/gpu/drm/i915/intel_device_info.c
@@ -234,7 +234,7 @@  static void broadwell_sseu_info_init(struct drm_i915_private *dev_priv)
 	 * The subslice disable field is global, i.e. it applies
 	 * to each of the enabled slices.
 	 */
-	sseu->subslice_mask = BIT(ss_max) - 1;
+	sseu->subslice_mask = GENMASK(ss_max, 0);
 	sseu->subslice_mask &= ~((fuse2 & GEN8_F2_SS_DIS_MASK) >>
 				 GEN8_F2_SS_DIS_SHIFT);
 
diff --git a/drivers/gpu/drm/i915/intel_fbdev.c b/drivers/gpu/drm/i915/intel_fbdev.c
index 1b8ba2e..1a0eeb9 100644
--- a/drivers/gpu/drm/i915/intel_fbdev.c
+++ b/drivers/gpu/drm/i915/intel_fbdev.c
@@ -371,7 +371,7 @@  static bool intel_fb_initial_config(struct drm_fb_helper *fb_helper,
 		return false;
 
 	memcpy(save_enabled, enabled, count);
-	mask = BIT(count) - 1;
+	mask = GENMASK(count, 0);
 	conn_configured = 0;
 retry:
 	for (i = 0; i < count; i++) {
diff --git a/drivers/gpu/drm/i915/intel_runtime_pm.c b/drivers/gpu/drm/i915/intel_runtime_pm.c
index 66aa1bb..8258fd6 100644
--- a/drivers/gpu/drm/i915/intel_runtime_pm.c
+++ b/drivers/gpu/drm/i915/intel_runtime_pm.c
@@ -1249,7 +1249,7 @@  static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
 	vlv_set_power_well(dev_priv, power_well, false);
 }
 
-#define POWER_DOMAIN_MASK (BIT(POWER_DOMAIN_NUM) - 1)
+#define POWER_DOMAIN_MASK (GENMASK(POWER_DOMAIN_NUM, 0))
 
 static struct i915_power_well *lookup_power_well(struct drm_i915_private *dev_priv,
 						 int power_well_id)