Re: [RFC] driver core: add a virtual bus for use when a simple device/bus is needed
From: Greg Kroah-Hartman
Date: Tue Feb 04 2025 - 01:06:18 EST
On Mon, Feb 03, 2025 at 10:13:08PM +0100, Danilo Krummrich wrote:
> On Mon, Feb 03, 2025 at 12:25:23PM +0100, Greg Kroah-Hartman wrote:
> > On Mon, Feb 03, 2025 at 12:01:04PM +0100, Danilo Krummrich wrote:
> > > On Mon, Feb 03, 2025 at 10:39:58AM +0100, Greg Kroah-Hartman wrote:
> > > > From 4c7aa0f9f0f7d25c962b70a11bad48d418b9490a Mon Sep 17 00:00:00 2001
> > > > From: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
> > > > Date: Fri, 31 Jan 2025 15:01:32 +0100
> > > > Subject: [PATCH] driver core: add a virtual bus for use when a simple
> > > > device/bus is needed
> > > >
> > > > 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 "virtual" bus that
> > > > can be used instead.
> > > >
> > > > Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
> > >
> > > I think it turned out pretty nice combining the driver and device creation for
> > > convenience.
> > >
> > > But I think we may still need the option to create multiple devices for the same
> > > driver, as mentioned by Sima.
> >
> > That will work just fine, the api will allow that, just give each device
> > a unique name and you are good to go.
> >
> > > @Sima: I wonder if the number of devices could just be an argument?
> >
> > Then the virtual bus logic will have to create some sort of number/name
> > system and I don't want to do that. It's a "first caller gets the name"
> > type thing here. You can easily in a driver do this:
> >
> > my_dev_1 = virtual_device_create(&my_virt_ops, "my_dev_1");
> > my_dev_2 = virtual_device_create(&my_virt_ops, "my_dev_2");
> > my_dev_3 = virtual_device_create(&my_virt_ops, "my_dev_3");
> > ...
> >
> > You share the same callbacks, and that's all you really care about. If
> > you want to hang sysfs files off of these things, I can make them take a
> > device_groups pointer as well, but let's keep it simple first.
>
> Sure, that works perfectly. Just thought, we might not want to also create a new
> struct driver for each device.
Oooh, good catch, I can get rid of that now and just use a single
internal driver structure. The "driver vs. device" shouldn't really
matter anymore as that's not the goal here.
I'll keep my v1 version of the virtual bus code here and rename it to
something else (simple?) as we do want tht for other platform devices
that need/want to have a real driver, but for this api for now, that's
not needed.
thanks,
greg k-h