Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 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>

authored by

Takashi Iwai and committed by
Borislav Petkov
e339f1ec 4e8d230d

+44 -115
+11 -36
drivers/edac/amd64_edac.c
··· 2663 2663 return true; 2664 2664 } 2665 2665 2666 - static int set_mc_sysfs_attrs(struct mem_ctl_info *mci) 2667 - { 2668 - struct amd64_pvt *pvt = mci->pvt_info; 2669 - int rc; 2670 - 2671 - rc = amd64_create_sysfs_dbg_files(mci); 2672 - if (rc < 0) 2673 - return rc; 2674 - 2675 - if (pvt->fam >= 0x10) { 2676 - rc = amd64_create_sysfs_inject_files(mci); 2677 - if (rc < 0) 2678 - return rc; 2679 - } 2680 - 2681 - return 0; 2682 - } 2683 - 2684 - static void del_mc_sysfs_attrs(struct mem_ctl_info *mci) 2685 - { 2686 - struct amd64_pvt *pvt = mci->pvt_info; 2687 - 2688 - amd64_remove_sysfs_dbg_files(mci); 2689 - 2690 - if (pvt->fam >= 0x10) 2691 - amd64_remove_sysfs_inject_files(mci); 2692 - } 2693 - 2694 2666 static void setup_mci_misc_attrs(struct mem_ctl_info *mci, 2695 2667 struct amd64_family_type *fam) 2696 2668 { ··· 2750 2778 return fam_type; 2751 2779 } 2752 2780 2781 + static const struct attribute_group *amd64_edac_attr_groups[] = { 2782 + #ifdef CONFIG_EDAC_DEBUG 2783 + &amd64_edac_dbg_group, 2784 + #endif 2785 + #ifdef CONFIG_EDAC_AMD64_ERROR_INJECTION 2786 + &amd64_edac_inj_group, 2787 + #endif 2788 + NULL 2789 + }; 2790 + 2753 2791 static int init_one_instance(struct pci_dev *F2) 2754 2792 { 2755 2793 struct amd64_pvt *pvt = NULL; ··· 2826 2844 mci->edac_cap = EDAC_FLAG_NONE; 2827 2845 2828 2846 ret = -ENODEV; 2829 - if (edac_mc_add_mc(mci)) { 2847 + if (edac_mc_add_mc_with_groups(mci, amd64_edac_attr_groups)) { 2830 2848 edac_dbg(1, "failed edac_mc_add_mc()\n"); 2831 2849 goto err_add_mc; 2832 - } 2833 - if (set_mc_sysfs_attrs(mci)) { 2834 - edac_dbg(1, "failed edac_mc_add_mc()\n"); 2835 - goto err_add_sysfs; 2836 2850 } 2837 2851 2838 2852 /* register stuff with EDAC MCE */ ··· 2843 2865 2844 2866 return 0; 2845 2867 2846 - err_add_sysfs: 2847 - edac_mc_del_mc(mci->pdev); 2848 2868 err_add_mc: 2849 2869 edac_mc_free(mci); 2850 2870 ··· 2916 2940 mci = find_mci_by_dev(&pdev->dev); 2917 2941 WARN_ON(!mci); 2918 2942 2919 - del_mc_sysfs_attrs(mci); 2920 2943 /* Remove from EDAC CORE tracking list */ 2921 2944 mci = edac_mc_del_mc(&pdev->dev); 2922 2945 if (!mci)
+2 -22
drivers/edac/amd64_edac.h
··· 453 453 }; 454 454 455 455 #ifdef CONFIG_EDAC_DEBUG 456 - int amd64_create_sysfs_dbg_files(struct mem_ctl_info *mci); 457 - void amd64_remove_sysfs_dbg_files(struct mem_ctl_info *mci); 458 - 459 - #else 460 - static inline int amd64_create_sysfs_dbg_files(struct mem_ctl_info *mci) 461 - { 462 - return 0; 463 - } 464 - static void inline amd64_remove_sysfs_dbg_files(struct mem_ctl_info *mci) 465 - { 466 - } 456 + extern const struct attribute_group amd64_edac_dbg_group; 467 457 #endif 468 458 469 459 #ifdef CONFIG_EDAC_AMD64_ERROR_INJECTION 470 - int amd64_create_sysfs_inject_files(struct mem_ctl_info *mci); 471 - void amd64_remove_sysfs_inject_files(struct mem_ctl_info *mci); 472 - 473 - #else 474 - static inline int amd64_create_sysfs_inject_files(struct mem_ctl_info *mci) 475 - { 476 - return 0; 477 - } 478 - static inline void amd64_remove_sysfs_inject_files(struct mem_ctl_info *mci) 479 - { 480 - } 460 + extern const struct attribute_group amd64_edac_inj_group; 481 461 #endif 482 462 483 463 /*
+11 -30
drivers/edac/amd64_edac_dbg.c
··· 40 40 static DEVICE_ATTR(topmem2, S_IRUGO, amd64_top_mem2_show, NULL); 41 41 static DEVICE_ATTR(dram_hole, S_IRUGO, amd64_hole_show, NULL); 42 42 43 - int amd64_create_sysfs_dbg_files(struct mem_ctl_info *mci) 44 - { 45 - int rc; 43 + static struct attribute *amd64_edac_dbg_attrs[] = { 44 + &dev_attr_dhar.attr, 45 + &dev_attr_dbam.attr, 46 + &dev_attr_topmem.attr, 47 + &dev_attr_topmem2.attr, 48 + &dev_attr_dram_hole.attr, 49 + NULL 50 + }; 46 51 47 - rc = device_create_file(&mci->dev, &dev_attr_dhar); 48 - if (rc < 0) 49 - return rc; 50 - rc = device_create_file(&mci->dev, &dev_attr_dbam); 51 - if (rc < 0) 52 - return rc; 53 - rc = device_create_file(&mci->dev, &dev_attr_topmem); 54 - if (rc < 0) 55 - return rc; 56 - rc = device_create_file(&mci->dev, &dev_attr_topmem2); 57 - if (rc < 0) 58 - return rc; 59 - rc = device_create_file(&mci->dev, &dev_attr_dram_hole); 60 - if (rc < 0) 61 - return rc; 62 - 63 - return 0; 64 - } 65 - 66 - void amd64_remove_sysfs_dbg_files(struct mem_ctl_info *mci) 67 - { 68 - device_remove_file(&mci->dev, &dev_attr_dhar); 69 - device_remove_file(&mci->dev, &dev_attr_dbam); 70 - device_remove_file(&mci->dev, &dev_attr_topmem); 71 - device_remove_file(&mci->dev, &dev_attr_topmem2); 72 - device_remove_file(&mci->dev, &dev_attr_dram_hole); 73 - } 52 + const struct attribute_group amd64_edac_dbg_group = { 53 + .attrs = amd64_edac_dbg_attrs, 54 + };
+20 -27
drivers/edac/amd64_edac_inj.c
··· 207 207 static DEVICE_ATTR(inject_read, S_IWUSR, 208 208 NULL, amd64_inject_read_store); 209 209 210 + static struct attribute *amd64_edac_inj_attrs[] = { 211 + &dev_attr_inject_section.attr, 212 + &dev_attr_inject_word.attr, 213 + &dev_attr_inject_ecc_vector.attr, 214 + &dev_attr_inject_write.attr, 215 + &dev_attr_inject_read.attr, 216 + NULL 217 + }; 210 218 211 - int amd64_create_sysfs_inject_files(struct mem_ctl_info *mci) 219 + static umode_t amd64_edac_inj_is_visible(struct kobject *kobj, 220 + struct attribute *attr, int idx) 212 221 { 213 - int rc; 222 + struct device *dev = kobj_to_dev(kobj); 223 + struct mem_ctl_info *mci = container_of(dev, struct mem_ctl_info, dev); 224 + struct amd64_pvt *pvt = mci->pvt_info; 214 225 215 - rc = device_create_file(&mci->dev, &dev_attr_inject_section); 216 - if (rc < 0) 217 - return rc; 218 - rc = device_create_file(&mci->dev, &dev_attr_inject_word); 219 - if (rc < 0) 220 - return rc; 221 - rc = device_create_file(&mci->dev, &dev_attr_inject_ecc_vector); 222 - if (rc < 0) 223 - return rc; 224 - rc = device_create_file(&mci->dev, &dev_attr_inject_write); 225 - if (rc < 0) 226 - return rc; 227 - rc = device_create_file(&mci->dev, &dev_attr_inject_read); 228 - if (rc < 0) 229 - return rc; 230 - 231 - return 0; 226 + if (pvt->fam < 0x10) 227 + return 0; 228 + return attr->mode; 232 229 } 233 230 234 - void amd64_remove_sysfs_inject_files(struct mem_ctl_info *mci) 235 - { 236 - device_remove_file(&mci->dev, &dev_attr_inject_section); 237 - device_remove_file(&mci->dev, &dev_attr_inject_word); 238 - device_remove_file(&mci->dev, &dev_attr_inject_ecc_vector); 239 - device_remove_file(&mci->dev, &dev_attr_inject_write); 240 - device_remove_file(&mci->dev, &dev_attr_inject_read); 241 - } 231 + const struct attribute_group amd64_edac_inj_group = { 232 + .attrs = amd64_edac_inj_attrs, 233 + .is_visible = amd64_edac_inj_is_visible, 234 + };