]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
driver core: faux: stop using static struct device
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 21 Jan 2026 10:29:45 +0000 (11:29 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 21 Jan 2026 13:17:58 +0000 (14:17 +0100)
faux_bus_root should not have been a static struct device, but rather a
dynamically created structure so that lockdep and other testing tools do
not trip over it (as well as being the right thing overall to do.)  Fix
this up by making it properly dynamic.

Reported-by: Gui-Dong Han <hanguidong02@gmail.com>
Closes: https://lore.kernel.org/lkml/CALbr=LYKJsj6cbrDLA07qioKhWJcRj+gW8=bq5=4ZvpEe2c4Yg@mail.gmail.com/
Reviewed-by: Danilo Krummrich <dakr@kernel.org>
Link: https://patch.msgid.link/2026012145-lapping-countless-ef81@gregkh
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/faux.c

index 21dd02124231a90ec51cac886831b61bf51a4435..23d72581723256501b82e517450531b7b5140358 100644 (file)
@@ -29,9 +29,7 @@ struct faux_object {
 };
 #define to_faux_object(dev) container_of_const(dev, struct faux_object, faux_dev.dev)
 
-static struct device faux_bus_root = {
-       .init_name      = "faux",
-};
+static struct device *faux_bus_root;
 
 static int faux_match(struct device *dev, const struct device_driver *drv)
 {
@@ -152,7 +150,7 @@ struct faux_device *faux_device_create_with_groups(const char *name,
        if (parent)
                dev->parent = parent;
        else
-               dev->parent = &faux_bus_root;
+               dev->parent = faux_bus_root;
        dev->bus = &faux_bus_type;
        dev_set_name(dev, "%s", name);
        device_set_pm_not_required(dev);
@@ -236,9 +234,15 @@ int __init faux_bus_init(void)
 {
        int ret;
 
-       ret = device_register(&faux_bus_root);
+       faux_bus_root = kzalloc(sizeof(*faux_bus_root), GFP_KERNEL);
+       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);
+               put_device(faux_bus_root);
                return ret;
        }
 
@@ -256,6 +260,6 @@ error_driver:
        bus_unregister(&faux_bus_type);
 
 error_bus:
-       device_unregister(&faux_bus_root);
+       device_unregister(faux_bus_root);
        return ret;
 }