All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Zijun Hu <quic_zijuhu@quicinc.com>
Cc: linux-kernel@vger.kernel.org,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Lyude Paul" <lyude@redhat.com>,
	"Alexander Lobakin" <aleksander.lobakin@intel.com>,
	"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Jonathan Cameron" <Jonathan.Cameron@huawei.com>,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	"Lukas Wunner" <lukas@wunner.de>,
	"Mark Brown" <broonie@kernel.org>,
	"Maíra Canal" <mairacanal@riseup.net>,
	"Robin Murphy" <robin.murphy@arm.com>,
	"Simona Vetter" <simona.vetter@ffwll.ch>,
	linux-usb@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH v2 1/5] driver core: add a faux bus for use when a simple device/bus is needed
Date: Thu, 6 Feb 2025 17:19:48 +0100	[thread overview]
Message-ID: <2025020638-refresh-pager-cdc0@gregkh> (raw)
In-Reply-To: <f575978b-7103-48b9-8125-a38fb6425f5c@quicinc.com>

On Thu, Feb 06, 2025 at 11:34:27PM +0800, Zijun Hu wrote:
> On 2/4/2025 7:09 PM, Greg Kroah-Hartman wrote:
> > +#define MAX_NAME_SIZE	256	/* Max size of a faux_device name */
> > +
> > +/*
> > + * Internal wrapper structure so we can hold the memory
> > + * for the driver and the name string of the faux device.
> > + */
> > +struct faux_object {
> > +	struct faux_device faux_dev;
> > +	const struct faux_driver_ops *faux_ops;
> > +	char name[];
> 
> Remove name since it is not used actually ?

Hm, we do copy it:
	/* Save off the name of the object into local memory */
	memcpy(faux_obj->name, name, name_size);

Ah, but then we do a dev_set_name() so we don't care anymore!  When the
code was a two-step process we did care.  Nice catch, let me go change
that and test it to be sure.

> > +};+ */
> > +void faux_device_destroy(struct faux_device *faux_dev)
> > +{
> > +	struct device *dev = &faux_dev->dev;
> > +
> > +	if (IS_ERR_OR_NULL(faux_dev))
> > +		return;
> > +
> 
> struct device *dev;
> 
> //faux_device_create() does not return ERR_PTR().
> if (!faux_dev)
> 	return;
> 
> // avoid NULL pointer dereference in case of above error
> dev = &faux_dev->dev;

Nope, that wouldn't have been a dereference error, you can set a pointer
to point to NULL just fine as long as you don't try to dereference it to
something else.  Isn't C fun!  :)

> > +	device_del(dev);
> > +
> > +	/* The final put_device() will clean up the driver we created for this device. */
> > +	put_device(dev);
> 
> use device_unregister() instead of above 2 statements?

Could be, both are the same.

> > +}
> > +EXPORT_SYMBOL_GPL(faux_device_destroy);
> > +
> > +int __init faux_bus_init(void)
> > +{
> > +	int ret;
> > +
> > +	ret = device_register(&faux_bus_root);
> > +	if (ret) {
> > +		put_device(&faux_bus_root);
> 
> put_device() for static device may trigger below warning:
> 
> drivers/base/core.c:device_release():
> WARN(1, KERN_ERR "Device '%s' does not have a release() function, it is
> broken and must be fixed. See Documentation/core-api/kobject.rst.\n",
> 			dev_name(dev));

Yes, but that will never trigger when you run the code as the final put
device never happens.  So you will not ever see that.

And yes, I HATE static struct devices in the kernel a lot, but in the
driver core we use them for a few things like this, so either I fix all
of them, or just live with the few that we have.

thanks for the review!

greg k-h

  reply	other threads:[~2025-02-06 16:19 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-04 11:09 [PATCH v2 0/5] Driver core: Add faux bus devices Greg Kroah-Hartman
2025-02-04 11:09 ` [PATCH v2 1/5] driver core: add a faux bus for use when a simple device/bus is needed Greg Kroah-Hartman
2025-02-04 11:44   ` Danilo Krummrich
2025-02-04 11:52     ` Greg Kroah-Hartman
2025-02-04 12:04       ` Danilo Krummrich
2025-02-04 12:55         ` Greg Kroah-Hartman
2025-02-04 13:57           ` Danilo Krummrich
2025-02-04 12:46   ` Jonathan Cameron
2025-02-04 15:31   ` Alan Stern
2025-02-06  7:44     ` Greg Kroah-Hartman
2025-02-04 16:46   ` Rob Herring
2025-02-04 16:51     ` Rob Herring
2025-02-06  7:43     ` Greg Kroah-Hartman
2025-02-04 22:18   ` Lyude Paul
2025-02-06 10:50     ` Greg Kroah-Hartman
2025-02-04 22:51   ` Lyude Paul
2025-02-05  5:51     ` Greg Kroah-Hartman
2025-02-04 23:10   ` Lyude Paul
2025-02-05  5:53     ` Greg Kroah-Hartman
2025-02-05  7:57       ` Andy Shevchenko
2025-02-05  8:58         ` Greg Kroah-Hartman
2025-02-06 15:34   ` Zijun Hu
2025-02-06 16:19     ` Greg Kroah-Hartman [this message]
2025-02-04 11:09 ` [PATCH v2 2/5] regulator: dummy: convert to use the faux bus Greg Kroah-Hartman
2025-02-04 12:35   ` Mark Brown
2025-02-04 12:47   ` Jonathan Cameron
2025-02-04 11:09 ` [PATCH v2 3/5] USB: phy: convert usb_phy_generic logic to use a faux device Greg Kroah-Hartman
2025-02-05 10:19   ` Peter Chen
2025-02-05 12:27     ` Greg Kroah-Hartman
2025-02-05 13:41       ` Greg Kroah-Hartman
2025-02-06  1:54         ` Peter Chen
2025-02-06  5:46           ` Greg Kroah-Hartman
2025-02-04 11:09 ` [PATCH v2 4/5] x86/microcode: move away from using a fake platform device Greg Kroah-Hartman
2025-02-04 11:09 ` [PATCH v2 5/5] wifi: cfg80211: " 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=2025020638-refresh-pager-cdc0@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=aleksander.lobakin@intel.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bhelgaas@google.com \
    --cc=broonie@kernel.org \
    --cc=dakr@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=lyude@redhat.com \
    --cc=mairacanal@riseup.net \
    --cc=quic_zijuhu@quicinc.com \
    --cc=rafael@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=simona.vetter@ffwll.ch \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.