> -----Original Message----- > From: Greg KH <gregkh@xxxxxxxxxxxxxxxxxxx> > Sent: Friday, February 14, 2020 12:45 PM > To: Jason Gunthorpe <jgg@xxxxxxxx> > Cc: Kirsher, Jeffrey T <jeffrey.t.kirsher@xxxxxxxxx>; davem@xxxxxxxxxxxxx; > Ertman, David M <david.m.ertman@xxxxxxxxx>; netdev@xxxxxxxxxxxxxxx; > linux-rdma@xxxxxxxxxxxxxxx; nhorman@xxxxxxxxxx; > sassmann@xxxxxxxxxx; parav@xxxxxxxxxxxx; galpress@xxxxxxxxxx; > selvin.xavier@xxxxxxxxxxxx; sriharsha.basavapatna@xxxxxxxxxxxx; > benve@xxxxxxxxx; bharat@xxxxxxxxxxx; xavier.huwei@xxxxxxxxxx; > yishaih@xxxxxxxxxxxx; leonro@xxxxxxxxxxxx; mkalderon@xxxxxxxxxxx; > aditr@xxxxxxxxxx; Patil, Kiran <kiran.patil@xxxxxxxxx>; Bowers, AndrewX > <andrewx.bowers@xxxxxxxxx> > Subject: Re: [RFC PATCH v4 01/25] virtual-bus: Implementation of Virtual Bus > > On Fri, Feb 14, 2020 at 04:34:55PM -0400, Jason Gunthorpe wrote: > > On Fri, Feb 14, 2020 at 09:02:40AM -0800, Greg KH wrote: > > > > + put_device(&vdev->dev); > > > > + ida_simple_remove(&virtbus_dev_ida, vdev->id); > > > > > > You need to do this before put_device(). > > > > Shouldn't it be in the release function? The ida index should not be > > re-used until the kref goes to zero.. The IDA should not be reused until the virtbus_device is unregistered. We don't want another device with the same name and same IDA to be registered, so the IDA has to remain unique until the device is unregistered, that is why I am moving it to before put_device, but remember, this index is just to ensure unique naming among the devices registered on the bus. There could (and will) be several foo_rdma devices created (one per PF) and we need to keep them all straight. > > Doesn't really matter, once you have unregistered it, you can reuse it. > But yes, putting it in release() is the safest thing to do. > > > > > +struct virtbus_device { > > > > + struct device dev; > > > > + const char *name; > > > > + void (*release)(struct virtbus_device *); > > > > + int id; > > > > + const struct virtbus_dev_id *matched_element; > > > > +}; > > > > > > Any reason you need to make "struct virtbus_device" a public structure > > > at all? > > > > The general point of this scheme is to do this in a public header: > > > > +struct iidc_virtbus_object { > > + struct virtbus_device vdev; > > + struct iidc_peer_dev *peer_dev; > > +}; > > > > And then this when the driver binds: > > Ah, yes, nevermind, I missed that. > > greg k-h -DaveE