[PATCH] EDAC: probe1 cleanup 1-of-2
- Add lower-level functions that handle various parts of the initialization
done by the xxx_probe1() functions. Some of the xxx_probe1() functions are
much too long and complicated (see "Chapter 5: Functions" in
Documentation/CodingStyle).
- Cleanup of probe1() functions in EDAC
Signed-off-by: Doug Thompson <norsk5@xmission.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
diff --git a/drivers/edac/amd76x_edac.c b/drivers/edac/amd76x_edac.c
index 303cb50..702141c 100644
--- a/drivers/edac/amd76x_edac.c
+++ b/drivers/edac/amd76x_edac.c
@@ -182,62 +182,20 @@
amd76x_process_error_info(mci, &info, 1);
}
-/**
- * amd76x_probe1 - Perform set up for detected device
- * @pdev; PCI device detected
- * @dev_idx: Device type index
- *
- * We have found an AMD76x and now need to set up the memory
- * controller status reporting. We configure and set up the
- * memory controller reporting and claim the device.
- */
-static int amd76x_probe1(struct pci_dev *pdev, int dev_idx)
+static void amd76x_init_csrows(struct mem_ctl_info *mci, struct pci_dev *pdev,
+ enum edac_type edac_mode)
{
- int rc = -ENODEV;
+ struct csrow_info *csrow;
+ u32 mba, mba_base, mba_mask, dms;
int index;
- struct mem_ctl_info *mci = NULL;
- enum edac_type ems_modes[] = {
- EDAC_NONE,
- EDAC_EC,
- EDAC_SECDED,
- EDAC_SECDED
- };
- u32 ems;
- u32 ems_mode;
- struct amd76x_error_info discard;
-
- debugf0("%s()\n", __func__);
- pci_read_config_dword(pdev, AMD76X_ECC_MODE_STATUS, &ems);
- ems_mode = (ems >> 10) & 0x3;
- mci = edac_mc_alloc(0, AMD76X_NR_CSROWS, AMD76X_NR_CHANS);
-
- if (mci == NULL) {
- rc = -ENOMEM;
- goto fail;
- }
-
- debugf0("%s(): mci = %p\n", __func__, mci);
- mci->dev = &pdev->dev;
- mci->mtype_cap = MEM_FLAG_RDDR;
- mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_EC | EDAC_FLAG_SECDED;
- mci->edac_cap = ems_mode ?
- (EDAC_FLAG_EC | EDAC_FLAG_SECDED) : EDAC_FLAG_NONE;
- mci->mod_name = EDAC_MOD_STR;
- mci->mod_ver = AMD76X_REVISION;
- mci->ctl_name = amd76x_devs[dev_idx].ctl_name;
- mci->edac_check = amd76x_check;
- mci->ctl_page_to_phys = NULL;
for (index = 0; index < mci->nr_csrows; index++) {
- struct csrow_info *csrow = &mci->csrows[index];
- u32 mba;
- u32 mba_base;
- u32 mba_mask;
- u32 dms;
+ csrow = &mci->csrows[index];
/* find the DRAM Chip Select Base address and mask */
pci_read_config_dword(pdev,
- AMD76X_MEM_BASE_ADDR + (index * 4), &mba);
+ AMD76X_MEM_BASE_ADDR + (index * 4),
+ &mba);
if (!(mba & BIT(0)))
continue;
@@ -252,9 +210,54 @@
csrow->grain = csrow->nr_pages << PAGE_SHIFT;
csrow->mtype = MEM_RDDR;
csrow->dtype = ((dms >> index) & 0x1) ? DEV_X4 : DEV_UNKNOWN;
- csrow->edac_mode = ems_modes[ems_mode];
+ csrow->edac_mode = edac_mode;
+ }
+}
+
+/**
+ * amd76x_probe1 - Perform set up for detected device
+ * @pdev; PCI device detected
+ * @dev_idx: Device type index
+ *
+ * We have found an AMD76x and now need to set up the memory
+ * controller status reporting. We configure and set up the
+ * memory controller reporting and claim the device.
+ */
+static int amd76x_probe1(struct pci_dev *pdev, int dev_idx)
+{
+ static const enum edac_type ems_modes[] = {
+ EDAC_NONE,
+ EDAC_EC,
+ EDAC_SECDED,
+ EDAC_SECDED
+ };
+ struct mem_ctl_info *mci = NULL;
+ u32 ems;
+ u32 ems_mode;
+ struct amd76x_error_info discard;
+
+ debugf0("%s()\n", __func__);
+ pci_read_config_dword(pdev, AMD76X_ECC_MODE_STATUS, &ems);
+ ems_mode = (ems >> 10) & 0x3;
+ mci = edac_mc_alloc(0, AMD76X_NR_CSROWS, AMD76X_NR_CHANS);
+
+ if (mci == NULL) {
+ return -ENOMEM;
}
+ debugf0("%s(): mci = %p\n", __func__, mci);
+ mci->dev = &pdev->dev;
+ mci->mtype_cap = MEM_FLAG_RDDR;
+ mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_EC | EDAC_FLAG_SECDED;
+ mci->edac_cap = ems_mode ?
+ (EDAC_FLAG_EC | EDAC_FLAG_SECDED) : EDAC_FLAG_NONE;
+ mci->mod_name = EDAC_MOD_STR;
+ mci->mod_ver = AMD76X_REVISION;
+ mci->ctl_name = amd76x_devs[dev_idx].ctl_name;
+ mci->edac_check = amd76x_check;
+ mci->ctl_page_to_phys = NULL;
+
+ amd76x_init_csrows(mci, pdev, ems_modes[ems_mode]);
amd76x_get_error_info(mci, &discard); /* clear counters */
/* Here we assume that we will never see multiple instances of this
@@ -270,9 +273,8 @@
return 0;
fail:
- if (mci != NULL)
- edac_mc_free(mci);
- return rc;
+ edac_mc_free(mci);
+ return -ENODEV;
}
/* returns count (>= 0), or negative on error */