Commit 6e5a8748 authored by Dave Peterson's avatar Dave Peterson Committed by Linus Torvalds

[PATCH] EDAC: kobject_init/kobject_put fixes

- Remove calls to kobject_init().  These are unnecessary because
  kobject_register() calls kobject_init().

- Remove extra calls to kobject_put().  When we call
  kobject_unregister(), this releases our reference to the kobject.
  The extra calls to kobject_put() may cause the reference count to
  drop to 0 while a kobject is still in use.
Signed-off-by: default avatarDavid S. Peterson <dsp@llnl.gov>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 028a7b6d
...@@ -278,8 +278,6 @@ static int edac_sysfs_memctrl_setup(void) ...@@ -278,8 +278,6 @@ static int edac_sysfs_memctrl_setup(void)
if (!err) { if (!err) {
/* Init the MC's kobject */ /* Init the MC's kobject */
memset(&edac_memctrl_kobj, 0, sizeof (edac_memctrl_kobj)); memset(&edac_memctrl_kobj, 0, sizeof (edac_memctrl_kobj));
kobject_init(&edac_memctrl_kobj);
edac_memctrl_kobj.parent = &edac_class.kset.kobj; edac_memctrl_kobj.parent = &edac_class.kset.kobj;
edac_memctrl_kobj.ktype = &ktype_memctrl; edac_memctrl_kobj.ktype = &ktype_memctrl;
...@@ -314,9 +312,6 @@ static void edac_sysfs_memctrl_teardown(void) ...@@ -314,9 +312,6 @@ static void edac_sysfs_memctrl_teardown(void)
/* Unregister the MC's kobject */ /* Unregister the MC's kobject */
kobject_unregister(&edac_memctrl_kobj); kobject_unregister(&edac_memctrl_kobj);
/* release the master edac mc kobject */
kobject_put(&edac_memctrl_kobj);
/* Unregister the 'edac' object */ /* Unregister the 'edac' object */
sysdev_class_unregister(&edac_class); sysdev_class_unregister(&edac_class);
#endif /* DISABLE_EDAC_SYSFS */ #endif /* DISABLE_EDAC_SYSFS */
...@@ -594,8 +589,6 @@ static int edac_sysfs_pci_setup(void) ...@@ -594,8 +589,6 @@ static int edac_sysfs_pci_setup(void)
debugf1("%s()\n", __func__); debugf1("%s()\n", __func__);
memset(&edac_pci_kobj, 0, sizeof(edac_pci_kobj)); memset(&edac_pci_kobj, 0, sizeof(edac_pci_kobj));
kobject_init(&edac_pci_kobj);
edac_pci_kobj.parent = &edac_class.kset.kobj; edac_pci_kobj.parent = &edac_class.kset.kobj;
edac_pci_kobj.ktype = &ktype_edac_pci; edac_pci_kobj.ktype = &ktype_edac_pci;
...@@ -619,7 +612,6 @@ static void edac_sysfs_pci_teardown(void) ...@@ -619,7 +612,6 @@ static void edac_sysfs_pci_teardown(void)
debugf0("%s()\n", __func__); debugf0("%s()\n", __func__);
kobject_unregister(&edac_pci_kobj); kobject_unregister(&edac_pci_kobj);
kobject_put(&edac_pci_kobj);
#endif #endif
} }
...@@ -829,7 +821,6 @@ static int edac_create_csrow_object(struct kobject *edac_mci_kobj, ...@@ -829,7 +821,6 @@ static int edac_create_csrow_object(struct kobject *edac_mci_kobj,
/* generate ..../edac/mc/mc<id>/csrow<index> */ /* generate ..../edac/mc/mc<id>/csrow<index> */
kobject_init(&csrow->kobj);
csrow->kobj.parent = edac_mci_kobj; csrow->kobj.parent = edac_mci_kobj;
csrow->kobj.ktype = &ktype_csrow; csrow->kobj.ktype = &ktype_csrow;
...@@ -1104,7 +1095,6 @@ static int edac_create_sysfs_mci_device(struct mem_ctl_info *mci) ...@@ -1104,7 +1095,6 @@ static int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
debugf0("%s() idx=%d\n", __func__, mci->mc_idx); debugf0("%s() idx=%d\n", __func__, mci->mc_idx);
memset(edac_mci_kobj, 0, sizeof(*edac_mci_kobj)); memset(edac_mci_kobj, 0, sizeof(*edac_mci_kobj));
kobject_init(edac_mci_kobj);
/* set the name of the mc<id> object */ /* set the name of the mc<id> object */
err = kobject_set_name(edac_mci_kobj,"mc%d",mci->mc_idx); err = kobject_set_name(edac_mci_kobj,"mc%d",mci->mc_idx);
...@@ -1123,10 +1113,8 @@ static int edac_create_sysfs_mci_device(struct mem_ctl_info *mci) ...@@ -1123,10 +1113,8 @@ static int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
/* create a symlink for the device */ /* create a symlink for the device */
err = sysfs_create_link(edac_mci_kobj, &mci->pdev->dev.kobj, err = sysfs_create_link(edac_mci_kobj, &mci->pdev->dev.kobj,
EDAC_DEVICE_SYMLINK); EDAC_DEVICE_SYMLINK);
if (err) { if (err)
kobject_unregister(edac_mci_kobj); goto fail0;
return err;
}
/* Make directories for each CSROW object /* Make directories for each CSROW object
* under the mc<id> kobject * under the mc<id> kobject
...@@ -1139,7 +1127,7 @@ static int edac_create_sysfs_mci_device(struct mem_ctl_info *mci) ...@@ -1139,7 +1127,7 @@ static int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
if (csrow->nr_pages > 0) { if (csrow->nr_pages > 0) {
err = edac_create_csrow_object(edac_mci_kobj,csrow,i); err = edac_create_csrow_object(edac_mci_kobj,csrow,i);
if (err) if (err)
goto fail; goto fail1;
} }
} }
...@@ -1150,16 +1138,14 @@ static int edac_create_sysfs_mci_device(struct mem_ctl_info *mci) ...@@ -1150,16 +1138,14 @@ static int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
/* CSROW error: backout what has already been registered, */ /* CSROW error: backout what has already been registered, */
fail: fail1:
for ( i--; i >= 0; i--) { for ( i--; i >= 0; i--) {
if (csrow->nr_pages > 0) { if (csrow->nr_pages > 0)
kobject_unregister(&mci->csrows[i].kobj); kobject_unregister(&mci->csrows[i].kobj);
kobject_put(&mci->csrows[i].kobj);
}
} }
fail0:
kobject_unregister(edac_mci_kobj); kobject_unregister(edac_mci_kobj);
kobject_put(edac_mci_kobj);
return err; return err;
} }
...@@ -1177,16 +1163,13 @@ static void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci) ...@@ -1177,16 +1163,13 @@ static void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci)
/* remove all csrow kobjects */ /* remove all csrow kobjects */
for (i = 0; i < mci->nr_csrows; i++) { for (i = 0; i < mci->nr_csrows; i++) {
if (mci->csrows[i].nr_pages > 0) { if (mci->csrows[i].nr_pages > 0)
kobject_unregister(&mci->csrows[i].kobj); kobject_unregister(&mci->csrows[i].kobj);
kobject_put(&mci->csrows[i].kobj);
}
} }
sysfs_remove_link(&mci->edac_mci_kobj, EDAC_DEVICE_SYMLINK); sysfs_remove_link(&mci->edac_mci_kobj, EDAC_DEVICE_SYMLINK);
kobject_unregister(&mci->edac_mci_kobj); kobject_unregister(&mci->edac_mci_kobj);
kobject_put(&mci->edac_mci_kobj);
#endif /* DISABLE_EDAC_SYSFS */ #endif /* DISABLE_EDAC_SYSFS */
} }
......
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