All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yang Yingliang <yangyingliang@huawei.com>
To: <linux-hyperv@vger.kernel.org>
Cc: <kys@microsoft.com>, <haiyangz@microsoft.com>,
	<sthemmin@microsoft.com>, <wei.liu@kernel.org>,
	<decui@microsoft.com>, <mikelley@microsoft.com>,
	<yangyingliang@huawei.com>
Subject: [PATCH v3 2/2] Drivers: hv: vmbus: fix possible memory leak in vmbus_device_register()
Date: Sat, 19 Nov 2022 16:11:35 +0800	[thread overview]
Message-ID: <20221119081135.1564691-3-yangyingliang@huawei.com> (raw)
In-Reply-To: <20221119081135.1564691-1-yangyingliang@huawei.com>

If device_register() returns error in vmbus_device_register(),
the name allocated by dev_set_name() must be freed. As comment
of device_register() says, it should use put_device() to give
up the reference in the error path. So fix this by calling
put_device(), then the name can be freed in kobject_cleanup().

Fixes: 09d50ff8a233 ("Staging: hv: make the Hyper-V virtual bus code build")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/hv/vmbus_drv.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 8b2e413bf19c..e592c481f7ae 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -2082,6 +2082,7 @@ int vmbus_device_register(struct hv_device *child_device_obj)
 	ret = device_register(&child_device_obj->device);
 	if (ret) {
 		pr_err("Unable to register child device\n");
+		put_device(&child_device_obj->device);
 		return ret;
 	}
 
-- 
2.25.1


  parent reply	other threads:[~2022-11-19  8:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-19  8:11 [PATCH v3 0/2] Drivers: hv: vmbus: fix two issues Yang Yingliang
2022-11-19  8:11 ` [PATCH v3 1/2] Drivers: hv: vmbus: fix double free in the error path of vmbus_add_channel_work() Yang Yingliang
2022-11-20  5:50   ` Michael Kelley (LINUX)
2022-11-19  8:11 ` Yang Yingliang [this message]
2022-11-20  5:50   ` [PATCH v3 2/2] Drivers: hv: vmbus: fix possible memory leak in vmbus_device_register() Michael Kelley (LINUX)
2022-11-21 10:58 ` [PATCH v3 0/2] Drivers: hv: vmbus: fix two issues 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=20221119081135.1564691-3-yangyingliang@huawei.com \
    --to=yangyingliang@huawei.com \
    --cc=decui@microsoft.com \
    --cc=haiyangz@microsoft.com \
    --cc=kys@microsoft.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=mikelley@microsoft.com \
    --cc=sthemmin@microsoft.com \
    --cc=wei.liu@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.