Re: [PATCH v2 1/5] driver core: add a faux bus for use when a simple device/bus is needed

Greg Kroah-Hartman
2025-02-05T05:53:12Z

On Tue, Feb 04, 2025 at 06:10:36PM -0500, Lyude Paul wrote:
> OK I definitely should have waited to write the actual bindings before review
> - sorry! There was one other small thing I ended up noticing:
>
> On Tue, 2025-02-04 at 12:09 +0100, Greg Kroah-Hartman wrote:
> > diff --git a/include/linux/device/faux.h b/include/linux/device/faux.h
> > new file mode 100644
> > index 000000000000..2c8ae5bd7ae8
> > --- /dev/null
> > +++ b/include/linux/device/faux.h
> > @@ -0,0 +1,31 @@
> > +/* SPDX-License-Identifier: GPL-2.0-only */
> > +/*
> > + * Copyright (c) 2025 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > + * Copyright (c) 2025 The Linux Foundation
> > + *
> > + * A "simple" faux bus that allows devices to be created and added
> > + * automatically to it. This is to be used whenever you need to create a
> > + * device that is not associated with any "real" system resources, and do
> > + * not want to have to deal with a bus/driver binding logic. It is
> > + * intended to be very simple, with only a create and a destroy function
> > + * available.
> > + */
> > +#ifndef _FAUX_DEVICE_H_
> > +#define _FAUX_DEVICE_H_
> > +
> > +#include <linux/device.h>
> > +
> > +struct faux_device {
> > + struct device dev;
> > +};
> > +#define to_faux_device(x) container_of_const((x), struct faux_device, dev)
> > +
> > +struct faux_driver_ops {
> > + int (*probe)(struct faux_device *faux_dev);
> > + void (*remove)(struct faux_device *faux_dev);
> > +};
> > +
> > +struct faux_device *faux_device_create(const char *name, struct faux_driver_ops *faux_ops);
> > +void faux_device_destroy(struct faux_device *faux_dev);
>
> Should we add faux_get_drvdata()/faux_set_drvdata() since we've got a
> probe/remove function? Doesn't really look like the platform driver equivalent
> does mcuh, but I assume just having an inline function for this would make
> things a little less confusing for users.

You already have a reference counted object returned to you, why do you
need to increment/decrement it again? All of the users I've found in
the kernel so far didn't need that, do you have a specific example where
it would be useful?

I'll be glad to add it, I just didn't think anyone would ever call it.

thanks,

greg k-h