Commit e339f1ec authored by Takashi Iwai's avatar Takashi Iwai Committed by Borislav Petkov

EDAC: amd64: Use static attribute groups

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: default avatarTakashi Iwai <tiwai@suse.de>
Link: http://lkml.kernel.org/r/1423046938-18111-4-git-send-email-tiwai@suse.deSigned-off-by: default avatarBorislav Petkov <bp@suse.de>
parent 4e8d230d
...@@ -2663,34 +2663,6 @@ static bool ecc_enabled(struct pci_dev *F3, u16 nid) ...@@ -2663,34 +2663,6 @@ static bool ecc_enabled(struct pci_dev *F3, u16 nid)
return true; 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, static void setup_mci_misc_attrs(struct mem_ctl_info *mci,
struct amd64_family_type *fam) struct amd64_family_type *fam)
{ {
...@@ -2778,6 +2750,16 @@ static struct amd64_family_type *per_family_init(struct amd64_pvt *pvt) ...@@ -2778,6 +2750,16 @@ static struct amd64_family_type *per_family_init(struct amd64_pvt *pvt)
return fam_type; 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) static int init_one_instance(struct pci_dev *F2)
{ {
struct amd64_pvt *pvt = NULL; struct amd64_pvt *pvt = NULL;
...@@ -2844,14 +2826,10 @@ static int init_one_instance(struct pci_dev *F2) ...@@ -2844,14 +2826,10 @@ static int init_one_instance(struct pci_dev *F2)
mci->edac_cap = EDAC_FLAG_NONE; mci->edac_cap = EDAC_FLAG_NONE;
ret = -ENODEV; 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"); edac_dbg(1, "failed edac_mc_add_mc()\n");
goto err_add_mc; 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 */ /* register stuff with EDAC MCE */
if (report_gart_errors) if (report_gart_errors)
...@@ -2865,8 +2843,6 @@ static int init_one_instance(struct pci_dev *F2) ...@@ -2865,8 +2843,6 @@ static int init_one_instance(struct pci_dev *F2)
return 0; return 0;
err_add_sysfs:
edac_mc_del_mc(mci->pdev);
err_add_mc: err_add_mc:
edac_mc_free(mci); edac_mc_free(mci);
...@@ -2940,7 +2916,6 @@ static void remove_one_instance(struct pci_dev *pdev) ...@@ -2940,7 +2916,6 @@ static void remove_one_instance(struct pci_dev *pdev)
mci = find_mci_by_dev(&pdev->dev); mci = find_mci_by_dev(&pdev->dev);
WARN_ON(!mci); WARN_ON(!mci);
del_mc_sysfs_attrs(mci);
/* Remove from EDAC CORE tracking list */ /* Remove from EDAC CORE tracking list */
mci = edac_mc_del_mc(&pdev->dev); mci = edac_mc_del_mc(&pdev->dev);
if (!mci) if (!mci)
......
...@@ -453,31 +453,11 @@ struct ecc_settings { ...@@ -453,31 +453,11 @@ struct ecc_settings {
}; };
#ifdef CONFIG_EDAC_DEBUG #ifdef CONFIG_EDAC_DEBUG
int amd64_create_sysfs_dbg_files(struct mem_ctl_info *mci); extern const struct attribute_group amd64_edac_dbg_group;
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)
{
}
#endif #endif
#ifdef CONFIG_EDAC_AMD64_ERROR_INJECTION #ifdef CONFIG_EDAC_AMD64_ERROR_INJECTION
int amd64_create_sysfs_inject_files(struct mem_ctl_info *mci); extern const struct attribute_group amd64_edac_inj_group;
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)
{
}
#endif #endif
/* /*
......
...@@ -40,34 +40,15 @@ static DEVICE_ATTR(topmem, S_IRUGO, amd64_top_mem_show, NULL); ...@@ -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(topmem2, S_IRUGO, amd64_top_mem2_show, NULL);
static DEVICE_ATTR(dram_hole, S_IRUGO, amd64_hole_show, NULL); static DEVICE_ATTR(dram_hole, S_IRUGO, amd64_hole_show, NULL);
int amd64_create_sysfs_dbg_files(struct mem_ctl_info *mci) static struct attribute *amd64_edac_dbg_attrs[] = {
{ &dev_attr_dhar.attr,
int rc; &dev_attr_dbam.attr,
&dev_attr_topmem.attr,
rc = device_create_file(&mci->dev, &dev_attr_dhar); &dev_attr_topmem2.attr,
if (rc < 0) &dev_attr_dram_hole.attr,
return rc; NULL
rc = device_create_file(&mci->dev, &dev_attr_dbam); };
if (rc < 0)
return rc; const struct attribute_group amd64_edac_dbg_group = {
rc = device_create_file(&mci->dev, &dev_attr_topmem); .attrs = amd64_edac_dbg_attrs,
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);
}
...@@ -207,35 +207,28 @@ static DEVICE_ATTR(inject_write, S_IWUSR, ...@@ -207,35 +207,28 @@ static DEVICE_ATTR(inject_write, S_IWUSR,
static DEVICE_ATTR(inject_read, S_IWUSR, static DEVICE_ATTR(inject_read, S_IWUSR,
NULL, amd64_inject_read_store); NULL, amd64_inject_read_store);
static struct attribute *amd64_edac_inj_attrs[] = {
int amd64_create_sysfs_inject_files(struct mem_ctl_info *mci) &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; struct device *dev = kobj_to_dev(kobj);
struct mem_ctl_info *mci = container_of(dev, struct mem_ctl_info, dev);
rc = device_create_file(&mci->dev, &dev_attr_inject_section); struct amd64_pvt *pvt = mci->pvt_info;
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;
}
void amd64_remove_sysfs_inject_files(struct mem_ctl_info *mci) if (pvt->fam < 0x10)
{ return 0;
device_remove_file(&mci->dev, &dev_attr_inject_section); return attr->mode;
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);
} }
const struct attribute_group amd64_edac_inj_group = {
.attrs = amd64_edac_inj_attrs,
.is_visible = amd64_edac_inj_is_visible,
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment