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

Greg Kroah-Hartman
2025-02-07T09:15:09Z

On Thu, Feb 06, 2025 at 07:08:18PM +0100, Thomas Weißschuh wrote:
> On Thu, Feb 06, 2025 at 06:38:15PM +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.
> >
> > Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > Reviewed-by: Danilo Krummrich <dakr@kernel.org>
> > Reviewed-by: Lyude Paul <lyude@redhat.com>
>
> Some tiny nitpicks below, but still:
>
> Reviewed-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>

Thanks!

> > +#include <linux/err.h>
> > +#include <linux/init.h>
> > +#include <linux/slab.h>
> > +#include <linux/string.h>
> > +#include <linux/container_of.h>
> > +#include <linux/device/faux.h>
> > +#include "base.h"
>
> Weird order.

I don't believe in any specific header file ordering, that's done by
maintainers for other reasons to see if people are paying attention in
reviews :)

> > + struct device *dev;
> > + struct faux_object *faux_obj;
> > + struct faux_device *faux_dev;
> > + int name_size;
> > + int ret;
> > +
> > + name_size = strlen(name);
> > + if (name_size > MAX_FAUX_NAME_SIZE)
> > + return NULL;
> > +
> > + faux_obj = kzalloc(sizeof(*faux_obj) + name_size + 1, GFP_KERNEL);
>
> The name is not actually stored in the object anymore.

Ick, you are right, I'll go clean that up.

> > 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/container_of.h>

This is the second time it's come up, I'll fix it up :)

thanks again for the review,

greg k-h