From: Wei Liu <wei.liu@kernel.org>
To: Juan Vazquez <juvazq@linux.microsoft.com>
Cc: Miaoqian Lin <linmq006@gmail.com>,
"K. Y. Srinivasan" <kys@microsoft.com>,
Haiyang Zhang <haiyangz@microsoft.com>,
Stephen Hemminger <sthemmin@microsoft.com>,
Wei Liu <wei.liu@kernel.org>, Dexuan Cui <decui@microsoft.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Drivers: hv: vmbus: Fix memory leak in vmbus_add_channel_kobj
Date: Thu, 3 Feb 2022 12:44:32 +0000 [thread overview]
Message-ID: <20220203124432.ckvfzgyyg6fqe2pm@liuwe-devbox-debian-v2> (raw)
In-Reply-To: <20220128215604.xuqdpnnn4yjqfaoy@surface>
On Fri, Jan 28, 2022 at 01:56:04PM -0800, Juan Vazquez wrote:
> On Wed, Jan 26, 2022 at 05:52:46AM +0000, 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 memory leak by calling kobject_put().
> >
> > Fixes: c2e5df616e1a ("vmbus: add per-channel sysfs info")
> > Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> > ---
> > drivers/hv/vmbus_drv.c | 4 +++-
> > 1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
> > index 17bf55fe3169..9e055697783b 100644
> > --- a/drivers/hv/vmbus_drv.c
> > +++ b/drivers/hv/vmbus_drv.c
> > @@ -2028,8 +2028,10 @@ int vmbus_add_channel_kobj(struct hv_device *dev, struct vmbus_channel *channel)
> > kobj->kset = dev->channels_kset;
> > ret = kobject_init_and_add(kobj, &vmbus_chan_ktype, NULL,
> > "%u", relid);
> > - if (ret)
> > + if (ret) {
> > + kobject_put(kobj);
> > return ret;
> > + }
> >
> > ret = sysfs_create_group(kobj, &vmbus_chan_group);
> If sysfs_create_group() fails same cleanup I think is required.
>
> Later kobject_uevent() may fail according to doc, but there is no error
> handling, maybe a good moment to consider adding it and do same cleanup.
Miaoqian, are you going to post a new version to address Juan's comment
here?
Thanks,
Wei.
> >
> > --
> > 2.17.1
next prev parent reply other threads:[~2022-02-03 12:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-26 5:52 [PATCH] Drivers: hv: vmbus: Fix memory leak in vmbus_add_channel_kobj Miaoqian Lin
2022-01-28 21:56 ` Juan Vazquez
2022-02-03 12:44 ` Wei Liu [this message]
2022-02-03 17:30 ` [PATCH v2] " Miaoqian Lin
2022-02-06 14:55 ` Juan Vazquez
2022-02-07 17:54 ` Wei Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220203124432.ckvfzgyyg6fqe2pm@liuwe-devbox-debian-v2 \
--to=wei.liu@kernel.org \
--cc=decui@microsoft.com \
--cc=gregkh@linuxfoundation.org \
--cc=haiyangz@microsoft.com \
--cc=juvazq@linux.microsoft.com \
--cc=kys@microsoft.com \
--cc=linmq006@gmail.com \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sthemmin@microsoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox