* [PATCH] virtio-mmio: fix device release warning on module unload
@ 2026-04-24 10:48 Johan Hovold
2026-04-27 4:16 ` Jason Wang
0 siblings, 1 reply; 3+ messages in thread
From: Johan Hovold @ 2026-04-24 10:48 UTC (permalink / raw)
To: Michael S . Tsirkin, Jason Wang
Cc: Xuan Zhuo, Eugenio Pérez, Greg Kroah-Hartman, virtualization,
linux-kernel, Johan Hovold, stable, Pawel Moll
Driver core expects devices to be allocated dynamically and complains
loudly when a device that lacks a release function is freed.
Use __root_device_register() to allocate and register the root device
instead of open coding using a static device.
Note that root_device_register(), which also creates a link to the
module, cannot be used as the device is registered when parsing the
module parameters which happens before the module kobject has been set
up.
Fixes: 81a054ce0b46 ("virtio-mmio: Devices parameter parsing")
Cc: stable@vger.kernel.org # 3.5
Cc: Pawel Moll <pawel.moll@arm.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/virtio/virtio_mmio.c | 20 ++++++++------------
1 file changed, 8 insertions(+), 12 deletions(-)
diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
index 595c2274fbb5..1b580de81e82 100644
--- a/drivers/virtio/virtio_mmio.c
+++ b/drivers/virtio/virtio_mmio.c
@@ -662,9 +662,7 @@ static void virtio_mmio_remove(struct platform_device *pdev)
#if defined(CONFIG_VIRTIO_MMIO_CMDLINE_DEVICES)
-static struct device vm_cmdline_parent = {
- .init_name = "virtio-mmio-cmdline",
-};
+static struct device *vm_cmdline_parent;
static int vm_cmdline_parent_registered;
static int vm_cmdline_id;
@@ -672,7 +670,6 @@ static int vm_cmdline_id;
static int vm_cmdline_set(const char *device,
const struct kernel_param *kp)
{
- int err;
struct resource resources[2] = {};
char *str;
long long base, size;
@@ -704,11 +701,10 @@ static int vm_cmdline_set(const char *device,
resources[1].start = resources[1].end = irq;
if (!vm_cmdline_parent_registered) {
- err = device_register(&vm_cmdline_parent);
- if (err) {
- put_device(&vm_cmdline_parent);
+ vm_cmdline_parent = __root_device_register("virtio-mmio-cmdline", NULL);
+ if (IS_ERR(vm_cmdline_parent)) {
pr_err("Failed to register parent device!\n");
- return err;
+ return PTR_ERR(vm_cmdline_parent);
}
vm_cmdline_parent_registered = 1;
}
@@ -719,7 +715,7 @@ static int vm_cmdline_set(const char *device,
(unsigned long long)resources[0].end,
(int)resources[1].start);
- pdev = platform_device_register_resndata(&vm_cmdline_parent,
+ pdev = platform_device_register_resndata(vm_cmdline_parent,
"virtio-mmio", vm_cmdline_id++,
resources, ARRAY_SIZE(resources), NULL, 0);
@@ -743,7 +739,7 @@ static int vm_cmdline_get_device(struct device *dev, void *data)
static int vm_cmdline_get(char *buffer, const struct kernel_param *kp)
{
buffer[0] = '\0';
- device_for_each_child(&vm_cmdline_parent, buffer,
+ device_for_each_child(vm_cmdline_parent, buffer,
vm_cmdline_get_device);
return strlen(buffer) + 1;
}
@@ -766,9 +762,9 @@ static int vm_unregister_cmdline_device(struct device *dev,
static void vm_unregister_cmdline_devices(void)
{
if (vm_cmdline_parent_registered) {
- device_for_each_child(&vm_cmdline_parent, NULL,
+ device_for_each_child(vm_cmdline_parent, NULL,
vm_unregister_cmdline_device);
- device_unregister(&vm_cmdline_parent);
+ root_device_unregister(vm_cmdline_parent);
vm_cmdline_parent_registered = 0;
}
}
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] virtio-mmio: fix device release warning on module unload
2026-04-24 10:48 [PATCH] virtio-mmio: fix device release warning on module unload Johan Hovold
@ 2026-04-27 4:16 ` Jason Wang
2026-04-27 15:01 ` Johan Hovold
0 siblings, 1 reply; 3+ messages in thread
From: Jason Wang @ 2026-04-27 4:16 UTC (permalink / raw)
To: Johan Hovold
Cc: Michael S . Tsirkin, Xuan Zhuo, Eugenio Pérez,
Greg Kroah-Hartman, virtualization, linux-kernel, stable,
Pawel Moll
On Fri, Apr 24, 2026 at 6:48 PM Johan Hovold <johan@kernel.org> wrote:
>
> Driver core expects devices to be allocated dynamically and complains
> loudly when a device that lacks a release function is freed.
>
> Use __root_device_register() to allocate and register the root device
> instead of open coding using a static device.
>
> Note that root_device_register(), which also creates a link to the
> module, cannot be used as the device is registered when parsing the
> module parameters which happens before the module kobject has been set
> up.
>
> Fixes: 81a054ce0b46 ("virtio-mmio: Devices parameter parsing")
> Cc: stable@vger.kernel.org # 3.5
> Cc: Pawel Moll <pawel.moll@arm.com>
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
> drivers/virtio/virtio_mmio.c | 20 ++++++++------------
> 1 file changed, 8 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
> index 595c2274fbb5..1b580de81e82 100644
> --- a/drivers/virtio/virtio_mmio.c
> +++ b/drivers/virtio/virtio_mmio.c
> @@ -662,9 +662,7 @@ static void virtio_mmio_remove(struct platform_device *pdev)
>
> #if defined(CONFIG_VIRTIO_MMIO_CMDLINE_DEVICES)
>
> -static struct device vm_cmdline_parent = {
> - .init_name = "virtio-mmio-cmdline",
> -};
> +static struct device *vm_cmdline_parent;
vm_cmdline_get() is the .get callback for the device module parameter.
It is invoked when userspace reads
/sys/module/virtio_mmio/parameters/device. This function uses
vm_cmdline_parent unconditionally, without checking whether the device
has been registered. This would cause NULL pointer dereference.
Thanks
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] virtio-mmio: fix device release warning on module unload
2026-04-27 4:16 ` Jason Wang
@ 2026-04-27 15:01 ` Johan Hovold
0 siblings, 0 replies; 3+ messages in thread
From: Johan Hovold @ 2026-04-27 15:01 UTC (permalink / raw)
To: Jason Wang
Cc: Michael S . Tsirkin, Xuan Zhuo, Eugenio Pérez,
Greg Kroah-Hartman, virtualization, linux-kernel, stable,
Pawel Moll
On Mon, Apr 27, 2026 at 12:16:47PM +0800, Jason Wang wrote:
> On Fri, Apr 24, 2026 at 6:48 PM Johan Hovold <johan@kernel.org> wrote:
> >
> > Driver core expects devices to be allocated dynamically and complains
> > loudly when a device that lacks a release function is freed.
> >
> > Use __root_device_register() to allocate and register the root device
> > instead of open coding using a static device.
> > -static struct device vm_cmdline_parent = {
> > - .init_name = "virtio-mmio-cmdline",
> > -};
> > +static struct device *vm_cmdline_parent;
>
> vm_cmdline_get() is the .get callback for the device module parameter.
> It is invoked when userspace reads
> /sys/module/virtio_mmio/parameters/device. This function uses
> vm_cmdline_parent unconditionally, without checking whether the device
> has been registered. This would cause NULL pointer dereference.
Indeed, Sashiko flagged this as well. Just sent a v2 here:
https://lore.kernel.org/r/20260427143710.14702-1-johan@kernel.org
Johan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-27 15:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-24 10:48 [PATCH] virtio-mmio: fix device release warning on module unload Johan Hovold
2026-04-27 4:16 ` Jason Wang
2026-04-27 15:01 ` Johan Hovold
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox