Skip to content

Commit

Permalink
EDAC: Fix some refcount leaks
Browse files Browse the repository at this point in the history
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.

Fixes: b2ed215 ("Kobject: change drivers/edac to use kobject_init_and_add")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
  • Loading branch information
Yuuoniy authored and intel-lab-lkp committed May 11, 2022
1 parent cd2ef50 commit e5e3d8b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/edac/edac_device_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,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
Expand Down Expand Up @@ -637,7 +637,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 edac_device_create_instance;
}

edac_dbg(4, "now register '%d' blocks for instance %d\n",
Expand Down

0 comments on commit e5e3d8b

Please sign in to comment.