Skip to content

Commit da62aa6

Browse files
committed
Merge branch 'linux_next' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/i7core
* 'linux_next' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/i7core: (34 commits) i7core_edac: return -ENODEV when devices were already probed i7core_edac: properly terminate pci_dev_table i7core_edac: Avoid PCI refcount to reach zero on successive load/reload i7core_edac: Fix refcount error at PCI devices i7core_edac: it is safe to i7core_unregister_mci() when mci=NULL i7core_edac: Fix an oops at i7core probe i7core_edac: Remove unused member channels in i7core_pvt i7core_edac: Remove unused arg csrow from get_dimm_config i7core_edac: Reduce args of i7core_register_mci i7core_edac: Introduce i7core_unregister_mci i7core_edac: Use saved pointers i7core_edac: Check probe counter in i7core_remove i7core_edac: Call pci_dev_put() when alloc_i7core_dev() failed i7core_edac: Fix error path of i7core_register_mci i7core_edac: Fix order of lines in i7core_register_mci i7core_edac: Always do get/put for all devices i7core_edac: Introduce i7core_pci_ctl_create/release i7core_edac: Introduce free_i7core_dev i7core_edac: Introduce alloc_i7core_dev i7core_edac: Reduce args of i7core_get_onedevice ...
2 parents f1ebdd6 + 76a7bd8 commit da62aa6

File tree

4 files changed

+313
-224
lines changed

4 files changed

+313
-224
lines changed

drivers/edac/edac_core.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@
4242

4343
#if PAGE_SHIFT < 20
4444
#define PAGES_TO_MiB( pages ) ( ( pages ) >> ( 20 - PAGE_SHIFT ) )
45+
#define MiB_TO_PAGES(mb) ((mb) >> (20 - PAGE_SHIFT))
4546
#else /* PAGE_SHIFT > 20 */
4647
#define PAGES_TO_MiB( pages ) ( ( pages ) << ( PAGE_SHIFT - 20 ) )
48+
#define MiB_TO_PAGES(mb) ((mb) >> (PAGE_SHIFT - 20))
4749
#endif
4850

4951
#define edac_printk(level, prefix, fmt, arg...) \
@@ -328,15 +330,15 @@ struct csrow_info {
328330

329331
struct mcidev_sysfs_group {
330332
const char *name; /* group name */
331-
struct mcidev_sysfs_attribute *mcidev_attr; /* group attributes */
333+
const struct mcidev_sysfs_attribute *mcidev_attr; /* group attributes */
332334
};
333335

334336
struct mcidev_sysfs_group_kobj {
335337
struct list_head list; /* list for all instances within a mc */
336338

337339
struct kobject kobj; /* kobj for the group */
338340

339-
struct mcidev_sysfs_group *grp; /* group description table */
341+
const struct mcidev_sysfs_group *grp; /* group description table */
340342
struct mem_ctl_info *mci; /* the parent */
341343
};
342344

@@ -347,7 +349,7 @@ struct mcidev_sysfs_group_kobj {
347349
struct mcidev_sysfs_attribute {
348350
/* It should use either attr or grp */
349351
struct attribute attr;
350-
struct mcidev_sysfs_group *grp; /* Points to a group of attributes */
352+
const struct mcidev_sysfs_group *grp; /* Points to a group of attributes */
351353

352354
/* Ops for show/store values at the attribute - not used on group */
353355
ssize_t (*show)(struct mem_ctl_info *,char *);
@@ -440,7 +442,7 @@ struct mem_ctl_info {
440442
* If attributes are desired, then set to array of attributes
441443
* If no attributes are desired, leave NULL
442444
*/
443-
struct mcidev_sysfs_attribute *mc_driver_sysfs_attributes;
445+
const struct mcidev_sysfs_attribute *mc_driver_sysfs_attributes;
444446

445447
/* work struct for this MC */
446448
struct delayed_work work;
@@ -810,6 +812,7 @@ extern struct mem_ctl_info *edac_mc_alloc(unsigned sz_pvt, unsigned nr_csrows,
810812
extern int edac_mc_add_mc(struct mem_ctl_info *mci);
811813
extern void edac_mc_free(struct mem_ctl_info *mci);
812814
extern struct mem_ctl_info *edac_mc_find(int idx);
815+
extern struct mem_ctl_info *find_mci_by_dev(struct device *dev);
813816
extern struct mem_ctl_info *edac_mc_del_mc(struct device *dev);
814817
extern int edac_mc_find_csrow_by_page(struct mem_ctl_info *mci,
815818
unsigned long page);

drivers/edac/edac_mc.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ struct mem_ctl_info *edac_mc_alloc(unsigned sz_pvt, unsigned nr_csrows,
207207
}
208208

209209
mci->op_state = OP_ALLOC;
210+
INIT_LIST_HEAD(&mci->grp_kobj_list);
210211

211212
/*
212213
* Initialize the 'root' kobj for the edac_mc controller
@@ -234,18 +235,24 @@ EXPORT_SYMBOL_GPL(edac_mc_alloc);
234235
*/
235236
void edac_mc_free(struct mem_ctl_info *mci)
236237
{
238+
debugf1("%s()\n", __func__);
239+
237240
edac_mc_unregister_sysfs_main_kobj(mci);
241+
242+
/* free the mci instance memory here */
243+
kfree(mci);
238244
}
239245
EXPORT_SYMBOL_GPL(edac_mc_free);
240246

241247

242-
/*
248+
/**
243249
* find_mci_by_dev
244250
*
245251
* scan list of controllers looking for the one that manages
246252
* the 'dev' device
253+
* @dev: pointer to a struct device related with the MCI
247254
*/
248-
static struct mem_ctl_info *find_mci_by_dev(struct device *dev)
255+
struct mem_ctl_info *find_mci_by_dev(struct device *dev)
249256
{
250257
struct mem_ctl_info *mci;
251258
struct list_head *item;
@@ -261,6 +268,7 @@ static struct mem_ctl_info *find_mci_by_dev(struct device *dev)
261268

262269
return NULL;
263270
}
271+
EXPORT_SYMBOL_GPL(find_mci_by_dev);
264272

265273
/*
266274
* handler for EDAC to check if NMI type handler has asserted interrupt

drivers/edac/edac_mc_sysfs.c

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -631,9 +631,6 @@ static void edac_mci_control_release(struct kobject *kobj)
631631

632632
/* decrement the module ref count */
633633
module_put(mci->owner);
634-
635-
/* free the mci instance memory here */
636-
kfree(mci);
637634
}
638635

639636
static struct kobj_type ktype_mci = {
@@ -713,6 +710,8 @@ int edac_mc_register_sysfs_main_kobj(struct mem_ctl_info *mci)
713710
*/
714711
void edac_mc_unregister_sysfs_main_kobj(struct mem_ctl_info *mci)
715712
{
713+
debugf1("%s()\n", __func__);
714+
716715
/* delete the kobj from the mc_kset */
717716
kobject_put(&mci->edac_mci_kobj);
718717
}
@@ -760,8 +759,6 @@ static void edac_inst_grp_release(struct kobject *kobj)
760759

761760
grp = container_of(kobj, struct mcidev_sysfs_group_kobj, kobj);
762761
mci = grp->mci;
763-
764-
kobject_put(&mci->edac_mci_kobj);
765762
}
766763

767764
/* Intermediate show/store table */
@@ -784,25 +781,25 @@ static struct kobj_type ktype_inst_grp = {
784781
* object tree.
785782
*/
786783
static int edac_create_mci_instance_attributes(struct mem_ctl_info *mci,
787-
struct mcidev_sysfs_attribute *sysfs_attrib,
784+
const struct mcidev_sysfs_attribute *sysfs_attrib,
788785
struct kobject *kobj)
789786
{
790787
int err;
791788

792789
debugf1("%s()\n", __func__);
793790

794791
while (sysfs_attrib) {
792+
debugf1("%s() sysfs_attrib = %p\n",__func__, sysfs_attrib);
795793
if (sysfs_attrib->grp) {
796794
struct mcidev_sysfs_group_kobj *grp_kobj;
797795

798796
grp_kobj = kzalloc(sizeof(*grp_kobj), GFP_KERNEL);
799797
if (!grp_kobj)
800798
return -ENOMEM;
801799

802-
list_add_tail(&grp_kobj->list, &mci->grp_kobj_list);
803-
804800
grp_kobj->grp = sysfs_attrib->grp;
805801
grp_kobj->mci = mci;
802+
list_add_tail(&grp_kobj->list, &mci->grp_kobj_list);
806803

807804
debugf0("%s() grp %s, mci %p\n", __func__,
808805
sysfs_attrib->grp->name, mci);
@@ -811,26 +808,28 @@ static int edac_create_mci_instance_attributes(struct mem_ctl_info *mci,
811808
&ktype_inst_grp,
812809
&mci->edac_mci_kobj,
813810
sysfs_attrib->grp->name);
814-
if (err)
811+
if (err < 0) {
812+
printk(KERN_ERR "kobject_init_and_add failed: %d\n", err);
815813
return err;
816-
814+
}
817815
err = edac_create_mci_instance_attributes(mci,
818816
grp_kobj->grp->mcidev_attr,
819817
&grp_kobj->kobj);
820818

821-
if (err)
819+
if (err < 0)
822820
return err;
823821
} else if (sysfs_attrib->attr.name) {
824822
debugf0("%s() file %s\n", __func__,
825823
sysfs_attrib->attr.name);
826824

827825
err = sysfs_create_file(kobj, &sysfs_attrib->attr);
826+
if (err < 0) {
827+
printk(KERN_ERR "sysfs_create_file failed: %d\n", err);
828+
return err;
829+
}
828830
} else
829831
break;
830832

831-
if (err) {
832-
return err;
833-
}
834833
sysfs_attrib++;
835834
}
836835

@@ -843,7 +842,7 @@ static int edac_create_mci_instance_attributes(struct mem_ctl_info *mci,
843842
* directory of this mci instance.
844843
*/
845844
static void edac_remove_mci_instance_attributes(struct mem_ctl_info *mci,
846-
struct mcidev_sysfs_attribute *sysfs_attrib,
845+
const struct mcidev_sysfs_attribute *sysfs_attrib,
847846
struct kobject *kobj, int count)
848847
{
849848
struct mcidev_sysfs_group_kobj *grp_kobj, *tmp;
@@ -855,13 +854,24 @@ static void edac_remove_mci_instance_attributes(struct mem_ctl_info *mci,
855854
* Remove first all the atributes
856855
*/
857856
while (sysfs_attrib) {
857+
debugf1("%s() sysfs_attrib = %p\n",__func__, sysfs_attrib);
858858
if (sysfs_attrib->grp) {
859-
list_for_each_entry(grp_kobj, &mci->grp_kobj_list,
860-
list)
861-
if (grp_kobj->grp == sysfs_attrib->grp)
859+
debugf1("%s() seeking for group %s\n",
860+
__func__, sysfs_attrib->grp->name);
861+
list_for_each_entry(grp_kobj,
862+
&mci->grp_kobj_list, list) {
863+
debugf1("%s() grp_kobj->grp = %p\n",__func__, grp_kobj->grp);
864+
if (grp_kobj->grp == sysfs_attrib->grp) {
862865
edac_remove_mci_instance_attributes(mci,
863866
grp_kobj->grp->mcidev_attr,
864867
&grp_kobj->kobj, count + 1);
868+
debugf0("%s() group %s\n", __func__,
869+
sysfs_attrib->grp->name);
870+
kobject_put(&grp_kobj->kobj);
871+
}
872+
}
873+
debugf1("%s() end of seeking for group %s\n",
874+
__func__, sysfs_attrib->grp->name);
865875
} else if (sysfs_attrib->attr.name) {
866876
debugf0("%s() file %s\n", __func__,
867877
sysfs_attrib->attr.name);
@@ -871,15 +881,14 @@ static void edac_remove_mci_instance_attributes(struct mem_ctl_info *mci,
871881
sysfs_attrib++;
872882
}
873883

874-
/*
875-
* Now that all attributes got removed, it is save to remove all groups
876-
*/
877-
if (!count)
878-
list_for_each_entry_safe(grp_kobj, tmp, &mci->grp_kobj_list,
879-
list) {
880-
debugf0("%s() grp %s\n", __func__, grp_kobj->grp->name);
881-
kobject_put(&grp_kobj->kobj);
882-
}
884+
/* Remove the group objects */
885+
if (count)
886+
return;
887+
list_for_each_entry_safe(grp_kobj, tmp,
888+
&mci->grp_kobj_list, list) {
889+
list_del(&grp_kobj->list);
890+
kfree(grp_kobj);
891+
}
883892
}
884893

885894

@@ -971,27 +980,28 @@ void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci)
971980
debugf0("%s()\n", __func__);
972981

973982
/* remove all csrow kobjects */
983+
debugf0("%s() unregister this mci kobj\n", __func__);
974984
for (i = 0; i < mci->nr_csrows; i++) {
975985
if (mci->csrows[i].nr_pages > 0) {
976986
debugf0("%s() unreg csrow-%d\n", __func__, i);
977987
kobject_put(&mci->csrows[i].kobj);
978988
}
979989
}
980990

981-
debugf0("%s() remove_link\n", __func__);
991+
/* remove this mci instance's attribtes */
992+
if (mci->mc_driver_sysfs_attributes) {
993+
debugf0("%s() unregister mci private attributes\n", __func__);
994+
edac_remove_mci_instance_attributes(mci,
995+
mci->mc_driver_sysfs_attributes,
996+
&mci->edac_mci_kobj, 0);
997+
}
982998

983999
/* remove the symlink */
1000+
debugf0("%s() remove_link\n", __func__);
9841001
sysfs_remove_link(&mci->edac_mci_kobj, EDAC_DEVICE_SYMLINK);
9851002

986-
debugf0("%s() remove_mci_instance\n", __func__);
987-
988-
/* remove this mci instance's attribtes */
989-
edac_remove_mci_instance_attributes(mci,
990-
mci->mc_driver_sysfs_attributes,
991-
&mci->edac_mci_kobj, 0);
992-
debugf0("%s() unregister this mci kobj\n", __func__);
993-
9941003
/* unregister this instance's kobject */
1004+
debugf0("%s() remove_mci_instance\n", __func__);
9951005
kobject_put(&mci->edac_mci_kobj);
9961006
}
9971007

0 commit comments

Comments
 (0)