From: Johan Hovold <johan@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J . Wysocki" <rafael@kernel.org>,
Danilo Krummrich <dakr@kernel.org>,
driver-core@lists.linux.dev, linux-kernel@vger.kernel.org,
Johan Hovold <johan@kernel.org>,
stable@vger.kernel.org
Subject: [PATCH v2 1/2] driver core: faux: fix root device registration
Date: Fri, 24 Apr 2026 17:31:26 +0200 [thread overview]
Message-ID: <20260424153127.2647405-2-johan@kernel.org> (raw)
In-Reply-To: <20260424153127.2647405-1-johan@kernel.org>
A recent change made the faux bus root device be allocated dynamically
but failed to provide a release function to free the memory when the
last reference is dropped (on theoretical failure to register the device
or bus).
Fix this by using root_device_register() instead of open coding.
Also add the missing sanity check when registering faux devices to avoid
use-after-free if the bus failed to register (which would previously
have triggered a bunch of use-after-free warnings).
Fixes: 61b76d07d2b4 ("driver core: faux: stop using static struct device")
Cc: stable@vger.kernel.org # 7.0
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/base/faux.c | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)
diff --git a/drivers/base/faux.c b/drivers/base/faux.c
index fb3e42f21362..3d1d1eafb473 100644
--- a/drivers/base/faux.c
+++ b/drivers/base/faux.c
@@ -133,6 +133,9 @@ struct faux_device *faux_device_create_with_groups(const char *name,
struct device *dev;
int ret;
+ if (!faux_bus_root)
+ return NULL;
+
faux_obj = kzalloc_obj(*faux_obj);
if (!faux_obj)
return NULL;
@@ -232,19 +235,12 @@ EXPORT_SYMBOL_GPL(faux_device_destroy);
int __init faux_bus_init(void)
{
+ struct device *root;
int ret;
- faux_bus_root = kzalloc_obj(*faux_bus_root);
- if (!faux_bus_root)
- return -ENOMEM;
-
- dev_set_name(faux_bus_root, "faux");
-
- ret = device_register(faux_bus_root);
- if (ret) {
- put_device(faux_bus_root);
- return ret;
- }
+ root = root_device_register("faux");
+ if (IS_ERR(root))
+ return PTR_ERR(root);
ret = bus_register(&faux_bus_type);
if (ret)
@@ -254,12 +250,14 @@ int __init faux_bus_init(void)
if (ret)
goto error_driver;
+ faux_bus_root = root;
+
return ret;
error_driver:
bus_unregister(&faux_bus_type);
error_bus:
- device_unregister(faux_bus_root);
+ root_device_unregister(root);
return ret;
}
--
2.53.0
next prev parent reply other threads:[~2026-04-24 15:32 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-24 15:31 [PATCH v2 0/2] driver core: faux: fix root device registration Johan Hovold
2026-04-24 15:31 ` Johan Hovold [this message]
2026-04-28 22:19 ` [PATCH v2 1/2] " Danilo Krummrich
2026-04-29 10:17 ` Johan Hovold
2026-04-29 10:47 ` Danilo Krummrich
2026-04-29 11:19 ` Johan Hovold
2026-04-29 14:20 ` Danilo Krummrich
2026-04-29 15:02 ` Johan Hovold
2026-04-29 20:11 ` Danilo Krummrich
2026-04-30 7:00 ` Greg Kroah-Hartman
2026-04-30 11:29 ` Danilo Krummrich
2026-04-24 15:31 ` [PATCH v2 2/2] driver core: faux: clean up init error handling Johan Hovold
2026-04-29 20:22 ` [PATCH v2 0/2] driver core: faux: fix root device registration Danilo Krummrich
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=20260424153127.2647405-2-johan@kernel.org \
--to=johan@kernel.org \
--cc=dakr@kernel.org \
--cc=driver-core@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=stable@vger.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.