Skip to content
/ linux Public

Commit 6944aaa

Browse files
gregkhSasha Levin
authored andcommitted
driver core: faux: stop using static struct device
[ Upstream commit 61b76d0 ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent e1c24d4 commit 6944aaa

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

drivers/base/faux.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ struct faux_object {
2929
};
3030
#define to_faux_object(dev) container_of_const(dev, struct faux_object, faux_dev.dev)
3131

32-
static struct device faux_bus_root = {
33-
.init_name = "faux",
34-
};
32+
static struct device *faux_bus_root;
3533

3634
static int faux_match(struct device *dev, const struct device_driver *drv)
3735
{
@@ -152,7 +150,7 @@ struct faux_device *faux_device_create_with_groups(const char *name,
152150
if (parent)
153151
dev->parent = parent;
154152
else
155-
dev->parent = &faux_bus_root;
153+
dev->parent = faux_bus_root;
156154
dev->bus = &faux_bus_type;
157155
dev_set_name(dev, "%s", name);
158156
device_set_pm_not_required(dev);
@@ -236,9 +234,15 @@ int __init faux_bus_init(void)
236234
{
237235
int ret;
238236

239-
ret = device_register(&faux_bus_root);
237+
faux_bus_root = kzalloc(sizeof(*faux_bus_root), GFP_KERNEL);
238+
if (!faux_bus_root)
239+
return -ENOMEM;
240+
241+
dev_set_name(faux_bus_root, "faux");
242+
243+
ret = device_register(faux_bus_root);
240244
if (ret) {
241-
put_device(&faux_bus_root);
245+
put_device(faux_bus_root);
242246
return ret;
243247
}
244248

@@ -256,6 +260,6 @@ int __init faux_bus_init(void)
256260
bus_unregister(&faux_bus_type);
257261

258262
error_bus:
259-
device_unregister(&faux_bus_root);
263+
device_unregister(faux_bus_root);
260264
return ret;
261265
}

0 commit comments

Comments
 (0)