From: Suyuan Wang via B4 Relay <devnull+shyckless.gmail.com@kernel.org>
To: haiyangz@microsoft.com, decui@microsoft.com, wei.liu@kernel.org
Cc: romank@linux.microsoft.com, ssengar@linux.microsoft.com,
namjain@linux.microsoft.com, linux-kernel@vger.kernel.org,
linux-hyperv@vger.kernel.org, mhklinux@outlook.com
Subject: [PATCH] mshv_vtl: Release mem_dev through put_device()
Date: Thu, 12 Nov 2026 10:04:18 +0000 [thread overview]
Message-ID: <20261112-hyperv-v1-1-67144d71878c@gmail.com> (raw)
From: Suyuan Wang <stevewong@hust.edu.cn>
mem_dev is set up with device_initialize() and device_add(), but it is
freed with a plain kfree(), both on the device_add() error path and on
module exit:
device_del(mem_dev);
kfree(mem_dev);
It has no release() callback either. Freeing an initialized device with
kfree() skips the final put_device() and device_release(). On module
unload this leaks the device name and the device_private allocated by
device_add(), and on the device_add() error path at least the name is
leaked. The leak is small, and the fix is to free the device the way
the driver core expects.
Give mem_dev a release() callback that frees it, and use put_device()
on the error path and device_unregister() in mshv_vtl_exit(). Nothing
else changes: the devm_memremap_pages() mapping is still torn down by
device_del() as before.
Found with a static analysis tool and checked by hand.
Fixes: 7bfe3b8ea6e3 ("Drivers: hv: Introduce mshv_vtl driver")
Cc: stable@vger.kernel.org
Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
---
Compile tested with CONFIG_MSHV_VTL=y only, I don't have an OpenHCL
setup to run it.
---
drivers/hv/mshv_vtl_main.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/drivers/hv/mshv_vtl_main.c b/drivers/hv/mshv_vtl_main.c
index 2d4fe24cecbf..bbf43330e129 100644
--- a/drivers/hv/mshv_vtl_main.c
+++ b/drivers/hv/mshv_vtl_main.c
@@ -1346,6 +1346,11 @@ static struct miscdevice mshv_vtl_low = {
.minor = MISC_DYNAMIC_MINOR,
};
+static void mshv_vtl_mem_dev_release(struct device *dev)
+{
+ kfree(dev);
+}
+
static int __init mshv_vtl_init(void)
{
int ret;
@@ -1412,17 +1417,18 @@ static int __init mshv_vtl_init(void)
}
device_initialize(mem_dev);
+ mem_dev->release = mshv_vtl_mem_dev_release;
dev_set_name(mem_dev, "mshv vtl mem dev");
ret = device_add(mem_dev);
if (ret) {
dev_err(dev, "mshv vtl mem dev add: %d\n", ret);
- goto free_mem;
+ goto put_mem;
}
return 0;
-free_mem:
- kfree(mem_dev);
+put_mem:
+ put_device(mem_dev);
free_low:
misc_deregister(&mshv_vtl_low);
free_hvcall:
@@ -1439,8 +1445,7 @@ static int __init mshv_vtl_init(void)
static void __exit mshv_vtl_exit(void)
{
- device_del(mem_dev);
- kfree(mem_dev);
+ device_unregister(mem_dev);
misc_deregister(&mshv_vtl_low);
misc_deregister(&mshv_vtl_hvcall_dev);
misc_deregister(&mshv_vtl_sint_dev);
---
base-commit: 630059a5a632377b9b7b487baccde92b7ae1dd47
change-id: 20261112-hyperv-55c5333ce654
Best regards,
--
Suyuan Wang <shyckless@gmail.com>
WARNING: multiple messages have this Message-ID (diff)
From: Suyuan Wang <shyckless@gmail.com>
To: haiyangz@microsoft.com, decui@microsoft.com, wei.liu@kernel.org
Cc: romank@linux.microsoft.com, ssengar@linux.microsoft.com,
namjain@linux.microsoft.com, linux-kernel@vger.kernel.org,
linux-hyperv@vger.kernel.org, mhklinux@outlook.com
Subject: [PATCH] mshv_vtl: Release mem_dev through put_device()
Date: Thu, 12 Nov 2026 10:04:18 +0000 [thread overview]
Message-ID: <20261112-hyperv-v1-1-67144d71878c@gmail.com> (raw)
From: Suyuan Wang <stevewong@hust.edu.cn>
mem_dev is set up with device_initialize() and device_add(), but it is
freed with a plain kfree(), both on the device_add() error path and on
module exit:
device_del(mem_dev);
kfree(mem_dev);
It has no release() callback either. Freeing an initialized device with
kfree() skips the final put_device() and device_release(). On module
unload this leaks the device name and the device_private allocated by
device_add(), and on the device_add() error path at least the name is
leaked. The leak is small, and the fix is to free the device the way
the driver core expects.
Give mem_dev a release() callback that frees it, and use put_device()
on the error path and device_unregister() in mshv_vtl_exit(). Nothing
else changes: the devm_memremap_pages() mapping is still torn down by
device_del() as before.
Found with a static analysis tool and checked by hand.
Fixes: 7bfe3b8ea6e3 ("Drivers: hv: Introduce mshv_vtl driver")
Cc: stable@vger.kernel.org
Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
---
Compile tested with CONFIG_MSHV_VTL=y only, I don't have an OpenHCL
setup to run it.
---
drivers/hv/mshv_vtl_main.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/drivers/hv/mshv_vtl_main.c b/drivers/hv/mshv_vtl_main.c
index 2d4fe24cecbf..bbf43330e129 100644
--- a/drivers/hv/mshv_vtl_main.c
+++ b/drivers/hv/mshv_vtl_main.c
@@ -1346,6 +1346,11 @@ static struct miscdevice mshv_vtl_low = {
.minor = MISC_DYNAMIC_MINOR,
};
+static void mshv_vtl_mem_dev_release(struct device *dev)
+{
+ kfree(dev);
+}
+
static int __init mshv_vtl_init(void)
{
int ret;
@@ -1412,17 +1417,18 @@ static int __init mshv_vtl_init(void)
}
device_initialize(mem_dev);
+ mem_dev->release = mshv_vtl_mem_dev_release;
dev_set_name(mem_dev, "mshv vtl mem dev");
ret = device_add(mem_dev);
if (ret) {
dev_err(dev, "mshv vtl mem dev add: %d\n", ret);
- goto free_mem;
+ goto put_mem;
}
return 0;
-free_mem:
- kfree(mem_dev);
+put_mem:
+ put_device(mem_dev);
free_low:
misc_deregister(&mshv_vtl_low);
free_hvcall:
@@ -1439,8 +1445,7 @@ static int __init mshv_vtl_init(void)
static void __exit mshv_vtl_exit(void)
{
- device_del(mem_dev);
- kfree(mem_dev);
+ device_unregister(mem_dev);
misc_deregister(&mshv_vtl_low);
misc_deregister(&mshv_vtl_hvcall_dev);
misc_deregister(&mshv_vtl_sint_dev);
---
base-commit: 630059a5a632377b9b7b487baccde92b7ae1dd47
change-id: 20261112-hyperv-55c5333ce654
Best regards,
--
Suyuan Wang <shyckless@gmail.com>
next reply other threads:[~2026-11-12 10:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 10:04 Suyuan Wang via B4 Relay [this message]
2026-11-12 10:04 ` [PATCH] mshv_vtl: Release mem_dev through put_device() Suyuan Wang
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=20261112-hyperv-v1-1-67144d71878c@gmail.com \
--to=devnull+shyckless.gmail.com@kernel.org \
--cc=decui@microsoft.com \
--cc=haiyangz@microsoft.com \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mhklinux@outlook.com \
--cc=namjain@linux.microsoft.com \
--cc=romank@linux.microsoft.com \
--cc=shyckless@gmail.com \
--cc=ssengar@linux.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.