From: Johan Hovold <johan@kernel.org>
To: Richard Weinberger <richard@nod.at>,
Anton Ivanov <anton.ivanov@cambridgegreys.com>,
Johannes Berg <johannes@sipsolutions.net>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-um@lists.infradead.org, linux-kernel@vger.kernel.org,
Johan Hovold <johan@kernel.org>
Subject: [PATCH] um: virtio_uml: switch to dynamic root device
Date: Fri, 24 Apr 2026 12:31:01 +0200 [thread overview]
Message-ID: <20260424103101.2616338-1-johan@kernel.org> (raw)
Driver core expects devices to be dynamically allocated and will, for
example, complain loudly when no release function has been provided.
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.
Signed-off-by: Johan Hovold <johan@kernel.org>
---
arch/um/drivers/virtio_uml.c | 24 ++++++++----------------
1 file changed, 8 insertions(+), 16 deletions(-)
diff --git a/arch/um/drivers/virtio_uml.c b/arch/um/drivers/virtio_uml.c
index 7425a8548141..c43afb0af47f 100644
--- a/arch/um/drivers/virtio_uml.c
+++ b/arch/um/drivers/virtio_uml.c
@@ -1274,14 +1274,7 @@ static void virtio_uml_remove(struct platform_device *pdev)
/* Command line device list */
-static void vu_cmdline_release_dev(struct device *d)
-{
-}
-
-static struct device vu_cmdline_parent = {
- .init_name = "virtio-uml-cmdline",
- .release = vu_cmdline_release_dev,
-};
+static struct device *vu_cmdline_parent;
static DEFINE_MUTEX(vu_cmdline_lock);
static bool vu_cmdline_parent_registered;
@@ -1333,11 +1326,10 @@ static int vu_cmdline_set_device(const char *device)
return -EINVAL;
if (!vu_cmdline_parent_registered) {
- err = device_register(&vu_cmdline_parent);
- if (err) {
+ vu_cmdline_parent = __root_device_register("virtio-uml-cmdline", NULL);
+ if (IS_ERR(vu_cmdline_parent)) {
pr_err("Failed to register parent device!\n");
- put_device(&vu_cmdline_parent);
- return err;
+ return PTR_ERR(vu_cmdline_parent);
}
vu_cmdline_parent_registered = true;
}
@@ -1352,7 +1344,7 @@ static int vu_cmdline_set_device(const char *device)
pr_info("Registering device virtio-uml.%d id=%d at %s\n",
vu_cmdline_id, virtio_device_id, socket_path);
- pdev = platform_device_register_data(&vu_cmdline_parent, "virtio-uml",
+ pdev = platform_device_register_data(vu_cmdline_parent, "virtio-uml",
vu_cmdline_id++, &pdata,
sizeof(pdata));
err = PTR_ERR_OR_ZERO(pdev);
@@ -1393,7 +1385,7 @@ static int vu_cmdline_get(char *buffer, const struct kernel_param *kp)
buffer[0] = '\0';
if (vu_cmdline_parent_registered)
- device_for_each_child(&vu_cmdline_parent, buffer,
+ device_for_each_child(vu_cmdline_parent, buffer,
vu_cmdline_get_device);
return strlen(buffer) + 1;
}
@@ -1417,9 +1409,9 @@ static void vu_unregister_cmdline_devices(void)
guard(mutex)(&vu_cmdline_lock);
if (vu_cmdline_parent_registered) {
- device_for_each_child(&vu_cmdline_parent, NULL,
+ device_for_each_child(vu_cmdline_parent, NULL,
vu_unregister_cmdline_device);
- device_unregister(&vu_cmdline_parent);
+ root_device_unregister(vu_cmdline_parent);
vu_cmdline_parent_registered = false;
}
}
--
2.53.0
reply other threads:[~2026-04-24 10:31 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260424103101.2616338-1-johan@kernel.org \
--to=johan@kernel.org \
--cc=anton.ivanov@cambridgegreys.com \
--cc=gregkh@linuxfoundation.org \
--cc=johannes@sipsolutions.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-um@lists.infradead.org \
--cc=richard@nod.at \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox