EDAC: amd64: Use static attribute groups
authorTakashi Iwai <tiwai@suse.de>
Wed, 4 Feb 2015 10:48:53 +0000 (11:48 +0100)
committerBorislav Petkov <bp@suse.de>
Mon, 23 Feb 2015 12:08:09 +0000 (13:08 +0100)
Instead of calling device_create_file() and device_remove_file()
manually, pass the static attribute groups with the new
edac_mc_add_mc_with_groups(). The conditional creation of inject sysfs
files is done by a proper is_visible callback.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: http://lkml.kernel.org/r/1423046938-18111-4-git-send-email-tiwai@suse.de
Signed-off-by: Borislav Petkov <bp@suse.de>
drivers/edac/amd64_edac.c
drivers/edac/amd64_edac.h
drivers/edac/amd64_edac_dbg.c
drivers/edac/amd64_edac_inj.c

index 5907c1718f8c74fbe4a7d2c3bceb21759ed07422..3d6a511a9025b8002226b5ddcda4f56921a4dbf7 100644 (file)
@@ -2663,34 +2663,6 @@ static bool ecc_enabled(struct pci_dev *F3, u16 nid)
        return true;
 }
 
-static int set_mc_sysfs_attrs(struct mem_ctl_info *mci)
-{
-       struct amd64_pvt *pvt = mci->pvt_info;
-       int rc;
-
-       rc = amd64_create_sysfs_dbg_files(mci);
-       if (rc < 0)
-               return rc;
-
-       if (pvt->fam >= 0x10) {
-               rc = amd64_create_sysfs_inject_files(mci);
-               if (rc < 0)
-                       return rc;
-       }
-
-       return 0;
-}
-
-static void del_mc_sysfs_attrs(struct mem_ctl_info *mci)
-{
-       struct amd64_pvt *pvt = mci->pvt_info;
-
-       amd64_remove_sysfs_dbg_files(mci);
-
-       if (pvt->fam >= 0x10)
-               amd64_remove_sysfs_inject_files(mci);
-}
-
 static void setup_mci_misc_attrs(struct mem_ctl_info *mci,
                                 struct amd64_family_type *fam)
 {
@@ -2778,6 +2750,16 @@ static struct amd64_family_type *per_family_init(struct amd64_pvt *pvt)
        return fam_type;
 }
 
+static const struct attribute_group *amd64_edac_attr_groups[] = {
+#ifdef CONFIG_EDAC_DEBUG
+       &amd64_edac_dbg_group,
+#endif
+#ifdef CONFIG_EDAC_AMD64_ERROR_INJECTION
+       &amd64_edac_inj_group,
+#endif
+       NULL
+};
+
 static int init_one_instance(struct pci_dev *F2)
 {
        struct amd64_pvt *pvt = NULL;
@@ -2844,14 +2826,10 @@ static int init_one_instance(struct pci_dev *F2)
                mci->edac_cap = EDAC_FLAG_NONE;
 
        ret = -ENODEV;
-       if (edac_mc_add_mc(mci)) {
+       if (edac_mc_add_mc_with_groups(mci, amd64_edac_attr_groups)) {
                edac_dbg(1, "failed edac_mc_add_mc()\n");
                goto err_add_mc;
        }
-       if (set_mc_sysfs_attrs(mci)) {
-               edac_dbg(1, "failed edac_mc_add_mc()\n");
-               goto err_add_sysfs;
-       }
 
        /* register stuff with EDAC MCE */
        if (report_gart_errors)
@@ -2865,8 +2843,6 @@ static int init_one_instance(struct pci_dev *F2)
 
        return 0;
 
-err_add_sysfs:
-       edac_mc_del_mc(mci->pdev);
 err_add_mc:
        edac_mc_free(mci);
 
@@ -2940,7 +2916,6 @@ static void remove_one_instance(struct pci_dev *pdev)
        mci = find_mci_by_dev(&pdev->dev);
        WARN_ON(!mci);
 
-       del_mc_sysfs_attrs(mci);
        /* Remove from EDAC CORE tracking list */
        mci = edac_mc_del_mc(&pdev->dev);
        if (!mci)
index d8468c6679257b26b0157da63fd1d6bdd0633ba4..4bdec752d33096bfdfa9c5c201c81dba3c217af8 100644 (file)
@@ -453,31 +453,11 @@ struct ecc_settings {
 };
 
 #ifdef CONFIG_EDAC_DEBUG
-int amd64_create_sysfs_dbg_files(struct mem_ctl_info *mci);
-void amd64_remove_sysfs_dbg_files(struct mem_ctl_info *mci);
-
-#else
-static inline int amd64_create_sysfs_dbg_files(struct mem_ctl_info *mci)
-{
-       return 0;
-}
-static void inline amd64_remove_sysfs_dbg_files(struct mem_ctl_info *mci)
-{
-}
+extern const struct attribute_group amd64_edac_dbg_group;
 #endif
 
 #ifdef CONFIG_EDAC_AMD64_ERROR_INJECTION
-int amd64_create_sysfs_inject_files(struct mem_ctl_info *mci);
-void amd64_remove_sysfs_inject_files(struct mem_ctl_info *mci);
-
-#else
-static inline int amd64_create_sysfs_inject_files(struct mem_ctl_info *mci)
-{
-       return 0;
-}
-static inline void amd64_remove_sysfs_inject_files(struct mem_ctl_info *mci)
-{
-}
+extern const struct attribute_group amd64_edac_inj_group;
 #endif
 
 /*
index 2c1bbf7406058f4f80e1edb170db160c488cdcbc..4709c60798482e1e0b276ef35d810a30801111d4 100644 (file)
@@ -40,34 +40,15 @@ static DEVICE_ATTR(topmem, S_IRUGO, amd64_top_mem_show, NULL);
 static DEVICE_ATTR(topmem2, S_IRUGO, amd64_top_mem2_show, NULL);
 static DEVICE_ATTR(dram_hole, S_IRUGO, amd64_hole_show, NULL);
 
-int amd64_create_sysfs_dbg_files(struct mem_ctl_info *mci)
-{
-       int rc;
-
-       rc = device_create_file(&mci->dev, &dev_attr_dhar);
-       if (rc < 0)
-               return rc;
-       rc = device_create_file(&mci->dev, &dev_attr_dbam);
-       if (rc < 0)
-               return rc;
-       rc = device_create_file(&mci->dev, &dev_attr_topmem);
-       if (rc < 0)
-               return rc;
-       rc = device_create_file(&mci->dev, &dev_attr_topmem2);
-       if (rc < 0)
-               return rc;
-       rc = device_create_file(&mci->dev, &dev_attr_dram_hole);
-       if (rc < 0)
-               return rc;
-
-       return 0;
-}
-
-void amd64_remove_sysfs_dbg_files(struct mem_ctl_info *mci)
-{
-       device_remove_file(&mci->dev, &dev_attr_dhar);
-       device_remove_file(&mci->dev, &dev_attr_dbam);
-       device_remove_file(&mci->dev, &dev_attr_topmem);
-       device_remove_file(&mci->dev, &dev_attr_topmem2);
-       device_remove_file(&mci->dev, &dev_attr_dram_hole);
-}
+static struct attribute *amd64_edac_dbg_attrs[] = {
+       &dev_attr_dhar.attr,
+       &dev_attr_dbam.attr,
+       &dev_attr_topmem.attr,
+       &dev_attr_topmem2.attr,
+       &dev_attr_dram_hole.attr,
+       NULL
+};
+
+const struct attribute_group amd64_edac_dbg_group = {
+       .attrs = amd64_edac_dbg_attrs,
+};
index 0d66ae68d4681a9bb1ceedfca97fcafbde144d2c..e14977ff95dbb49dcd1038018091f37561cf86d4 100644 (file)
@@ -207,35 +207,28 @@ static DEVICE_ATTR(inject_write, S_IWUSR,
 static DEVICE_ATTR(inject_read,  S_IWUSR,
                   NULL, amd64_inject_read_store);
 
-
-int amd64_create_sysfs_inject_files(struct mem_ctl_info *mci)
+static struct attribute *amd64_edac_inj_attrs[] = {
+       &dev_attr_inject_section.attr,
+       &dev_attr_inject_word.attr,
+       &dev_attr_inject_ecc_vector.attr,
+       &dev_attr_inject_write.attr,
+       &dev_attr_inject_read.attr,
+       NULL
+};
+
+static umode_t amd64_edac_inj_is_visible(struct kobject *kobj,
+                                        struct attribute *attr, int idx)
 {
-       int rc;
-
-       rc = device_create_file(&mci->dev, &dev_attr_inject_section);
-       if (rc < 0)
-               return rc;
-       rc = device_create_file(&mci->dev, &dev_attr_inject_word);
-       if (rc < 0)
-               return rc;
-       rc = device_create_file(&mci->dev, &dev_attr_inject_ecc_vector);
-       if (rc < 0)
-               return rc;
-       rc = device_create_file(&mci->dev, &dev_attr_inject_write);
-       if (rc < 0)
-               return rc;
-       rc = device_create_file(&mci->dev, &dev_attr_inject_read);
-       if (rc < 0)
-               return rc;
-
-       return 0;
-}
+       struct device *dev = kobj_to_dev(kobj);
+       struct mem_ctl_info *mci = container_of(dev, struct mem_ctl_info, dev);
+       struct amd64_pvt *pvt = mci->pvt_info;
 
-void amd64_remove_sysfs_inject_files(struct mem_ctl_info *mci)
-{
-       device_remove_file(&mci->dev, &dev_attr_inject_section);
-       device_remove_file(&mci->dev, &dev_attr_inject_word);
-       device_remove_file(&mci->dev, &dev_attr_inject_ecc_vector);
-       device_remove_file(&mci->dev, &dev_attr_inject_write);
-       device_remove_file(&mci->dev, &dev_attr_inject_read);
+       if (pvt->fam < 0x10)
+               return 0;
+       return attr->mode;
 }
+
+const struct attribute_group amd64_edac_inj_group = {
+       .attrs = amd64_edac_inj_attrs,
+       .is_visible = amd64_edac_inj_is_visible,
+};