Re: [PATCH 1/1] x86/platform/x86: Fix count of CHas on multi-pci-segment arches

From: Andy Shevchenko
Date: Tue Mar 13 2018 - 13:46:57 EST


>>>> + pci_read_config_dword(dev, SKX_CAPID6, &val);
>>>> + return bitmap_weight((unsigned long *)&val, SKX_CHA_BIT_WIDTH);
>>>
>>>
>>> UB is here.
>>> Fix is simple, use unsigned long and drop this ugly casting.
>>>
>
> Just noticed that we have to do casting anyway.

No.

> pci_read_config_dword uses u32.
> bitmap_weight uses unsigned long.

...which would lead to UB.

So,

unsigned long bits;
u32 value;

...(..., &value);
bits = value;
...(&bits, ...);

--
With Best Regards,
Andy Shevchenko