Re: [patch V6a 01/19] x86/cpu: Provide cpuid_read() et al.

From: Andy Shevchenko
Date: Thu Feb 15 2024 - 03:49:50 EST


On Wed, Feb 14, 2024 at 10:29 PM Thomas Gleixner <tglx@xxxxxxxxxxxxx> wrote:
>
> Provide a few helper functions to read CPUID leafs or individual registers
> into a data structure without requiring unions.

..

> +#define cpuid_subleaf(leaf, subleaf, regs) { \
> + BUILD_BUG_ON(sizeof(*(regs)) != 16); \
> + __cpuid_read(leaf, subleaf, (u32 *)(regs)); \
> +}
> +
> +#define cpuid_leaf(leaf, regs) { \
> + BUILD_BUG_ON(sizeof(*(regs)) != 16); \
> + __cpuid_read(leaf, 0, (u32 *)(regs)); \
> +}

..

> +#define cpuid_subleaf_reg(leaf, subleaf, regidx, reg) { \
> + BUILD_BUG_ON(sizeof(*(reg)) != 4); \
> + __cpuid_read_reg(leaf, subleaf, regidx, (u32 *)(reg)); \
> +}
> +
> +#define cpuid_leaf_reg(leaf, regidx, reg) { \
> + BUILD_BUG_ON(sizeof(*(reg)) != 4); \
> + __cpuid_read_reg(leaf, 0, regidx, (u32 *)(reg)); \
> +}

I'm wondering if we can use static_assert() instead of BUILD_BUG_ON()
in the above macros.

--
With Best Regards,
Andy Shevchenko