EDAC: Fix some refcount leaks
PATCH v2 1/1 EDAC: Fix some refcount leaks
kobject_init_and_add() takes reference even when it fails. According to the doc of kobject_init_and_add()
If this function returns an error, kobject_put() must be called to properly clean up the memory associated with the object.
Fix this by calling kobject_put() when kobject_init_and_add() fails.
---
Changes on v2:
- fix wrong label
v1 link: https://lore.kernel.org/all/[email protected]/
--- drivers/edac/edac_device_sysfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/edac/edac_device_sysfs.c +2 -2
@@ -542,7 +542,7 @@ static int edac_device_create_block(struct edac_device_ctl_info *edac_dev,edac_dbg (1 ,"Failed to register instance '%s'\n" , block->name);kobject_put (main_kobj); err = -ENODEV ; - goto err_out; + goto err_on_attrib; }/* If there are driver level block attributes, then added them
@@ -640,7 +640,7 @@ static int edac_device_create_instance(struct edac_device_ctl_info *edac_dev,edac_dbg (2 ,"Failed to register instance '%s'\n" , instance->name);kobject_put (main_kobj); - goto err_out; + goto err_release_instance_kobj; } edac_dbg(4, "now register '%d' blocks for instance %d\n",
Signature · 1 line
2.25.1
Borislav Petkov
maintainerQuoted 7 lines · Miaoqian Lin
kobject_init_and_add()takes reference even when it fails. According to the doc ofkobject_init_and_add()If this function returns an error,
kobject_put()must be called to properly clean up the memory associated with the object.Fix this by calling
kobject_put()whenkobject_init_and_add()fails.
$ git grep -w kobject_init_and_add drivers/edac/ drivers/edac/edac_device_sysfs.c:259: err = kobject_init_and_add(&edac_dev->kobj, &ktype_device_ctrl, drivers/edac/edac_device_sysfs.c:538: err = kobject_init_and_add(&block->kobj, &ktype_block_ctrl, drivers/edac/edac_device_sysfs.c:637: err = kobject_init_and_add(&instance->kobj, &ktype_instance_ctrl, drivers/edac/edac_pci_sysfs.c:175: err = kobject_init_and_add(&pci->kobj, &ktype_pci_instance, drivers/edac/edac_pci_sysfs.c:372: err = kobject_init_and_add(edac_pci_top_main_kobj,
Wanna audit them all, make sure they all put the kobject properly and do a single patch fixing those which need fixing?
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteBorislav Petkov
maintainerQuoted 23 lines · Miaoqian Lin
kobject_init_and_add()takes reference even when it fails. According to the doc ofkobject_init_and_add()If this function returns an error,
kobject_put()must be called to properly clean up the memory associated with the object.Fix this by calling
kobject_put()whenkobject_init_and_add()fails.Fixes b2ed215a3338 ("Kobject: change drivers/edac to use kobject_init_and_add")Signed-off-by Miaoqian Lin <[email protected]>---
Changes on v2:
- fix wrong label
v1 link: https://lore.kernel.org/all/[email protected]/--- drivers/edac/edac_device_sysfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/edac/edac_device_sysfs.c +0
-0
drivers/edac/edac_device_sysfs.c static int edac_device_create_block(struct edac_device_ctl_info *edac_dev, · line 548
Quoted 8 lines
drivers/edac/edac_device_sysfs.c +1
-1@@ -542,7 +542,7 @@ static int edac_device_create_block(struct edac_device_ctl_info *edac_dev,edac_dbg (1 ,"Failed to register instance '%s'\n" , block->name);kobject_put (main_kobj); err = -ENODEV ; - goto err_out; + goto err_on_attrib; }/* If there are driver level block attributes, then added them
Actually, on a second look, that's not necessary:
err = edac_device_create_block(edac_dev, instance,
&instance->blocks[i]);
if (err) {
/* If any fail, remove all previous ones */
for (j = 0; j < i; j++)
edac_device_delete_block(edac_dev,
&instance->blocks[j]);
^^^^^^^^^^^^^^that cleans up the kobjects.
drivers/edac/edac_device_sysfs.c static int edac_device_create_instance(struct edac_device_ctl_info *edac_dev, · line 646
Quoted 9 lines
drivers/edac/edac_device_sysfs.c +1
-1@@ -640,7 +640,7 @@ static int edac_device_create_instance(struct edac_device_ctl_info *edac_dev,edac_dbg (2 ,"Failed to register instance '%s'\n" , instance->name);kobject_put (main_kobj); - goto err_out; + goto err_release_instance_kobj; } edac_dbg(4, "now register '%d' blocks for instance %d\n",
Ditto.
But keep lookin' :-)
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette