Skip to contentSkip to conversation

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

PATCH Superseded Joonas Lahtinen 3 participants 4 messages Feb 7, 2017

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Joonas Lahtinen

author maintainer
#0 lore raw

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

"BIT(max) - 1" will overflow when max = 32, and GCC will complain. We already have GENMASK for generating the mask, use it!

---
 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(-)
drivers/gpu/drm/i915/intel_device_info.c +1 -1
index fcf8181..1c06fbb 100644
@@ -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);
 
drivers/gpu/drm/i915/intel_fbdev.c +1 -1
index 1b8ba2e..1a0eeb9 100644
@@ -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++) {
drivers/gpu/drm/i915/intel_runtime_pm.c +1 -1
index 66aa1bb..8258fd6 100644
@@ -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)
Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw
Quoted 16 lines · Joonas Lahtinen

"BIT(max) - 1" will overflow when max = 32, and GCC will complain. We already have GENMASK for generating the mask, use it!

---
 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(-)
drivers/gpu/drm/i915/intel_device_info.c +0 -0
index fcf8181..1c06fbb 100644

drivers/gpu/drm/i915/intel_device_info.c static void broadwell_sseu_info_init(struct drm_i915_private *dev_priv) · line 237

Quoted 5 lines
drivers/gpu/drm/i915/intel_device_info.c +1 -1
@@ -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

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author maintainer
#2 lore raw
Quoted 26 lines · Chris Wilson
Quoted 17 lines · Joonas Lahtinen

"BIT(max) - 1" will overflow when max = 32, and GCC will complain. We already have GENMASK for generating the mask, use it!

---
 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(-)
drivers/gpu/drm/i915/intel_device_info.c +0 -0
index fcf8181..1c06fbb 100644
@@ -234,7 +234,7 @@ static void broadwell_sseu_info_init(struct drm_i915_private *dev_priv)
Quoted 5 lines
Quoted 5 lines

drivers/gpu/drm/i915/intel_device_info.c static void broadwell_sseu_info_init(struct drm_i915_private *dev_priv) · line 237

Quoted 5 lines

   * The subslice disable field is global, i.e. it applies
   * to each of the enabled slices.
   */

drivers/gpu/drm/i915/intel_device_info.c +1 -1
-	sseu->subslice_mask = BIT(ss_max) - 1;
+	sseu->subslice_mask = GENMASK(ss_max, 0);

Too simple!

Quoted 5 lines
	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

Signature · 7 lines
Joonas Lahtinen
Open Source Technology Center
Intel Corporation
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw

✗ Fi.CI.BAT: failure for drm/i915: Avoid BIT(max) - 1 and use GENMASK(max, 0)

In reply to Joonas Lahtinen
== Series Details ==

== Series Details ==

Series: drm/i915: Avoid BIT(max) - 1 and use GENMASK(max, 0)
URL : https://patchwork.freedesktop.org/series/19240/
State : failure

== Summary ==

Series 19240v1 drm/i915: Avoid BIT(max) - 1 and use GENMASK(max, 0)
https://patchwork.freedesktop.org/api/1.0/series/19240/revisions/1/mbox/

Test core_auth:

        Subgroup basic-auth:
                pass       -> INCOMPLETE (fi-skl-6260u)
                pass       -> INCOMPLETE (fi-skl-6700hq)
                pass       -> INCOMPLETE (fi-ivb-3770)
                pass       -> INCOMPLETE (fi-bxt-j4205)
                pass       -> INCOMPLETE (fi-bxt-t5700)
                pass       -> INCOMPLETE (fi-byt-n2820)
                pass       -> INCOMPLETE (fi-kbl-7500u)
                pass       -> INCOMPLETE (fi-snb-2520m)
                pass       -> INCOMPLETE (fi-skl-6700k)
                pass       -> INCOMPLETE (fi-byt-j1900)
                pass       -> INCOMPLETE (fi-skl-6770hq)
                pass       -> INCOMPLETE (fi-hsw-4770)
                pass       -> INCOMPLETE (fi-ilk-650)
                pass       -> INCOMPLETE (fi-hsw-4770r)
                pass       -> INCOMPLETE (fi-snb-2600)
                pass       -> INCOMPLETE (fi-bsw-n3050)
                pass       -> INCOMPLETE (fi-ivb-3520m)
                pass       -> INCOMPLETE (fi-bdw-5557u)
fi-bdw-5557u     total:1    pass:0    dwarn:0   dfail:0   fail:0   skip:0  
fi-bsw-n3050     total:1    pass:0    dwarn:0   dfail:0   fail:0   skip:0  
fi-bxt-j4205     total:1    pass:0    dwarn:0   dfail:0   fail:0   skip:0  
fi-bxt-t5700     total:1    pass:0    dwarn:0   dfail:0   fail:0   skip:0  
fi-byt-j1900     total:1    pass:0    dwarn:0   dfail:0   fail:0   skip:0  
fi-byt-n2820     total:1    pass:0    dwarn:0   dfail:0   fail:0   skip:0  
fi-hsw-4770      total:1    pass:0    dwarn:0   dfail:0   fail:0   skip:0  
fi-hsw-4770r     total:1    pass:0    dwarn:0   dfail:0   fail:0   skip:0  
fi-ilk-650       total:1    pass:0    dwarn:0   dfail:0   fail:0   skip:0  
fi-ivb-3520m     total:1    pass:0    dwarn:0   dfail:0   fail:0   skip:0  
fi-ivb-3770      total:1    pass:0    dwarn:0   dfail:0   fail:0   skip:0  
fi-kbl-7500u     total:1    pass:0    dwarn:0   dfail:0   fail:0   skip:0  
fi-skl-6260u     total:1    pass:0    dwarn:0   dfail:0   fail:0   skip:0  
fi-skl-6700hq    total:1    pass:0    dwarn:0   dfail:0   fail:0   skip:0  
fi-skl-6700k     total:1    pass:0    dwarn:0   dfail:0   fail:0   skip:0  
fi-skl-6770hq    total:1    pass:0    dwarn:0   dfail:0   fail:0   skip:0  
fi-snb-2520m     total:1    pass:0    dwarn:0   dfail:0   fail:0   skip:0  
fi-snb-2600      total:1    pass:0    dwarn:0   dfail:0   fail:0   skip:0  

b8157792b685dfcc86fa7dc23d66d663ad6fb93f drm-tip: 2017y-02m-07d-14h-55m-05s UTC integration manifest 23cf9f6 drm/i915: Avoid BIT(max) - 1 and use GENMASK(max, 0)

== Logs ==

For more details see: https://intel-gfx-ci.01.org/CI/Patchwork_3723/
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx