[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <D7PG55S1KG10.27S2ZIBE1TCUC@gmail.com>
Date: Tue, 11 Feb 2025 02:43:20 -0500
From: "Kurt Borja" <kuurtb@...il.com>
To: "Greg Kroah-Hartman" <gregkh@...uxfoundation.org>
Cc: <linux-kernel@...r.kernel.org>, "Lyude Paul" <lyude@...hat.com>, "Rafael
J. Wysocki" <rafael@...nel.org>, "Danilo Krummrich" <dakr@...nel.org>,
"Alexander Lobakin" <aleksander.lobakin@...el.com>, "Andy Shevchenko"
<andriy.shevchenko@...ux.intel.com>, "Bjorn Helgaas" <bhelgaas@...gle.com>,
"Jonathan Cameron" <Jonathan.Cameron@...wei.com>, "Liam Girdwood"
<lgirdwood@...il.com>, "Lukas Wunner" <lukas@...ner.de>, "Mark Brown"
<broonie@...nel.org>, Maíra Canal <mairacanal@...eup.net>,
"Robin Murphy" <robin.murphy@....com>, "Simona Vetter"
<simona.vetter@...ll.ch>, "Zijun Hu" <quic_zijuhu@...cinc.com>,
<linux-usb@...r.kernel.org>, <rust-for-linux@...r.kernel.org>,
Thomas Weißschuh <thomas.weissschuh@...utronix.de>
Subject: Re: [PATCH v4 1/9] driver core: add a faux bus for use when a
simple device/bus is needed
On Tue Feb 11, 2025 at 2:33 AM -05, Greg Kroah-Hartman wrote:
> On Tue, Feb 11, 2025 at 08:27:26AM +0100, Greg Kroah-Hartman wrote:
>> On Mon, Feb 10, 2025 at 12:56:46PM -0500, Kurt Borja wrote:
>> I'll work on adding "if probe failed, don't let the device be created"
>> logic as it's a simple change, BUT it is a functionally different change
>> from what the current api that this code is replacing is doing (i.e. the
>> current platform device creation code does this today and no one has
>> ever hit this in their use of it in the past few decades.)
>
> How about something as simple as this change, does that provide what you
> are thinking about here? Only compile tested, not runtime tested at
> all:
Yes, LGTM. However dev->driver is set to NULL if the probe fails so
wouldn't
if (!dev->driver)
do the job?
I understand your point about groups. This of course solves it, although
isn't there a small windows between device_add() and device_destroy() in
the failed probe path, in which a show/store/visibility method could
dereference a NULL drvdata?
--
~ Kurt
>
>
> diff --git a/drivers/base/faux.c b/drivers/base/faux.c
> index 531e9d789ee0..e2de0697c0e3 100644
> --- a/drivers/base/faux.c
> +++ b/drivers/base/faux.c
> @@ -25,6 +25,7 @@
> struct faux_object {
> struct faux_device faux_dev;
> const struct faux_device_ops *faux_ops;
> + bool probe_was_successful;
> };
> #define to_faux_object(dev) container_of_const(dev, struct faux_object, faux_dev.dev)
>
> @@ -48,6 +49,9 @@ static int faux_probe(struct device *dev)
> if (faux_ops && faux_ops->probe)
> ret = faux_ops->probe(faux_dev);
>
> + if (!ret)
> + faux_obj->probe_was_successful = true;
> +
> return ret;
> }
>
> @@ -147,6 +151,15 @@ struct faux_device *faux_device_create_with_groups(const char *name,
> return NULL;
> }
>
> + /*
> + * The probe callback will set probe_was_successful if it
> + * succeeded, if not, then we need to tear things down here
> + */
> + if (!faux_obj->probe_was_successful) {
> + faux_device_destroy(faux_dev);
> + return NULL;
> + }
> +
> return faux_dev;
> }
> EXPORT_SYMBOL_GPL(faux_device_create_with_groups);
Powered by blists - more mailing lists