EDAC: Clean up device_create_file() & co
Subsystems (6)
cover EDAC: Clean up device_create_file() & co
Hi,
this is a series of cleanup patches to replace the manual device_create_file() and device_remove_file() calls with the static attribute groups. This simplifies the code and also avoids the possible races between the device registration and sysfs creations.
Non-x86 driver have been only compile-tested.
Takashi
===
Takashi Iwai (8):
EDAC: core: Use static attribute groups for managing sysfs entries
EDAC: Allow to pass driver-specific attribute groups
EDAC: amd64: Use static attribute groups
EDAC: i7core: Return proper error codes for kzalloc() errors
EDAC: i7core: Use static attribute groups for sysfs entries
EDAC: mpc85xx: Use static attribute groups for sysfs entries
EDAC: octeon: Use static attribute groups for sysfs entries
EDAC: highbank: Use static attribute groups for sysfs entries
drivers/edac/amd64_edac.c | 47 +++--------- drivers/edac/amd64_edac.h | 24 +----- drivers/edac/amd64_edac_dbg.c | 43 +++-------- drivers/edac/amd64_edac_inj.c | 51 ++++++------- drivers/edac/edac_core.h | 4 +- drivers/edac/edac_mc.c | 12 +-- drivers/edac/edac_mc_sysfs.c | 162 ++++++++++++++++++---------------------- drivers/edac/edac_module.h | 3 +- drivers/edac/highbank_mc_edac.c | 12 ++- drivers/edac/i7core_edac.c | 33 +++----- drivers/edac/mpc85xx_edac.c | 38 ++-------- drivers/edac/octeon_edac-lmc.c | 55 ++++---------- 12 files changed, 174 insertions(+), 310 deletions(-)
Signature · 1 line
2.2.2
PATCH 1/8 EDAC: core: Use static attribute groups for managing sysfs entries
Instead of manual calls of device_create_file() and device_remove_file(), use static attribute groups with proper is_visible callbacks for managing the sysfs entries.
This simplifies the code a lot and avoids the possible races.
--- drivers/edac/edac_mc_sysfs.c | 158 +++++++++++++++++++------------------------ 1 file changed, 71 insertions(+), 87 deletions(-)
drivers/edac/edac_mc_sysfs.c +71 -87
@@ -323,13 +323,14 @@ DEVICE_CHANNEL(ch5_dimm_label, S_IRUGO | S_IWUSR, channel_dimm_label_show, channel_dimm_label_store, 5);/* Total possible dynamic DIMM Label attribute file table */ -static struct device_attribute *dynamic_csrow_dimm_attr[] = { - &dev_attr_legacy_ch0_dimm_label.attr, - &dev_attr_legacy_ch1_dimm_label.attr, - &dev_attr_legacy_ch2_dimm_label.attr, - &dev_attr_legacy_ch3_dimm_label.attr, - &dev_attr_legacy_ch4_dimm_label.attr, - &dev_attr_legacy_ch5_dimm_label.attr +static struct attribute *dynamic_csrow_dimm_attr[] = { + &dev_attr_legacy_ch0_dimm_label.attr.attr, + &dev_attr_legacy_ch1_dimm_label.attr.attr, + &dev_attr_legacy_ch2_dimm_label.attr.attr, + &dev_attr_legacy_ch3_dimm_label.attr.attr, + &dev_attr_legacy_ch4_dimm_label.attr.attr, + &dev_attr_legacy_ch5_dimm_label.attr.attr, +NULL };/* possible dynamic channel ce_count attribute files */
@@ -347,13 +348,45 @@ DEVICE_CHANNEL(ch5_ce_count, S_IRUGO, channel_ce_count_show, NULL, 5);/* Total possible dynamic ce_count attribute file table */ -static struct device_attribute *dynamic_csrow_ce_count_attr[] = { - &dev_attr_legacy_ch0_ce_count.attr, - &dev_attr_legacy_ch1_ce_count.attr, - &dev_attr_legacy_ch2_ce_count.attr, - &dev_attr_legacy_ch3_ce_count.attr, - &dev_attr_legacy_ch4_ce_count.attr, - &dev_attr_legacy_ch5_ce_count.attr +static struct attribute *dynamic_csrow_ce_count_attr[] = { + &dev_attr_legacy_ch0_ce_count.attr.attr, + &dev_attr_legacy_ch1_ce_count.attr.attr, + &dev_attr_legacy_ch2_ce_count.attr.attr, + &dev_attr_legacy_ch3_ce_count.attr.attr, + &dev_attr_legacy_ch4_ce_count.attr.attr, + &dev_attr_legacy_ch5_ce_count.attr.attr, +NULL +}; + +static umode_t csrow_dev_is_visible (struct kobject *kobj, +struct attribute *attr,int idx) +{ +struct device *dev =kobj_to_dev (kobj); + struct csrow_info *csrow = container_of(dev, struct csrow_info, dev); + +if (idx >= csrow->nr_channels) +return 0 ; +/* Only expose populated DIMMs */ +if (!csrow->channels[idx]->dimm->nr_pages) +return 0 ; +return attr->mode; +} + + +static const struct attribute_group csrow_dev_dimm_group = { + .attrs = dynamic_csrow_dimm_attr, + .is_visible = csrow_dev_is_visible, +}; + +static const struct attribute_group csrow_dev_ce_count_group = { + .attrs = dynamic_csrow_ce_count_attr, + .is_visible = csrow_dev_is_visible, +}; + +static const struct attribute_group *csrow_dev_groups[] = { + &csrow_dev_dimm_group, + &csrow_dev_ce_count_group, +NULL };static inline int nr_pages_per_csrow (struct csrow_info *csrow)
@@ -370,13 +403,12 @@ static inline int nr_pages_per_csrow(struct csrow_info *csrow)static int edac_create_csrow_object (struct mem_ctl_info *mci,struct csrow_info *csrow,int index) { -int err, chan; -if (csrow->nr_channels >EDAC_NR_CHANNELS )return -ENODEV ; csrow->dev.type = &csrow_attr_type; csrow->dev.bus = mci->bus; + csrow->dev.groups = csrow_dev_groups;device_initialize (&csrow->dev); csrow->dev.parent = &mci->dev; csrow->mci = mci;
@@ -386,45 +418,13 @@ static int edac_create_csrow_object(struct mem_ctl_info *mci,edac_dbg (0 ,"creating (virtual) csrow node %s\n" ,dev_name (&csrow->dev)); - err =device_add (&csrow->dev); -if (err <0 ) -return err; - -for (chan =0 ; chan < csrow->nr_channels; chan++) { -/* Only expose populated DIMMs */ -if (!csrow->channels[chan]->dimm->nr_pages) -continue ; - err =device_create_file (&csrow->dev, - dynamic_csrow_dimm_attr[chan]); -if (err <0 ) - goto error; - err =device_create_file (&csrow->dev, - dynamic_csrow_ce_count_attr[chan]); -if (err <0 ) { -device_remove_file (&csrow->dev, - dynamic_csrow_dimm_attr[chan]); - goto error; - } - } - -return 0 ; - -error: -for (--chan; chan >=0 ; chan--) { -device_remove_file (&csrow->dev, - dynamic_csrow_dimm_attr[chan]); -device_remove_file (&csrow->dev, - dynamic_csrow_ce_count_attr[chan]); - } -put_device (&csrow->dev); - -return err; +return device_add (&csrow->dev); }/* Create a CSROW object under specifed edac_mc_device */ static int edac_create_csrow_objects (struct mem_ctl_info *mci) { -int err, i, chan; +int err, i;struct csrow_info *csrow;for (i =0 ; i < mci->nr_csrows; i++) {
@@ -446,14 +446,6 @@ error: csrow = mci->csrows[i];if (!nr_pages_per_csrow (csrow))continue ; -for (chan = csrow->nr_channels -1 ; chan >=0 ; chan--) { -if (!csrow->channels[chan]->dimm->nr_pages) -continue ; -device_remove_file (&csrow->dev, - dynamic_csrow_dimm_attr[chan]); -device_remove_file (&csrow->dev, - dynamic_csrow_ce_count_attr[chan]); - }put_device (&mci->csrows[i]->dev); }
@@ -462,23 +454,13 @@ error:static void edac_delete_csrow_objects (struct mem_ctl_info *mci) { -int i, chan; +int i;struct csrow_info *csrow;for (i = mci->nr_csrows -1 ; i >=0 ; i--) { csrow = mci->csrows[i];if (!nr_pages_per_csrow (csrow))continue ; -for (chan = csrow->nr_channels -1 ; chan >=0 ; chan--) { -if (!csrow->channels[chan]->dimm->nr_pages) -continue ; -edac_dbg (1 ,"Removing csrow %d channel %d sysfs nodes\n" , - i, chan); -device_remove_file (&csrow->dev, - dynamic_csrow_dimm_attr[chan]); -device_remove_file (&csrow->dev, - dynamic_csrow_ce_count_attr[chan]); - }device_unregister (&mci->csrows[i]->dev); } }
@@ -863,7 +845,8 @@ DEVICE_ATTR(ce_count, S_IRUGO, mci_ce_count_show, NULL);DEVICE_ATTR (max_location,S_IRUGO , mci_max_location_show,NULL );/* memory scrubber attribute file */ -DEVICE_ATTR (sdram_scrub_rate,0 ,NULL ,NULL ); +DEVICE_ATTR (sdram_scrub_rate,0 , mci_sdram_scrub_rate_show, + mci_sdram_scrub_rate_store);/* umode set later in is_visible */ static struct attribute *mci_attrs[] = { &dev_attr_reset_counters.attr,
@@ -875,11 +858,29 @@ static struct attribute *mci_attrs[] = { &dev_attr_ue_count.attr, &dev_attr_ce_count.attr, &dev_attr_max_location.attr, + &dev_attr_sdram_scrub_rate.attr,NULL }; +static umode_t mci_attr_is_visible (struct kobject *kobj, +struct attribute *attr,int idx) +{ +struct device *dev =kobj_to_dev (kobj); +struct mem_ctl_info *mci =to_mci (dev); +umode_t mode =0 ; + +if (attr != &dev_attr_sdram_scrub_rate.attr) +return attr->mode; +if (mci->get_sdram_scrub_rate) + mode |=S_IRUGO ; +if (mci->set_sdram_scrub_rate) + mode |=S_IWUSR ; +return mode; +} +static struct attribute_group mci_attr_grp = { .attrs = mci_attrs, + .is_visible = mci_attr_is_visible, }; static const struct attribute_group *mci_attr_groups[] = {
@@ -1010,22 +1011,6 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)return err; } -if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) { -if (mci->get_sdram_scrub_rate) { - dev_attr_sdram_scrub_rate.attr.mode |=S_IRUGO ; - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show; - } -if (mci->set_sdram_scrub_rate) { - dev_attr_sdram_scrub_rate.attr.mode |=S_IWUSR ; - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store; - } - err =device_create_file (&mci->dev, - &dev_attr_sdram_scrub_rate); -if (err) { -edac_dbg (1 ,"failure: create sdram_scrub_rate\n" ); - goto fail2; - } - }/* * Create the dimm/rank devices */
@@ -1070,7 +1055,6 @@ fail:continue ;device_unregister (&dimm->dev); } -fail2:device_unregister (&mci->dev);bus_unregister (mci->bus);kfree (mci->bus->name);
Signature · 1 line
2.2.2
PATCH 2/8 EDAC: Allow to pass driver-specific attribute groups
In reply to Takashi IwaiAdd edac_mc_add_mc_with_groups() for initializing the mem_ctl_info object with the optional attribute groups. This allows drivers to pass additional sysfs entries without manual (and racy) device_create_file() and co calls.
edac_mc_add_mc() is kept as is, just calling edac_mc_add_with_groups() with NULL groups.
--- drivers/edac/edac_core.h | 4 +++- drivers/edac/edac_mc.c | 12 +++++++----- drivers/edac/edac_mc_sysfs.c | 4 +++- drivers/edac/edac_module.h | 3 ++- 4 files changed, 15 insertions(+), 8 deletions(-)
drivers/edac/edac_core.h +3 -1
@@ -446,7 +446,9 @@ struct mem_ctl_info *edac_mc_alloc(unsigned mc_num,unsigned n_layers, struct edac_mc_layer *layers, unsigned sz_pvt); -extern int edac_mc_add_mc (struct mem_ctl_info *mci); +extern int edac_mc_add_mc_with_groups (struct mem_ctl_info *mci, +const struct attribute_group **groups); +#define edac_mc_add_mc (mci) edac_mc_add_mc_with_groups(mci, NULL)extern void edac_mc_free (struct mem_ctl_info *mci);extern struct mem_ctl_info *edac_mc_find (int idx);extern struct mem_ctl_info *find_mci_by_dev (struct device *dev);
drivers/edac/edac_mc.c +7 -5
@@ -710,9 +710,10 @@ struct mem_ctl_info *edac_mc_find(int idx)EXPORT_SYMBOL (edac_mc_find);/** -* edac_mc_add_mc: Insert the 'mci' structure into the mci global list and -* create sysfs entries associated with mci structure +* edac_mc_add_mc_with_groups: Insert the 'mci' structure into the mci +* global list and create sysfs entries associated with mci structure * @mci: pointer to the mci structure to be added to the list +* @groups: optional attribute groups for the driver-specific sysfs entries * * Return: * 0 Success
@@ -720,7 +721,8 @@ EXPORT_SYMBOL(edac_mc_find);*/ /* FIXME - should a warning be printed if no error detection? correction? */ -int edac_mc_add_mc (struct mem_ctl_info *mci) +int edac_mc_add_mc_with_groups (struct mem_ctl_info *mci, +const struct attribute_group **groups) {int ret = -EINVAL ;edac_dbg (0 ,"\n" );
@@ -771,7 +773,7 @@ int edac_mc_add_mc(struct mem_ctl_info *mci) mci->bus = &mc_bus[mci->mc_idx]; -if (edac_create_sysfs_mci_device (mci)) { +if (edac_create_sysfs_mci_device (mci, groups)) {edac_mc_printk (mci,KERN_WARNING ,"failed to create sysfs device\n" ); goto fail1;
@@ -805,7 +807,7 @@ fail0:mutex_unlock (&mem_ctls_mutex);return ret; } -EXPORT_SYMBOL_GPL (edac_mc_add_mc); +EXPORT_SYMBOL_GPL (edac_mc_add_mc_with_groups);/** * edac_mc_del_mc: Remove sysfs entries for specified mci structure and
drivers/edac/edac_mc_sysfs.c +3 -1
@@ -974,7 +974,8 @@ nomem:* 0 Success * !0 Failure */ -int edac_create_sysfs_mci_device (struct mem_ctl_info *mci) +int edac_create_sysfs_mci_device (struct mem_ctl_info *mci, +const struct attribute_group **groups) {int i, err;
@@ -998,6 +999,7 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci) mci->dev.parent = mci_pdev; mci->dev.bus = mci->bus; + mci->dev.groups = groups;dev_set_name (&mci->dev,"mc%d" , mci->mc_idx);dev_set_drvdata (&mci->dev, mci);pm_runtime_forbid (&mci->dev);
drivers/edac/edac_module.h +2 -1
@@ -22,7 +22,8 @@/* on edac_mc_sysfs.c */ int edac_mc_sysfs_init (void );void edac_mc_sysfs_exit (void ); -extern int edac_create_sysfs_mci_device (struct mem_ctl_info *mci); +extern int edac_create_sysfs_mci_device (struct mem_ctl_info *mci, +const struct attribute_group **groups);extern void edac_remove_sysfs_mci_device (struct mem_ctl_info *mci);void edac_unregister_sysfs (struct mem_ctl_info *mci);extern int edac_get_log_ue (void );
Signature · 1 line
2.2.2
PATCH 3/8 EDAC: amd64: Use static attribute groups
In reply to Takashi IwaiInstead 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.
--- drivers/edac/amd64_edac.c | 47 ++++++++++----------------------------- drivers/edac/amd64_edac.h | 24 ++------------------ drivers/edac/amd64_edac_dbg.c | 43 ++++++++++-------------------------- drivers/edac/amd64_edac_inj.c | 51 +++++++++++++++++++------------------------ 4 files changed, 47 insertions(+), 118 deletions(-)
drivers/edac/amd64_edac.c +11 -36
@@ -2657,34 +2657,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) {
@@ -2772,6 +2744,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 ;
@@ -2838,14 +2820,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)
@@ -2859,8 +2837,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);
@@ -2934,7 +2910,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)
drivers/edac/amd64_edac.h +2 -22
@@ -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 /*
drivers/edac/amd64_edac_dbg.c +12 -31
46 lines not on this page · raw message
drivers/edac/amd64_edac_inj.c +22 -29
57 lines not on this page · raw message
Signature · 1 line
2.2.2
PATCH 4/8 EDAC: i7core: Return proper error codes for kzalloc() errors
In reply to Takashi Iwai--- drivers/edac/i7core_edac.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/edac/i7core_edac.c +2 -2
@@ -1177,7 +1177,7 @@ static int i7core_create_sysfs_devices(struct mem_ctl_info *mci) pvt->addrmatch_dev =kzalloc (sizeof (*pvt->addrmatch_dev),GFP_KERNEL );if (!pvt->addrmatch_dev) -return rc; +return -ENOMEM ; pvt->addrmatch_dev->type = &addrmatch_type; pvt->addrmatch_dev->bus = mci->dev.bus;
@@ -1198,7 +1198,7 @@ static int i7core_create_sysfs_devices(struct mem_ctl_info *mci)if (!pvt->chancounts_dev) {put_device (pvt->addrmatch_dev);device_del (pvt->addrmatch_dev); -return rc; +return -ENOMEM ; } pvt->chancounts_dev->type = &all_channel_counts_type;
Signature · 1 line
2.2.2
PATCH 5/8 EDAC: i7core: Use static attribute groups for sysfs entries
In reply to Takashi Iwai... instead of manual device_create_file() and device_remove_file() calls.
--- drivers/edac/i7core_edac.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-)
drivers/edac/i7core_edac.c +10 -19
@@ -1157,24 +1157,20 @@ static DEVICE_ATTR(inject_eccmask, S_IRUGO | S_IWUSR, static DEVICE_ATTR(inject_enable, S_IRUGO | S_IWUSR, i7core_inject_enable_show, i7core_inject_enable_store); +static struct attribute *i7core_dev_attrs[] = { + &dev_attr_inject_section.attr, + &dev_attr_inject_type.attr, + &dev_attr_inject_eccmask.attr, + &dev_attr_inject_enable.attr, +}; + +ATTRIBUTE_GROUPS (i7core_dev); +static int i7core_create_sysfs_devices (struct mem_ctl_info *mci) {struct i7core_pvt *pvt = mci->pvt_info;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_type); -if (rc <0 ) -return rc; - rc =device_create_file (&mci->dev, &dev_attr_inject_eccmask); -if (rc <0 ) -return rc; - rc =device_create_file (&mci->dev, &dev_attr_inject_enable); -if (rc <0 ) -return rc; - pvt->addrmatch_dev =kzalloc (sizeof (*pvt->addrmatch_dev),GFP_KERNEL );if (!pvt->addrmatch_dev)return -ENOMEM ;
@@ -1223,11 +1219,6 @@ static void i7core_delete_sysfs_devices(struct mem_ctl_info *mci)edac_dbg (1 ,"\n" ); -device_remove_file (&mci->dev, &dev_attr_inject_section); -device_remove_file (&mci->dev, &dev_attr_inject_type); -device_remove_file (&mci->dev, &dev_attr_inject_eccmask); -device_remove_file (&mci->dev, &dev_attr_inject_enable); -if (!pvt->is_registered) {put_device (pvt->chancounts_dev);device_del (pvt->chancounts_dev);
@@ -2259,7 +2250,7 @@ static int i7core_register_mci(struct i7core_dev *i7core_dev)enable_sdram_scrub_setting (mci);/* add this new MC control structure to EDAC's list of MCs */ -if (unlikely (edac_mc_add_mc (mci))) { +if (unlikely (edac_mc_add_mc_with_groups (mci, i7core_dev_groups))) {edac_dbg (0 ,"MC: failed edac_mc_add_mc()\n" );/* FIXME: perhaps some code should go here that disables error * reporting if we just enabled it
Signature · 1 line
2.2.2
PATCH 6/8 EDAC: mpc85xx: Use static attribute groups for sysfs entries
In reply to Takashi Iwai... instead of manual device_create_file() and device_remove_file() calls.
--- drivers/edac/mpc85xx_edac.c | 38 ++++++++------------------------------ 1 file changed, 8 insertions(+), 30 deletions(-)
drivers/edac/mpc85xx_edac.c +8 -30
@@ -134,29 +134,14 @@ DEVICE_ATTR(inject_data_lo, S_IRUGO | S_IWUSR,DEVICE_ATTR (inject_ctrl,S_IRUGO |S_IWUSR , mpc85xx_mc_inject_ctrl_show, mpc85xx_mc_inject_ctrl_store); -static int mpc85xx_create_sysfs_attributes (struct mem_ctl_info *mci) -{ -int rc; - - rc =device_create_file (&mci->dev, &dev_attr_inject_data_hi); -if (rc <0 ) -return rc; - rc =device_create_file (&mci->dev, &dev_attr_inject_data_lo); -if (rc <0 ) -return rc; - rc =device_create_file (&mci->dev, &dev_attr_inject_ctrl); -if (rc <0 ) -return rc; +static struct attribute *mpc85xx_dev_attrs[] = { + &dev_attr_inject_data_hi.attr, + &dev_attr_inject_data_lo.attr, + &dev_attr_inject_ctrl.attr, +NULL +}; -return 0 ; -} - -static void mpc85xx_remove_sysfs_attributes (struct mem_ctl_info *mci) -{ -device_remove_file (&mci->dev, &dev_attr_inject_data_hi); -device_remove_file (&mci->dev, &dev_attr_inject_data_lo); -device_remove_file (&mci->dev, &dev_attr_inject_ctrl); -} +ATTRIBUTE_GROUPS (mpc85xx_dev);/**************************** PCI Err device ***************************/ #ifdef CONFIG_PCI
@@ -1106,13 +1091,7 @@ static int mpc85xx_mc_err_probe(struct platform_device *op)/* clear all error bits */ out_be32 (pdata->mc_vbase +MPC85XX_MC_ERR_DETECT , ~0 ); -if (edac_mc_add_mc (mci)) { -edac_dbg (3 ,"failed edac_mc_add_mc()\n" ); - goto err; - } - -if (mpc85xx_create_sysfs_attributes (mci)) { -edac_mc_del_mc (mci->pdev); +if (edac_mc_add_mc_with_groups (mci, mpc85xx_dev_groups)) {edac_dbg (3 ,"failed edac_mc_add_mc()\n" ); goto err; }
@@ -1176,7 +1155,6 @@ static int mpc85xx_mc_err_remove(struct platform_device *op) orig_ddr_err_disable);out_be32 (pdata->mc_vbase +MPC85XX_MC_ERR_SBE , orig_ddr_err_sbe); -mpc85xx_remove_sysfs_attributes (mci);edac_mc_del_mc (&op->dev);edac_mc_free (mci);return 0 ;
Signature · 1 line
2.2.2
PATCH 7/8 EDAC: octeon: Use static attribute groups for sysfs entries
In reply to Takashi Iwai... instead of manual device_create_file() and device_remove_file() calls.
--- drivers/edac/octeon_edac-lmc.c | 55 ++++++++++-------------------------------- 1 file changed, 13 insertions(+), 42 deletions(-)
drivers/edac/octeon_edac-lmc.c +13 -42
@@ -209,35 +209,18 @@ static DEVICE_ATTR(row, S_IRUGO | S_IWUSR, static DEVICE_ATTR(col, S_IRUGO | S_IWUSR, octeon_mc_inject_col_show, octeon_mc_inject_col_store); +static struct attribute *octeon_dev_attrs[] = { + &dev_attr_inject.attr, + &dev_attr_error_type.attr, + &dev_attr_dimm.attr, + &dev_attr_rank.attr, + &dev_attr_bank.attr, + &dev_attr_row.attr, + &dev_attr_col.attr, +NULL +}; -static int octeon_set_mc_sysfs_attributes (struct mem_ctl_info *mci) -{ -int rc; - - rc =device_create_file (&mci->dev, &dev_attr_inject); -if (rc <0 ) -return rc; - rc =device_create_file (&mci->dev, &dev_attr_error_type); -if (rc <0 ) -return rc; - rc =device_create_file (&mci->dev, &dev_attr_dimm); -if (rc <0 ) -return rc; - rc =device_create_file (&mci->dev, &dev_attr_rank); -if (rc <0 ) -return rc; - rc =device_create_file (&mci->dev, &dev_attr_bank); -if (rc <0 ) -return rc; - rc =device_create_file (&mci->dev, &dev_attr_row); -if (rc <0 ) -return rc; - rc =device_create_file (&mci->dev, &dev_attr_col); -if (rc <0 ) -return rc; - -return 0 ; -} +ATTRIBUTE_GROUPS (octeon_dev);static int octeon_lmc_edac_probe (struct platform_device *pdev) {
@@ -271,18 +254,12 @@ static int octeon_lmc_edac_probe(struct platform_device *pdev) mci->ctl_name ="octeon-lmc-err" ; mci->edac_check = octeon_lmc_edac_poll; -if (edac_mc_add_mc (mci)) { +if (edac_mc_add_mc_with_groups (mci, octeon_dev_groups)) {dev_err (&pdev->dev,"edac_mc_add_mc() failed\n" );edac_mc_free (mci);return -ENXIO ; } -if (octeon_set_mc_sysfs_attributes (mci)) { -dev_err (&pdev->dev,"octeon_set_mc_sysfs_attributes() failed\n" ); -return -ENXIO ; - } - - cfg0.u64 =cvmx_read_csr (CVMX_LMCX_MEM_CFG0 (mc)); cfg0.s.intr_ded_ena =0 ;/* We poll */ cfg0.s.intr_sec_ena =0 ;
@@ -309,18 +286,12 @@ static int octeon_lmc_edac_probe(struct platform_device *pdev) mci->ctl_name ="co_lmc_err" ; mci->edac_check = octeon_lmc_edac_poll_o2; -if (edac_mc_add_mc (mci)) { +if (edac_mc_add_mc_with_groups (mci, octeon_dev_groups)) {dev_err (&pdev->dev,"edac_mc_add_mc() failed\n" );edac_mc_free (mci);return -ENXIO ; } -if (octeon_set_mc_sysfs_attributes (mci)) { -dev_err (&pdev->dev,"octeon_set_mc_sysfs_attributes() failed\n" ); -return -ENXIO ; - } - - en.u64 =cvmx_read_csr (CVMX_LMCX_MEM_CFG0 (mc)); en.s.intr_ded_ena =0 ;/* We poll */ en.s.intr_sec_ena =0 ;
Signature · 1 line
2.2.2
PATCH 8/8 EDAC: highbank: Use static attribute groups for sysfs entries
In reply to Takashi Iwai... instead of manual device_create_file() and device_remove_file() calls.
--- drivers/edac/highbank_mc_edac.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/edac/highbank_mc_edac.c +8 -4
@@ -124,6 +124,13 @@ static ssize_t highbank_mc_inject_ctrl(struct device *dev, static DEVICE_ATTR(inject_ctrl, S_IWUSR, NULL, highbank_mc_inject_ctrl); +static struct attribute *highbank_dev_attrs[] = { + &dev_attr_inject_ctrl.attr, +NULL +}; + +ATTRIBUTE_GROUPS (highbank_dev); +struct hb_mc_settings {int err_offset;int int_offset;
@@ -231,7 +238,7 @@ static int highbank_mc_probe(struct platform_device *pdev) dimm->mtype =MEM_DDR3 ; dimm->edac_mode =EDAC_SECDED ; - res =edac_mc_add_mc (mci); + res =edac_mc_add_mc_with_groups (mci, highbank_dev_groups);if (res <0 ) goto err;
@@ -243,8 +250,6 @@ static int highbank_mc_probe(struct platform_device *pdev) goto err2; } -device_create_file (&mci->dev, &dev_attr_inject_ctrl); -devres_close_group (&pdev->dev,NULL );return 0 ; err2:
@@ -259,7 +264,6 @@ static int highbank_mc_remove(struct platform_device *pdev) {struct mem_ctl_info *mci =platform_get_drvdata (pdev); -device_remove_file (&mci->dev, &dev_attr_inject_ctrl);edac_mc_del_mc (&pdev->dev);edac_mc_free (mci);return 0 ;
Signature · 1 line
2.2.2
Borislav Petkov
maintainerQuoted 8 lines · Takashi Iwai
Hi,
this is a series of cleanup patches to replace the manual
device_create_file()anddevice_remove_file()calls with the static attribute groups. This simplifies the code and also avoids the possible races between the device registration and sysfs creations.Non-x86 driver have been only compile-tested.
Thanks Takashi, patchset queued for 3.21.
Signature · 5 lines
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
--