From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8E2A39526B; Fri, 24 Apr 2026 10:48:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777027709; cv=none; b=TP9kvZ6ZqKjvNsdykSHhUwPHgKObN98jpkrQ535Uyd8N3E5nR5RtZ93ww8K/Ani95H3SyvybbcrggbxrQn2FktB/yjlPT3DseMjqWAlJLx7FbpjPs8/zKmR1cocQJH57RzElhj8BYgF2v+i+DO/dmD9lpRRKTsXallamuHX2cdE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777027709; c=relaxed/simple; bh=mlpkzg1lrGtZLmueKyXQZ8bYMt8d1vd2nA6Gfzvx4Vw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=VMs+yzRhulxYglC/C/HtcY+UoGsJYl3m4+fbx9/Q6SlzwIztrHEmtqZcv5np11itsUpRyzlzkl7SeoFNgeroL8CrmVKC077aFu3TDtgDEj+IhfdWT9M6pNNBVePDjeHW0tvJfpKcc1vNv4qag1FwIHwvuZYiBc8Ji+aH14dfjm8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KTQvb4fm; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KTQvb4fm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CC75C2BCB4; Fri, 24 Apr 2026 10:48:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777027708; bh=mlpkzg1lrGtZLmueKyXQZ8bYMt8d1vd2nA6Gfzvx4Vw=; h=From:To:Cc:Subject:Date:From; b=KTQvb4fmEb7Rb9UilDnyEhTvwAGiYh6Fx/HGzneIS/gXdT/QncJw6bJG2jRgRak2Z AD6OAu2dwOjcTAjO6AS3MnRaZjdNy/NobMQxIpxbuTRgJ9+67B1GeIeeBdsWt0ZMgR ibwqmSuYhd1amIHHIPvxoCRWYB+PvMa2LRQcqUhkMcDV+AM83TCJwmVfeGYtjxJeUt GxbyLM5Hxb06f+LaWmyTPOfQkDGKscO2p8nyzDRK1wpgQS9RUpkRqgkAIuPbljhgPP wjkceV53OdcniD5+AG1+tLnEnunmQPYgfpKIN5UJXvFNeN2nWpYU1zA2ga/YxOebux +hUyuNJZsJLIw== Received: from johan by xi.lan with local (Exim 4.98.2) (envelope-from ) id 1wGE5B-0000000AzNm-3xCK; Fri, 24 Apr 2026 12:48:25 +0200 From: Johan Hovold To: "Michael S . Tsirkin" , Jason Wang Cc: Xuan Zhuo , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Greg Kroah-Hartman , virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, Johan Hovold , stable@vger.kernel.org, Pawel Moll Subject: [PATCH] virtio-mmio: fix device release warning on module unload Date: Fri, 24 Apr 2026 12:48:20 +0200 Message-ID: <20260424104820.2619227-1-johan@kernel.org> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Johan Hovold --- 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