Re: [PATCH v11 3/4] x86/cpu: Do a sanity check on required feature bits

From: Pawan Gupta

Date: Thu Mar 26 2026 - 15:08:13 EST


On Thu, Mar 26, 2026 at 06:36:15PM +0000, Maciej Wieczor-Retman wrote:
> >Do we need 2 loops? Can this be simplified as below:
> >
> >static void verify_required_features(const struct cpuinfo_x86 *c)
> >{
> > u32 required_features[NCAPINTS + 1] = REQUIRED_MASK_INIT;
> > char cap_buf[X86_CAP_BUF_SIZE];
> > int i, error = 0;
>
> Isn't this [NCAPINTS + 1] still a problem because for_each_set_bit() works in 64
> bit chunks? If NCAPINTS becomes an odd number in the future, the
> required_features[] last 32 bits will be uninitialized - REQUIRED_MASK_INIT is
> of (NCAPINTS * sizeof(u32)) size. So they might have some bits set and trigger
> the pr_warn() below.

Isn't a partially initialized array always zeroed out for the uninitialized
part?