Skip to content

Commit eae95da

Browse files
suryasaimadhugregkh
authored andcommitted
EDAC/amd64: Fix PCI component registration
commit 706657b upstream. In order to setup its PCI component, the driver needs any node private instance in order to get a reference to the PCI device and hand that into edac_pci_create_generic_ctl(). For convenience, it uses the 0th memory controller descriptor under the assumption that if any, the 0th will be always present. However, this assumption goes wrong when the 0th node doesn't have memory and the driver doesn't initialize an instance for it: EDAC amd64: F17h detected (node 0). ... EDAC amd64: Node 0: No DIMMs detected. But looking up node instances is not really needed - all one needs is the pointer to the proper device which gets discovered during instance init. So stash that pointer into a variable and use it when setting up the EDAC PCI component. Clear that variable when the driver needs to unwind due to some instances failing init to avoid any registration imbalance. Cc: <stable@vger.kernel.org> Signed-off-by: Borislav Petkov <bp@suse.de> Link: https://lkml.kernel.org/r/20201122150815.13808-1-bp@alien8.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3a881be commit eae95da

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

‎drivers/edac/amd64_edac.c‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ static struct amd64_family_type *fam_type;
1818
/* Per-node stuff */
1919
static struct ecc_settings **ecc_stngs;
2020

21+
/* Device for the PCI component */
22+
static struct device *pci_ctl_dev;
23+
2124
/*
2225
* Valid scrub rates for the K8 hardware memory scrubber. We map the scrubbing
2326
* bandwidth to a valid bit pattern. The 'set' operation finds the 'matching-
@@ -2683,6 +2686,9 @@ reserve_mc_sibling_devs(struct amd64_pvt *pvt, u16 pci_id1, u16 pci_id2)
26832686
return -ENODEV;
26842687
}
26852688

2689+
if (!pci_ctl_dev)
2690+
pci_ctl_dev = &pvt->F0->dev;
2691+
26862692
edac_dbg(1, "F0: %s\n", pci_name(pvt->F0));
26872693
edac_dbg(1, "F3: %s\n", pci_name(pvt->F3));
26882694
edac_dbg(1, "F6: %s\n", pci_name(pvt->F6));
@@ -2707,6 +2713,9 @@ reserve_mc_sibling_devs(struct amd64_pvt *pvt, u16 pci_id1, u16 pci_id2)
27072713
return -ENODEV;
27082714
}
27092715

2716+
if (!pci_ctl_dev)
2717+
pci_ctl_dev = &pvt->F2->dev;
2718+
27102719
edac_dbg(1, "F1: %s\n", pci_name(pvt->F1));
27112720
edac_dbg(1, "F2: %s\n", pci_name(pvt->F2));
27122721
edac_dbg(1, "F3: %s\n", pci_name(pvt->F3));
@@ -3623,21 +3632,10 @@ static void remove_one_instance(unsigned int nid)
36233632

36243633
static void setup_pci_device(void)
36253634
{
3626-
struct mem_ctl_info *mci;
3627-
struct amd64_pvt *pvt;
3628-
36293635
if (pci_ctl)
36303636
return;
36313637

3632-
mci = edac_mc_find(0);
3633-
if (!mci)
3634-
return;
3635-
3636-
pvt = mci->pvt_info;
3637-
if (pvt->umc)
3638-
pci_ctl = edac_pci_create_generic_ctl(&pvt->F0->dev, EDAC_MOD_STR);
3639-
else
3640-
pci_ctl = edac_pci_create_generic_ctl(&pvt->F2->dev, EDAC_MOD_STR);
3638+
pci_ctl = edac_pci_create_generic_ctl(pci_ctl_dev, EDAC_MOD_STR);
36413639
if (!pci_ctl) {
36423640
pr_warn("%s(): Unable to create PCI control\n", __func__);
36433641
pr_warn("%s(): PCI error report via EDAC not set\n", __func__);
@@ -3716,6 +3714,8 @@ static int __init amd64_edac_init(void)
37163714
return 0;
37173715

37183716
err_pci:
3717+
pci_ctl_dev = NULL;
3718+
37193719
msrs_free(msrs);
37203720
msrs = NULL;
37213721

@@ -3745,6 +3745,8 @@ static void __exit amd64_edac_exit(void)
37453745
kfree(ecc_stngs);
37463746
ecc_stngs = NULL;
37473747

3748+
pci_ctl_dev = NULL;
3749+
37483750
msrs_free(msrs);
37493751
msrs = NULL;
37503752
}

0 commit comments

Comments
 (0)