[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <YvS97Ixj2cbOBjek@zn.tnic>
Date: Thu, 11 Aug 2022 10:29:32 +0200
From: Borislav Petkov <bp@...en8.de>
To: Miaoqian Lin <linmq006@...il.com>
Cc: Mauro Carvalho Chehab <mchehab@...nel.org>,
Tony Luck <tony.luck@...el.com>,
James Morse <james.morse@....com>,
Robert Richter <rric@...nel.org>,
Greg Kroah-Hartman <gregkh@...e.de>,
Doug Thompson <dougthompson@...ssion.com>,
linux-edac@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2] EDAC: Fix some refcount leaks
On Thu, May 12, 2022 at 11:59:06AM +0400, Miaoqian Lin wrote:
> 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: b2ed215a3338 ("Kobject: change drivers/edac to use kobject_init_and_add")
> Signed-off-by: Miaoqian Lin <linmq006@...il.com>
> ---
> Changes on v2:
> - fix wrong label
> v1 link: https://lore.kernel.org/all/20220511081402.19784-1-linmq006@gmail.com/
> ---
> drivers/edac/edac_device_sysfs.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/edac/edac_device_sysfs.c b/drivers/edac/edac_device_sysfs.c
> index 9a61d92bdf42..a48142a8ea6f 100644
> --- a/drivers/edac/edac_device_sysfs.c
> +++ b/drivers/edac/edac_device_sysfs.c
> @@ -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.
> @@ -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.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
Powered by blists - more mailing lists