linux/include
Vincent Mailhol 41e98f2789 bits: introduce fixed-type GENMASK_U*()
[ Upstream commit 19408200c0 ]

Add GENMASK_TYPE() which generalizes __GENMASK() to support different
types, and implement fixed-types versions of GENMASK() based on it.
The fixed-type version allows more strict checks to the min/max values
accepted, which is useful for defining registers like implemented by
i915 and xe drivers with their REG_GENMASK*() macros.

The strict checks rely on shift-count-overflow compiler check to fail
the build if a number outside of the range allowed is passed.
Example:

  #define FOO_MASK GENMASK_U32(33, 4)

will generate a warning like:

  include/linux/bits.h:51:27: error: right shift count >= width of type [-Werror=shift-count-overflow]
     51 |               type_max(t) >> (BITS_PER_TYPE(t) - 1 - (h)))))
        |                           ^~

The result is casted to the corresponding fixed width type. For
example, GENMASK_U8() returns an u8. Note that because of the C
promotion rules, GENMASK_U8() and GENMASK_U16() will immediately be
promoted to int if used in an expression. Regardless, the main goal is
not to get the correct type, but rather to enforce more checks at
compile time.

While GENMASK_TYPE() is crafted to cover all variants, including the
already existing GENMASK(), GENMASK_ULL() and GENMASK_U128(), for the
moment, only use it for the newly introduced GENMASK_U*(). The
consolidation will be done in a separate change.

Co-developed-by: Yury Norov <yury.norov@gmail.com>
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
Acked-by: Jani Nikula <jani.nikula@intel.com>
Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Yury Norov <yury.norov@gmail.com>
Stable-dep-of: 2ba5772e53 ("gpio: idio-16: Define fixed direction of the GPIO lines")
Signed-off-by: William Breathitt Gray <wbg@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2025-11-02 22:15:22 +09:00
..
acpi ACPICA: Allow to skip Global Lock initialization 2025-10-19 16:34:00 +02:00
asm-generic asm-generic/io.h: Skip trace helpers if rwmmio events are disabled 2025-10-19 16:33:35 +02:00
clocksource x86/hyperv: Fix hv tsc page based sched_clock for hibernation 2024-12-27 14:02:15 +01:00
crypto crypto: sha256 - fix crash at kexec 2025-10-06 11:17:51 +02:00
cxl cxl: Move mailbox related bits to the same context 2024-09-12 08:38:01 -07:00
drm drm/tests: Do not use drm_fb_blit() in format-helper tests 2025-08-28 16:31:12 +02:00
dt-bindings dt-bindings: clock: sunxi: Export PLL_VIDEO_2X and PLL_MIPI 2025-02-08 09:57:09 +01:00
keys KEYS: Remove unused declarations 2024-09-20 18:28:26 +03:00
kunit kunit: platform: Resolve 'struct completion' warning 2025-02-21 14:01:25 +01:00
kvm KVM: arm64: Refine PMU defines for number of counters 2024-08-16 13:09:12 +01:00
linux bits: introduce fixed-type GENMASK_U*() 2025-11-02 22:15:22 +09:00
math-emu powerpc/math-emu: Remove -w build flag and fix warnings 2022-09-05 17:28:25 +10:00
media media: v4l2-subdev: Fix alloc failure check in v4l2_subdev_call_state_try() 2025-10-19 16:33:34 +02:00
memory memory: renesas-rpc-if: Remove Runtime PM wrappers 2023-01-23 11:48:00 +01:00
misc cxl: fix typo in comment 2022-11-24 23:12:19 +11:00
net bonding: check xdp prog when set bond mode 2025-11-02 22:15:22 +09:00
pcmcia ARM: pxa/sa1100: move I/O space to PCI_IOBASE 2022-05-07 22:56:17 +02:00
ras mm/memory-failure: remove obsolete MF_MSG_DIFFERENT_COMPOUND 2024-07-12 15:52:22 -07:00
rdma RDMA/uverbs: Propagate errors from rdma_lookup_get_uobject() 2025-05-29 11:02:19 +02:00
rv rv: Reset per-task monitors also for idle tasks 2025-02-17 10:05:30 +01:00
scsi move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
soc soc: qcom: ice: introduce devm_of_qcom_ice_get 2025-05-02 07:58:52 +02:00
sound ASoC: tas2781: Fix the wrong step for TLV on tas2781 2025-08-15 12:14:06 +02:00
target move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
trace dma-mapping: fix direction in dma_alloc direction traces 2025-10-19 16:33:34 +02:00
uapi HID: hidraw: tighten ioctl command parsing 2025-10-15 12:00:12 +02:00
ufs scsi: ufs: Introduce quirk to extend PA_HIBERN8TIME for UFS devices 2025-05-29 11:01:58 +02:00
vdso vdso: Add struct __kernel_old_timeval forward declaration to gettime.h 2025-10-15 11:59:58 +02:00
video fbdev: da8xx: remove the driver 2024-10-15 10:08:23 +02:00
xen xen/mcelog: Add __nonstring annotations for unterminated strings 2025-04-20 10:15:12 +02:00