Skip to contentSkip to conversation

drm/i915/hwmon: Don't use FIELD_PREP

PATCH In review Ashutosh Dixit 3 participants 6 messages Oct 31, 2022 – Nov 2, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/i915/hwmon: Don't use FIELD_PREP

FIELD_PREP and REG_FIELD_PREP have checks requiring a compile time constant mask. When the mask comes in as the argument of a function these checks can can fail depending on the compiler (gcc vs clang), optimization level, etc. Use a simpler version of FIELD_PREP which skips these checks. The checks are not needed because the mask is formed using REG_GENMASK (so is actually a compile time constant).

v2: Split REG_FIELD_PREP into a macro with checks and one without and use
the one without checks in i915_hwmon.c (Gwan-gyeong Mun)

---
 drivers/gpu/drm/i915/i915_hwmon.c    |  2 +-
 drivers/gpu/drm/i915/i915_reg_defs.h | 17 +++++++++++------
 2 files changed, 12 insertions(+), 7 deletions(-)
drivers/gpu/drm/i915/i915_hwmon.c +1 -1
index 9e97814930254..ae435b035229a 100644
@@ -112,7 +112,7 @@ hwm_field_scale_and_write(struct hwm_drvdata *ddat, i915_reg_t rgadr,
 	nval = DIV_ROUND_CLOSEST_ULL((u64)lval << nshift, scale_factor);
 
 	bits_to_clear = field_msk;
-	bits_to_set = FIELD_PREP(field_msk, nval);
+	bits_to_set = __REG_FIELD_PREP(field_msk, nval);
 
 	hwm_locked_with_pm_intel_uncore_rmw(ddat, rgadr,
 					    bits_to_clear, bits_to_set);
drivers/gpu/drm/i915/i915_reg_defs.h +11 -6
index f1859046a9c48..dddacc8d48928 100644
@@ -67,12 +67,17 @@
  *
  * @return: @__val masked and shifted into the field defined by @__mask.
  */
-#define REG_FIELD_PREP(__mask, __val)						\
-	((u32)((((typeof(__mask))(__val) << __bf_shf(__mask)) & (__mask)) +	\
-	       BUILD_BUG_ON_ZERO(!__is_constexpr(__mask)) +		\
-	       BUILD_BUG_ON_ZERO((__mask) == 0 || (__mask) > U32_MAX) +		\
-	       BUILD_BUG_ON_ZERO(!IS_POWER_OF_2((__mask) + (1ULL << __bf_shf(__mask)))) + \
-	       BUILD_BUG_ON_ZERO(__builtin_choose_expr(__is_constexpr(__val), (~((__mask) >> __bf_shf(__mask)) & (__val)), 0))))
+#define __REG_FIELD_PREP_CHK(__mask, __val) \
+	(BUILD_BUG_ON_ZERO(!__is_constexpr(__mask)) + \
+	 BUILD_BUG_ON_ZERO((__mask) == 0 || (__mask) > U32_MAX) + \
+	 BUILD_BUG_ON_ZERO(!IS_POWER_OF_2((__mask) + (1ULL << __bf_shf(__mask)))) + \
+	 BUILD_BUG_ON_ZERO(__builtin_choose_expr(__is_constexpr(__val), (~((__mask) >> __bf_shf(__mask)) & (__val)), 0)))
+
+#define __REG_FIELD_PREP(__mask, __val) \
+	((u32)((((typeof(__mask))(__val) << __bf_shf(__mask)) & (__mask))))
+
+#define REG_FIELD_PREP(__mask, __val) \
+	(__REG_FIELD_PREP(__mask, __val) + __REG_FIELD_PREP_CHK(__mask, __val))
 
 /**
  * REG_FIELD_GET() - Extract a u32 bitfield value
Signature · 1 line
2.38.0
#1 lore raw

[Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for drm/i915/hwmon: Don't use FIELD_PREP (rev2)

== Series Details ==

== Series Details ==

Series: drm/i915/hwmon: Don't use FIELD_PREP (rev2)
URL : https://patchwork.freedesktop.org/series/110301/
State : warning

== Summary ==

Error: dim checkpatch failed
6a7780f724ae drm/i915/hwmon: Don't use FIELD_PREP
-:46: CHECK:MACRO_ARG_REUSE: Macro argument reuse '__mask' - possible side-effects? #46: FILE: drivers/gpu/drm/i915/i915_reg_defs.h:70:
+#define __REG_FIELD_PREP_CHK(__mask, __val) \
+ (BUILD_BUG_ON_ZERO(!__is_constexpr(__mask)) + \
+ BUILD_BUG_ON_ZERO((__mask) == 0 || (__mask) > U32_MAX) + \
+ BUILD_BUG_ON_ZERO(!IS_POWER_OF_2((__mask) + (1ULL << __bf_shf(__mask)))) + \
+ BUILD_BUG_ON_ZERO(__builtin_choose_expr(__is_constexpr(__val), (~((__mask) >> __bf_shf(__mask)) & (__val)), 0)))

-:46: CHECK:MACRO_ARG_REUSE: Macro argument reuse '__val' - possible side-effects? #46: FILE: drivers/gpu/drm/i915/i915_reg_defs.h:70:
+#define __REG_FIELD_PREP_CHK(__mask, __val) \
+ (BUILD_BUG_ON_ZERO(!__is_constexpr(__mask)) + \
+ BUILD_BUG_ON_ZERO((__mask) == 0 || (__mask) > U32_MAX) + \
+ BUILD_BUG_ON_ZERO(!IS_POWER_OF_2((__mask) + (1ULL << __bf_shf(__mask)))) + \
+ BUILD_BUG_ON_ZERO(__builtin_choose_expr(__is_constexpr(__val), (~((__mask) >> __bf_shf(__mask)) & (__val)), 0)))

-:50: WARNING:LONG_LINE: line length of 121 exceeds 100 columns #50: FILE: drivers/gpu/drm/i915/i915_reg_defs.h:74:
+ BUILD_BUG_ON_ZERO(__builtin_choose_expr(__is_constexpr(__val), (~((__mask) >> __bf_shf(__mask)) & (__val)), 0)))

-:52: CHECK:MACRO_ARG_REUSE: Macro argument reuse '__mask' - possible side-effects? #52: FILE: drivers/gpu/drm/i915/i915_reg_defs.h:76:
+#define __REG_FIELD_PREP(__mask, __val) \
+ ((u32)((((typeof(__mask))(__val) << __bf_shf(__mask)) & (__mask))))

-:55: CHECK:MACRO_ARG_REUSE: Macro argument reuse '__mask' - possible side-effects? #55: FILE: drivers/gpu/drm/i915/i915_reg_defs.h:79:
+#define REG_FIELD_PREP(__mask, __val) \
+ (__REG_FIELD_PREP(__mask, __val) + __REG_FIELD_PREP_CHK(__mask, __val))

-:55: CHECK:MACRO_ARG_REUSE: Macro argument reuse '__val' - possible side-effects? #55: FILE: drivers/gpu/drm/i915/i915_reg_defs.h:79:
+#define REG_FIELD_PREP(__mask, __val) \
+ (__REG_FIELD_PREP(__mask, __val) + __REG_FIELD_PREP_CHK(__mask, __val))

total: 0 errors, 1 warnings, 5 checks, 31 lines checked

#3 lore raw

[Intel-gfx] ✗ Fi.CI.BAT: failure for drm/i915/hwmon: Don't use FIELD_PREP (rev2)

In reply to Ashutosh Dixit
== Series Details ==

== Series Details ==

Series: drm/i915/hwmon: Don't use FIELD_PREP (rev2)
URL : https://patchwork.freedesktop.org/series/110301/
State : failure

== Summary ==

CI Bug Log - changes from CI_DRM_12325 -> Patchwork_110301v2
====================================================

Summary
-------

**FAILURE**

Serious unknown changes coming with Patchwork_110301v2 absolutely need to be verified manually.

If you think the reported changes have nothing to do with the changes introduced in Patchwork_110301v2, please notify your bug team to allow them to document this new failure mode, which will reduce false positives in CI.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/index.html

Participating hosts (40 -> 40)
------------------------------

Additional (2): fi-kbl-soraka fi-rkl-11600
Missing (2): fi-cml-u2 fi-hsw-4770

Possible new issues
-------------------

Here are the unknown changes that may have been introduced in Patchwork_110301v2:

### IGT changes ###

#### Possible regressions ####

* igt@i915_selftest@live@gem_contexts:
- fi-kbl-soraka: NOTRUN -> [INCOMPLETE][1]
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/fi-kbl-soraka/igt@i915_selftest@live@gem_contexts.html

Known issues
------------

Here are the changes found in Patchwork_110301v2 that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@core_hotunplug@unbind-rebind:
- fi-apl-guc: [PASS][2] -> [INCOMPLETE][3] ([i915#7073])
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12325/fi-apl-guc/igt@[email protected]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/fi-apl-guc/igt@[email protected]

* igt@gem_exec_gttfill@basic:
- fi-kbl-soraka: NOTRUN -> [SKIP][4] ([fdo#109271]) +8 similar issues
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/fi-kbl-soraka/igt@[email protected]

* igt@gem_huc_copy@huc-copy:
- fi-kbl-soraka: NOTRUN -> [SKIP][5] ([fdo#109271] / [i915#2190])
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/fi-kbl-soraka/igt@[email protected]
- fi-rkl-11600: NOTRUN -> [SKIP][6] ([i915#2190])
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/fi-rkl-11600/igt@[email protected]

* igt@gem_lmem_swapping@basic:
- fi-kbl-soraka: NOTRUN -> [SKIP][7] ([fdo#109271] / [i915#4613]) +3 similar issues
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/fi-kbl-soraka/igt@[email protected]
- fi-rkl-11600: NOTRUN -> [SKIP][8] ([i915#4613]) +3 similar issues
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/fi-rkl-11600/igt@[email protected]

* igt@gem_tiled_pread_basic:
- fi-rkl-11600: NOTRUN -> [SKIP][9] ([i915#3282])
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/fi-rkl-11600/igt@gem_tiled_pread_basic.html

* igt@i915_pm_backlight@basic-brightness:
- fi-rkl-11600: NOTRUN -> [SKIP][10] ([i915#3012])
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/fi-rkl-11600/igt@[email protected]

* igt@i915_selftest@live@gt_pm:
- fi-kbl-soraka: NOTRUN -> [DMESG-FAIL][11] ([i915#1886])
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/fi-kbl-soraka/igt@i915_selftest@live@gt_pm.html

* igt@i915_selftest@live@mman:
- fi-rkl-guc: [PASS][12] -> [INCOMPLETE][13] ([i915#6794])
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12325/fi-rkl-guc/igt@i915_selftest@[email protected]
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/fi-rkl-guc/igt@i915_selftest@[email protected]

* igt@i915_suspend@basic-s3-without-i915:
- fi-rkl-11600: NOTRUN -> [INCOMPLETE][14] ([i915#4817])
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/fi-rkl-11600/igt@[email protected]

* igt@kms_chamelium@hdmi-edid-read:
- fi-rkl-11600: NOTRUN -> [SKIP][15] ([fdo#111827]) +7 similar issues
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/fi-rkl-11600/igt@[email protected]

* igt@kms_chamelium@hdmi-hpd-fast:
- fi-kbl-soraka: NOTRUN -> [SKIP][16] ([fdo#109271] / [fdo#111827]) +7 similar issues
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/fi-kbl-soraka/igt@[email protected]

* igt@kms_cursor_legacy@basic-busy-flip-before-cursor:
- fi-rkl-11600: NOTRUN -> [SKIP][17] ([i915#4103])
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/fi-rkl-11600/igt@[email protected]

* igt@kms_force_connector_basic@force-load-detect:
- fi-rkl-11600: NOTRUN -> [SKIP][18] ([fdo#109285] / [i915#4098])
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/fi-rkl-11600/igt@[email protected]

* igt@kms_pipe_crc_basic@suspend-read-crc@pipe-a-hdmi-a-2:
- fi-bdw-5557u: [PASS][19] -> [INCOMPLETE][20] ([i915#146])
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12325/fi-bdw-5557u/igt@kms_pipe_crc_basic@[email protected]
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/fi-bdw-5557u/igt@kms_pipe_crc_basic@[email protected]

* igt@kms_psr@primary_page_flip:
- fi-rkl-11600: NOTRUN -> [SKIP][21] ([i915#1072]) +3 similar issues
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/fi-rkl-11600/igt@kms_psr@primary_page_flip.html

* igt@kms_setmode@basic-clone-single-crtc:
- fi-rkl-11600: NOTRUN -> [SKIP][22] ([i915#3555] / [i915#4098])
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/fi-rkl-11600/igt@[email protected]

* igt@prime_vgem@basic-read:
- fi-rkl-11600: NOTRUN -> [SKIP][23] ([fdo#109295] / [i915#3291] / [i915#3708]) +2 similar issues
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/fi-rkl-11600/igt@[email protected]

* igt@prime_vgem@basic-userptr:
- fi-rkl-11600: NOTRUN -> [SKIP][24] ([fdo#109295] / [i915#3301] / [i915#3708])
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/fi-rkl-11600/igt@[email protected]

#### Possible fixes ####

* igt@gem_exec_suspend@basic-s0@lmem0:
- {bat-dg2-11}: [DMESG-FAIL][25] ([fdo#103375]) -> [PASS][26]
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12325/bat-dg2-11/igt@gem_exec_suspend@[email protected]
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/bat-dg2-11/igt@gem_exec_suspend@[email protected]

* igt@gem_exec_suspend@basic-s0@smem:
- {bat-adlm-1}: [DMESG-WARN][27] ([i915#2867]) -> [PASS][28]
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12325/bat-adlm-1/igt@gem_exec_suspend@[email protected]
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/bat-adlm-1/igt@gem_exec_suspend@[email protected]

* igt@gem_exec_suspend@basic-s3@lmem0:
- {bat-dg2-11}: [FAIL][29] ([fdo#103375]) -> [PASS][30] +2 similar issues
[29]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12325/bat-dg2-11/igt@gem_exec_suspend@[email protected]
[30]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/bat-dg2-11/igt@gem_exec_suspend@[email protected]

* igt@gem_exec_suspend@basic-s3@smem:
- {bat-rplp-1}: [DMESG-WARN][31] ([i915#2867]) -> [PASS][32]
[31]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12325/bat-rplp-1/igt@gem_exec_suspend@[email protected]
[32]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/bat-rplp-1/igt@gem_exec_suspend@[email protected]

* igt@kms_cursor_legacy@basic-busy-flip-before-cursor@atomic-transitions-varying-size:
- fi-bsw-kefka: [FAIL][33] ([i915#6298]) -> [PASS][34]
[33]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12325/fi-bsw-kefka/igt@kms_cursor_legacy@basic-busy-flip-before-cursor@atomic-transitions-varying-size.html
[34]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/fi-bsw-kefka/igt@kms_cursor_legacy@basic-busy-flip-before-cursor@atomic-transitions-varying-size.html

* igt@kms_pipe_crc_basic@suspend-read-crc@pipe-a-dp-3:
- {bat-dg2-11}: [FAIL][35] -> [PASS][36]
[35]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12325/bat-dg2-11/igt@kms_pipe_crc_basic@[email protected]
[36]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/bat-dg2-11/igt@kms_pipe_crc_basic@[email protected]

* igt@kms_pipe_crc_basic@suspend-read-crc@pipe-b-dp-3:
- {bat-dg2-11}: [FAIL][37] ([i915#6818]) -> [PASS][38] +2 similar issues
[37]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12325/bat-dg2-11/igt@kms_pipe_crc_basic@[email protected]
[38]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/bat-dg2-11/igt@kms_pipe_crc_basic@[email protected]

* igt@kms_pipe_crc_basic@suspend-read-crc@pipe-b-hdmi-a-2:
- fi-icl-u2: [DMESG-WARN][39] ([i915#2867]) -> [PASS][40]
[39]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12325/fi-icl-u2/igt@kms_pipe_crc_basic@[email protected]
[40]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/fi-icl-u2/igt@kms_pipe_crc_basic@[email protected]

{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).

[fdo#103375]: https://bugs.freedesktop.org/show_bug.cgi?id=103375
[fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
[fdo#109285]: https://bugs.freedesktop.org/show_bug.cgi?id=109285
[fdo#109295]: https://bugs.freedesktop.org/show_bug.cgi?id=109295
[fdo#111827]: https://bugs.freedesktop.org/show_bug.cgi?id=111827
[i915#1072]: https://gitlab.freedesktop.org/drm/intel/issues/1072
[i915#146]: https://gitlab.freedesktop.org/drm/intel/issues/146
[i915#1886]: https://gitlab.freedesktop.org/drm/intel/issues/1886
[i915#2190]: https://gitlab.freedesktop.org/drm/intel/issues/2190
[i915#2582]: https://gitlab.freedesktop.org/drm/intel/issues/2582
[i915#2867]: https://gitlab.freedesktop.org/drm/intel/issues/2867
[i915#3012]: https://gitlab.freedesktop.org/drm/intel/issues/3012
[i915#3282]: https://gitlab.freedesktop.org/drm/intel/issues/3282
[i915#3291]: https://gitlab.freedesktop.org/drm/intel/issues/3291
[i915#3301]: https://gitlab.freedesktop.org/drm/intel/issues/3301
[i915#3555]: https://gitlab.freedesktop.org/drm/intel/issues/3555
[i915#3708]: https://gitlab.freedesktop.org/drm/intel/issues/3708
[i915#4098]: https://gitlab.freedesktop.org/drm/intel/issues/4098
[i915#4103]: https://gitlab.freedesktop.org/drm/intel/issues/4103
[i915#4312]: https://gitlab.freedesktop.org/drm/intel/issues/4312
[i915#4613]: https://gitlab.freedesktop.org/drm/intel/issues/4613
[i915#4817]: https://gitlab.freedesktop.org/drm/intel/issues/4817
[i915#4983]: https://gitlab.freedesktop.org/drm/intel/issues/4983
[i915#5537]: https://gitlab.freedesktop.org/drm/intel/issues/5537
[i915#6298]: https://gitlab.freedesktop.org/drm/intel/issues/6298
[i915#6434]: https://gitlab.freedesktop.org/drm/intel/issues/6434
[i915#6794]: https://gitlab.freedesktop.org/drm/intel/issues/6794
[i915#6818]: https://gitlab.freedesktop.org/drm/intel/issues/6818
[i915#7073]: https://gitlab.freedesktop.org/drm/intel/issues/7073

Build changes
-------------

* Linux: CI_DRM_12325 -> Patchwork_110301v2

CI-20190529: 20190529
CI_DRM_12325: 1a90222aa5e5bb86ffcbde5ba9611659a23f0df6 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_7032: 372c56225e12578a7a4a6bcc5b79eb40b643fcde @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
Patchwork_110301v2: 1a90222aa5e5bb86ffcbde5ba9611659a23f0df6 @ git://anongit.freedesktop.org/gfx-ci/linux

### Linux commits

c346baa59d6e drm/i915/hwmon: Don't use FIELD_PREP

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110301v2/index.html

maintainer
#4 lore raw
In reply to Ashutosh Dixit
Quoted 9 lines · Ashutosh Dixit

FIELD_PREP and REG_FIELD_PREP have checks requiring a compile time constant mask. When the mask comes in as the argument of a function these checks can can fail depending on the compiler (gcc vs clang), optimization level, etc. Use a simpler version of FIELD_PREP which skips these checks. The checks are not needed because the mask is formed using REG_GENMASK (so is actually a compile time constant).

v2: Split REG_FIELD_PREP into a macro with checks and one without and use
the one without checks in i915_hwmon.c (Gwan-gyeong Mun)

I frankly think you're solving the wrong problem here. See [1].

BR,
Jani.

[1] https://lore.kernel.org/r/[email protected]

Quoted 49 lines
---
 drivers/gpu/drm/i915/i915_hwmon.c    |  2 +-
 drivers/gpu/drm/i915/i915_reg_defs.h | 17 +++++++++++------
 2 files changed, 12 insertions(+), 7 deletions(-)
drivers/gpu/drm/i915/i915_hwmon.c +1 -1
index 9e97814930254..ae435b035229a 100644
@@ -112,7 +112,7 @@ hwm_field_scale_and_write(struct hwm_drvdata *ddat, i915_reg_t rgadr,
 	nval = DIV_ROUND_CLOSEST_ULL((u64)lval << nshift, scale_factor);
 
 	bits_to_clear = field_msk;
-	bits_to_set = FIELD_PREP(field_msk, nval);
+	bits_to_set = __REG_FIELD_PREP(field_msk, nval);
 
 	hwm_locked_with_pm_intel_uncore_rmw(ddat, rgadr,
 					    bits_to_clear, bits_to_set);
drivers/gpu/drm/i915/i915_reg_defs.h +11 -6
index f1859046a9c48..dddacc8d48928 100644
@@ -67,12 +67,17 @@
  *
  * @return: @__val masked and shifted into the field defined by @__mask.
  */
-#define REG_FIELD_PREP(__mask, __val)						\
-	((u32)((((typeof(__mask))(__val) << __bf_shf(__mask)) & (__mask)) +	\
-	       BUILD_BUG_ON_ZERO(!__is_constexpr(__mask)) +		\
-	       BUILD_BUG_ON_ZERO((__mask) == 0 || (__mask) > U32_MAX) +		\
-	       BUILD_BUG_ON_ZERO(!IS_POWER_OF_2((__mask) + (1ULL << __bf_shf(__mask)))) + \
-	       BUILD_BUG_ON_ZERO(__builtin_choose_expr(__is_constexpr(__val), (~((__mask) >> __bf_shf(__mask)) & (__val)), 0))))
+#define __REG_FIELD_PREP_CHK(__mask, __val) \
+	(BUILD_BUG_ON_ZERO(!__is_constexpr(__mask)) + \
+	 BUILD_BUG_ON_ZERO((__mask) == 0 || (__mask) > U32_MAX) + \
+	 BUILD_BUG_ON_ZERO(!IS_POWER_OF_2((__mask) + (1ULL << __bf_shf(__mask)))) + \
+	 BUILD_BUG_ON_ZERO(__builtin_choose_expr(__is_constexpr(__val), (~((__mask) >> __bf_shf(__mask)) & (__val)), 0)))
+
+#define __REG_FIELD_PREP(__mask, __val) \
+	((u32)((((typeof(__mask))(__val) << __bf_shf(__mask)) & (__mask))))
+
+#define REG_FIELD_PREP(__mask, __val) \
+	(__REG_FIELD_PREP(__mask, __val) + __REG_FIELD_PREP_CHK(__mask, __val))
 
 /**
  * REG_FIELD_GET() - Extract a u32 bitfield value
Signature · 1 line
Jani Nikula, Intel Open Source Graphics Center
#5 lore raw
Quoted 9 lines · Jani Nikula
Quoted 7 lines · Ashutosh Dixit

FIELD_PREP and REG_FIELD_PREP have checks requiring a compile time constant mask. When the mask comes in as the argument of a function these checks can can fail depending on the compiler (gcc vs clang), optimization level, etc. Use a simpler version of FIELD_PREP which skips these checks. The checks are not needed because the mask is formed using REG_GENMASK (so is actually a compile time constant).

Quoted 4 lines
Quoted 2 lines

v2: Split REG_FIELD_PREP into a macro with checks and one without and use
the one without checks in i915_hwmon.c (Gwan-gyeong Mun)

I frankly think you're solving the wrong problem here. See [1].

We can consider the sort of refactoring suggested in [1] in the future, right now I thought I'll offer what in my opinion is the correct way to fix the clang compile break incrementally with the current code. But otherwise feel free to go with whatever you think is the correct course of action for this issue. Even if we don't fix the issue the clang guys will (as they have in the past).

Thanks.
--
Ashutosh

Quoted 51 lines

[1] https://lore.kernel.org/r/[email protected]

Quoted 49 lines
---
 drivers/gpu/drm/i915/i915_hwmon.c    |  2 +-
 drivers/gpu/drm/i915/i915_reg_defs.h | 17 +++++++++++------
 2 files changed, 12 insertions(+), 7 deletions(-)
drivers/gpu/drm/i915/i915_hwmon.c +1 -1
index 9e97814930254..ae435b035229a 100644
@@ -112,7 +112,7 @@ hwm_field_scale_and_write(struct hwm_drvdata *ddat, i915_reg_t rgadr,
 	nval = DIV_ROUND_CLOSEST_ULL((u64)lval << nshift, scale_factor);
 
 	bits_to_clear = field_msk;
-	bits_to_set = FIELD_PREP(field_msk, nval);
+	bits_to_set = __REG_FIELD_PREP(field_msk, nval);
 
 	hwm_locked_with_pm_intel_uncore_rmw(ddat, rgadr,
 					    bits_to_clear, bits_to_set);
drivers/gpu/drm/i915/i915_reg_defs.h +11 -6
index f1859046a9c48..dddacc8d48928 100644
@@ -67,12 +67,17 @@
  *
  * @return: @__val masked and shifted into the field defined by @__mask.
  */
-#define REG_FIELD_PREP(__mask, __val)						\
-	((u32)((((typeof(__mask))(__val) << __bf_shf(__mask)) & (__mask)) +	\
-	       BUILD_BUG_ON_ZERO(!__is_constexpr(__mask)) +		\
-	       BUILD_BUG_ON_ZERO((__mask) == 0 || (__mask) > U32_MAX) +		\
-	       BUILD_BUG_ON_ZERO(!IS_POWER_OF_2((__mask) + (1ULL << __bf_shf(__mask)))) + \
-	       BUILD_BUG_ON_ZERO(__builtin_choose_expr(__is_constexpr(__val), (~((__mask) >> __bf_shf(__mask)) & (__val)), 0))))
+#define __REG_FIELD_PREP_CHK(__mask, __val) \
+	(BUILD_BUG_ON_ZERO(!__is_constexpr(__mask)) + \
+	 BUILD_BUG_ON_ZERO((__mask) == 0 || (__mask) > U32_MAX) + \
+	 BUILD_BUG_ON_ZERO(!IS_POWER_OF_2((__mask) + (1ULL << __bf_shf(__mask)))) + \
+	 BUILD_BUG_ON_ZERO(__builtin_choose_expr(__is_constexpr(__val), (~((__mask) >> __bf_shf(__mask)) & (__val)), 0)))
+
+#define __REG_FIELD_PREP(__mask, __val) \
+	((u32)((((typeof(__mask))(__val) << __bf_shf(__mask)) & (__mask))))
+
+#define REG_FIELD_PREP(__mask, __val) \
+	(__REG_FIELD_PREP(__mask, __val) + __REG_FIELD_PREP_CHK(__mask, __val))
 
 /**
  * REG_FIELD_GET() - Extract a u32 bitfield value