rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Danilo Krummrich <dakr@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	"Rafael J. Wysocki" <rafael@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>,
	"Zijun Hu" <quic_zijuhu@quicinc.com>,
	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: Tue, 4 Feb 2025 12:52:34 +0100	[thread overview]
Message-ID: <2025020435-earwig-zesty-87ea@gregkh> (raw)
In-Reply-To: <Z6H9g_bvvMf5pPyc@cassiopeiae>

On Tue, Feb 04, 2025 at 12:44:03PM +0100, Danilo Krummrich wrote:
> On Tue, Feb 04, 2025 at 12:09:13PM +0100, Greg Kroah-Hartman wrote:
> > Many drivers abuse the platform driver/bus system as it provides a
> > simple way to create and bind a device to a driver-specific set of
> > probe/release functions.  Instead of doing that, and wasting all of the
> > memory associated with a platform device, here is a "faux" bus that
> > can be used instead.
> > 
> > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > ---
> >  v2: - renamed bus and root device to just "faux" thanks to Thomas
> >      - removed the one-driver-per-device and now just have one driver
> >        entirely thanks to Danilo
> >      - kerneldoc fixups and additions and string handling bounds checks
> >        hanks to Andy
> >      - coding style fix thanks to Jonathan
> >      - tested that the destroy path actually works
> > 
> >  drivers/base/Makefile       |   2 +-
> >  drivers/base/base.h         |   1 +
> >  drivers/base/faux.c         | 196 ++++++++++++++++++++++++++++++++++++
> >  drivers/base/init.c         |   1 +
> >  include/linux/device/faux.h |  31 ++++++
> >  5 files changed, 230 insertions(+), 1 deletion(-)
> >  create mode 100644 drivers/base/faux.c
> >  create mode 100644 include/linux/device/faux.h
> 
> I really like it, it's as simply as it can be.
> 
> Please find one nit below, otherwise
> 
> Reviewed-by: Danilo Krummrich <dakr@kernel.org>
> 
> > 
> > +/**
> > + * faux_device_destroy - destroy a faux device
> > + * @faux_dev: faux device to destroy
> > + *
> > + * Unregister and free all memory associated with a faux device that was
> > + * previously created with a call to faux_device_create().
> 
> Can we really claim that this frees all memory? Someone can still have a
> reference to the underlying struct device, right?

That "someone" is the person that had the original device pointer passed
to it, so if that person then calls faux_device_destroy(), yes, that
should all be properly cleaned up.

But even if it isn't, the device is destroyed and gone from sysfs, and
whenever that final final put_device() is called, the memory will then
be freed by the driver core itself.

So all should be ok unless I'm missing something in some codepath here.

> > + */
> > +void faux_device_destroy(struct faux_device *faux_dev)
> > +{
> > +	struct device *dev = &faux_dev->dev;
> > +
> > +	if (IS_ERR_OR_NULL(faux_dev))
> > +		return;
> > +
> > +	device_del(dev);
> > +
> > +	/* The final put_device() will clean up the driver we created for this device. */
> > +	put_device(dev);
> 
> Same here, how do we know it's the final one? I also think the "clean up the
> driver we created for this device" part isn't true any longer.

Oops, missed that comment, will go fix that.

And same response as above, it should all be cleaned up as best as we
can by now, any other external references is up to them be dropped by
that owner.

thanks for the review,

greg k-h

  reply	other threads:[~2025-02-04 11:52 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 [this message]
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
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=2025020435-earwig-zesty-87ea@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).