Re: [PATCH] virtio-mmio: fix device release warning on module unload

From: Jason Wang

Date: Mon Apr 27 2026 - 00:17:16 EST


On Fri, Apr 24, 2026 at 6:48 PM Johan Hovold <johan@xxxxxxxxxx> 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@xxxxxxxxxxxxxxx # 3.5
> Cc: Pawel Moll <pawel.moll@xxxxxxx>
> Signed-off-by: Johan Hovold <johan@xxxxxxxxxx>
> ---
> 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