* [PATCH] driver core: faux: stop using static struct device
@ 2026-01-21 10:29 Greg Kroah-Hartman
2026-01-21 12:12 ` Danilo Krummrich
2026-01-21 14:55 ` David Laight
0 siblings, 2 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2026-01-21 10:29 UTC (permalink / raw)
To: dakr, rafael; +Cc: linux-kernel, driver-core, Greg Kroah-Hartman, Gui-Dong Han
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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/base/faux.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/drivers/base/faux.c b/drivers/base/faux.c
index 21dd02124231..23d725817232 100644
--- a/drivers/base/faux.c
+++ b/drivers/base/faux.c
@@ -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 @@ int __init faux_bus_init(void)
bus_unregister(&faux_bus_type);
error_bus:
- device_unregister(&faux_bus_root);
+ device_unregister(faux_bus_root);
return ret;
}
--
2.52.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] driver core: faux: stop using static struct device
2026-01-21 10:29 [PATCH] driver core: faux: stop using static struct device Greg Kroah-Hartman
@ 2026-01-21 12:12 ` Danilo Krummrich
2026-01-21 14:55 ` David Laight
1 sibling, 0 replies; 4+ messages in thread
From: Danilo Krummrich @ 2026-01-21 12:12 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: rafael, linux-kernel, driver-core, Gui-Dong Han
On Wed Jan 21, 2026 at 11:29 AM CET, Greg Kroah-Hartman wrote:
> 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/
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Danilo Krummrich <dakr@kernel.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] driver core: faux: stop using static struct device
2026-01-21 10:29 [PATCH] driver core: faux: stop using static struct device Greg Kroah-Hartman
2026-01-21 12:12 ` Danilo Krummrich
@ 2026-01-21 14:55 ` David Laight
2026-01-21 17:03 ` Greg Kroah-Hartman
1 sibling, 1 reply; 4+ messages in thread
From: David Laight @ 2026-01-21 14:55 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: dakr, rafael, linux-kernel, driver-core, Gui-Dong Han
On Wed, 21 Jan 2026 11:29:45 +0100
Greg Kroah-Hartman <gregkh@linuxfoundation.org> wrote:
> 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>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---
> drivers/base/faux.c | 18 +++++++++++-------
> 1 file changed, 11 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/base/faux.c b/drivers/base/faux.c
> index 21dd02124231..23d725817232 100644
> --- a/drivers/base/faux.c
> +++ b/drivers/base/faux.c
> @@ -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;
Should there be:
if (faux_bus_root)
return -EBUSY;
here?
While I guess there shouldn't be two of these, better be safe.
David
>
> - 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 @@ int __init faux_bus_init(void)
> bus_unregister(&faux_bus_type);
>
> error_bus:
> - device_unregister(&faux_bus_root);
> + device_unregister(faux_bus_root);
> return ret;
> }
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] driver core: faux: stop using static struct device
2026-01-21 14:55 ` David Laight
@ 2026-01-21 17:03 ` Greg Kroah-Hartman
0 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2026-01-21 17:03 UTC (permalink / raw)
To: David Laight; +Cc: dakr, rafael, linux-kernel, driver-core, Gui-Dong Han
On Wed, Jan 21, 2026 at 02:55:24PM +0000, David Laight wrote:
> On Wed, 21 Jan 2026 11:29:45 +0100
> Greg Kroah-Hartman <gregkh@linuxfoundation.org> wrote:
>
> > 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>
> > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > ---
> > drivers/base/faux.c | 18 +++++++++++-------
> > 1 file changed, 11 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/base/faux.c b/drivers/base/faux.c
> > index 21dd02124231..23d725817232 100644
> > --- a/drivers/base/faux.c
> > +++ b/drivers/base/faux.c
> > @@ -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;
>
> Should there be:
> if (faux_bus_root)
> return -EBUSY;
> here?
How can that happen?
> While I guess there shouldn't be two of these, better be safe.
It can't, no need for that :)
thanks,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-01-21 17:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-21 10:29 [PATCH] driver core: faux: stop using static struct device Greg Kroah-Hartman
2026-01-21 12:12 ` Danilo Krummrich
2026-01-21 14:55 ` David Laight
2026-01-21 17:03 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox