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

From: Liang, Kan
Date: Tue Mar 13 2018 - 13:43:04 EST




On 3/13/2018 1:16 PM, Liang, Kan wrote:


On 3/13/2018 11:58 AM, Andy Shevchenko wrote:
On Tue, Mar 13, 2018 at 3:42 AM, Liang, Kan <kan.liang@xxxxxxxxxxxxxxx> wrote:

+#define SKX_CAPID6ÂÂÂÂÂÂÂÂÂÂÂÂ 0x9c
+#define SKX_CHA_BIT_WIDTHÂÂÂÂÂ 28
+
 static int skx_count_chabox(void)
 {
+ÂÂÂÂÂÂ struct pci_dev *dev = NULL;
+ÂÂÂÂÂÂ u32 val = 0;


+ÂÂÂÂÂÂ dev = pci_get_device(PCI_VENDOR_ID_INTEL, 0x2083, dev);
+ÂÂÂÂÂÂ if (!dev)
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ return 0;

Where is pci_dev_put()?


+ÂÂÂÂÂÂ 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.
pci_read_config_dword uses u32.
bitmap_weight uses unsigned long.

Thanks,
Kan