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

From: Borislav Petkov
Date: Wed Jan 24 2024 - 07:25:49 EST


On Tue, Jan 23, 2024 at 01:53:30PM +0100, Thomas Gleixner wrote:
> +static inline void __cpuid_read(unsigned int leaf, unsigned int subleaf, u32 *regs)
> +{
> + regs[CPUID_EAX] = leaf;
> + regs[CPUID_ECX] = subleaf;
> + __cpuid(regs, regs + 1, regs + 2, regs + 3);

You have defines for the regs - might as well use them:

__cpuid(regs, regs + CPUID_EBX, regs + CPUID_ECX, regs + CPUID_EDX);

> +}
> +
> +#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)); \
> +}
> +
> +static inline void __cpuid_read_reg(unsigned int leaf, unsigned int subleaf,
> + enum cpuid_regs_idx regidx, u32 *reg)
> +{
> + u32 regs[4];
> +
> + __cpuid_read(leaf, subleaf, regs);
> + *reg = regs[regidx];

Why not do

return regs[regidx];

instead?

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette