From: David Laight <david.laight.linux@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: dakr@kernel.org, rafael@kernel.org, linux-kernel@vger.kernel.org,
driver-core@lists.linux.dev,
Gui-Dong Han <hanguidong02@gmail.com>
Subject: Re: [PATCH] driver core: faux: stop using static struct device
Date: Wed, 21 Jan 2026 14:55:24 +0000 [thread overview]
Message-ID: <20260121145524.2ecd29eb@pumpkin> (raw)
In-Reply-To: <2026012145-lapping-countless-ef81@gregkh>
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;
> }
next prev parent reply other threads:[~2026-01-21 16:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2026-01-21 17:03 ` Greg Kroah-Hartman
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=20260121145524.2ecd29eb@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=dakr@kernel.org \
--cc=driver-core@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=hanguidong02@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox