[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <f575978b-7103-48b9-8125-a38fb6425f5c@quicinc.com>
Date: Thu, 6 Feb 2025 23:34:27 +0800
From: Zijun Hu <quic_zijuhu@...cinc.com>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
<linux-kernel@...r.kernel.org>,
"Rafael J. Wysocki" <rafael@...nel.org>,
Danilo Krummrich <dakr@...nel.org>, Lyude Paul <lyude@...hat.com>
CC: 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>, <linux-usb@...r.kernel.org>,
<rust-for-linux@...r.kernel.org>
Subject: Re: [PATCH v2 1/5] driver core: add a faux bus for use when a simple
device/bus is needed
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 ?
> +};+ */
> +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;
> + 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?
> +}
> +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));
> + return ret;
> + }
> +
> + ret = bus_register(&faux_bus_type);
> + if (ret)
> + goto error_bus;
> +
> + ret = driver_register(&faux_driver);
> + if (ret)
> + goto error_driver;
> +
> + return ret;
> +
> +error_driver:
> + bus_unregister(&faux_bus_type);
> +
> +error_bus:
> + device_unregister(&faux_bus_root);
> + return ret;
> +}
Powered by blists - more mailing lists