i7core_edac: move static vars to the beginning of the file
[pandora-kernel.git] / drivers / edac / i7core_edac.c
index e0187d1..4c1dcc1 100644 (file)
 
 #include "edac_core.h"
 
+/* Static vars */
+static LIST_HEAD(i7core_edac_list);
+static DEFINE_MUTEX(i7core_edac_lock);
+static int probed;
+
 /*
  * This is used for Nehalem-EP and Nehalem-EX devices, where the non-core
  * registers start at bus 255, and are not reported by BIOS.
@@ -261,11 +266,10 @@ struct i7core_pvt {
 
        /* Count indicator to show errors not got */
        unsigned                mce_overrun;
-};
 
-/* Static vars */
-static LIST_HEAD(i7core_edac_list);
-static DEFINE_MUTEX(i7core_edac_lock);
+       /* Struct to control EDAC polling */
+       struct edac_pci_ctl_info *i7core_pci;
+};
 
 #define PCI_DESCR(device, function, device_id) \
        .dev = (device),                        \
@@ -378,8 +382,6 @@ static const struct pci_device_id i7core_pci_tbl[] __devinitdata = {
        {0,}                    /* 0 terminated list. */
 };
 
-static struct edac_pci_ctl_info *i7core_pci;
-
 /****************************************************************************
                        Anciliary status routines
  ****************************************************************************/
@@ -1140,6 +1142,7 @@ static struct mcidev_sysfs_attribute i7core_udimm_counters_attrs[] = {
        ATTR_COUNTER(0),
        ATTR_COUNTER(1),
        ATTR_COUNTER(2),
+       { .attr = { .name = NULL } }
 };
 
 static struct mcidev_sysfs_group i7core_udimm_counters = {
@@ -1905,9 +1908,9 @@ static int i7core_register_mci(struct i7core_dev *i7core_dev,
        }
 
        /* allocating generic PCI control info */
-       i7core_pci = edac_pci_create_generic_ctl(&i7core_dev->pdev[0]->dev,
+       pvt->i7core_pci = edac_pci_create_generic_ctl(&i7core_dev->pdev[0]->dev,
                                                 EDAC_MOD_STR);
-       if (unlikely(!i7core_pci)) {
+       if (unlikely(!pvt->i7core_pci)) {
                printk(KERN_WARNING
                        "%s(): Unable to create PCI control\n",
                        __func__);
@@ -1948,8 +1951,6 @@ fail:
  *             < 0 for error code
  */
 
-static int probed = 0;
-
 static int __devinit i7core_probe(struct pci_dev *pdev,
                                  const struct pci_device_id *id)
 {
@@ -2007,12 +2008,10 @@ static void __devexit i7core_remove(struct pci_dev *pdev)
 {
        struct mem_ctl_info *mci;
        struct i7core_dev *i7core_dev, *tmp;
+       struct i7core_pvt *pvt;
 
        debugf0(__FILE__ ": %s()\n", __func__);
 
-       if (i7core_pci)
-               edac_pci_release_generic_ctl(i7core_pci);
-
        /*
         * we have a trouble here: pdev value for removal will be wrong, since
         * it will point to the X58 register used to detect that the machine
@@ -2023,19 +2022,28 @@ static void __devexit i7core_remove(struct pci_dev *pdev)
 
        mutex_lock(&i7core_edac_lock);
        list_for_each_entry_safe(i7core_dev, tmp, &i7core_edac_list, list) {
-               mci = edac_mc_del_mc(&i7core_dev->pdev[0]->dev);
-               if (mci) {
-                       struct i7core_pvt *pvt = mci->pvt_info;
-
+               mci = find_mci_by_dev(&i7core_dev->pdev[0]->dev);
+               if (unlikely(!mci || !mci->pvt_info)) {
+                       i7core_printk(KERN_ERR,
+                                     "Couldn't find mci hanler\n");
+               } else {
+                       pvt = mci->pvt_info;
                        i7core_dev = pvt->i7core_dev;
+
+                       if (likely(pvt->i7core_pci))
+                               edac_pci_release_generic_ctl(pvt->i7core_pci);
+                       else
+                               i7core_printk(KERN_ERR,
+                                             "Couldn't find mem_ctl_info for socket %d\n",
+                                             i7core_dev->socket);
+                       pvt->i7core_pci = NULL;
+
+                       edac_mc_del_mc(&i7core_dev->pdev[0]->dev);
+
                        edac_mce_unregister(&pvt->edac_mce);
                        kfree(mci->ctl_name);
                        edac_mc_free(mci);
                        i7core_put_devices(i7core_dev);
-               } else {
-                       i7core_printk(KERN_ERR,
-                                     "Couldn't find mci for socket %d\n",
-                                     i7core_dev->socket);
                }
        }
        probed--;