Le Fri, 20 May 2022 18:58:15 +0300, Vladimir Oltean <olteanv@xxxxxxxxx> a écrit : > On Fri, May 20, 2022 at 05:49:34PM +0200, Clément Léger wrote: > > Le Fri, 20 May 2022 18:44:40 +0300, > > Vladimir Oltean <olteanv@xxxxxxxxx> a écrit : > > > > > On Fri, May 20, 2022 at 05:22:44PM +0200, Clément Léger wrote: > > > > Le Fri, 20 May 2022 11:49:14 +0300, > > > > Vladimir Oltean <olteanv@xxxxxxxxx> a écrit : > > > > > > > > > On Fri, May 20, 2022 at 09:52:41AM +0200, Clément Léger wrote: > > > > > > > Also, as a request to unbind this driver would be disasterous to users, > > > > > > > I think you should set ".suppress_bind_attrs = true" to prevent the > > > > > > > sysfs bind/unbind facility being available. This doesn't completely > > > > > > > solve the problem. > > > > > > > > > > > > Acked. What should I do to make it more robust ? Should I use a > > > > > > refcount per pdev and check that in the remove() callback to avoid > > > > > > removing the pdev if used ? > > > > > > > > > > I wonder, if you call device_link_add(ds->dev, miic->dev, DL_FLAG_AUTOREMOVE_CONSUMER), > > > > > wouldn't that be enough to auto-unbind the DSA driver when the MII > > > > > converter driver unbinds? > > > > > > > > I looiked at that a bit and I'm not sure how to achieve that cleanly. If > > > > I need to create this link, then I need to do it once for the dsa switch > > > > device. However, currently, the way I get the references to the MII > > > > converter are via the pcs-handle properties which are for each port. > > > > > > > > So, I'm not sure creating the link multiple times in miic_create() would > > > > be ok and also, I'm not sure how to create the link once without adding > > > > a specific property which points on the MII converter node and use that > > > > to create the link by adding miic_device_add_link() for instance. > > > > > > > > Do you have any preference ? > > > > > > The simplest (although not the most elegant) way would probably be to > > > pass the ds->dev as a second argument to miic_create(), and call > > > device_link_add() multiple times, letting all but the first call fail, > > > and ignoring the resulting NULL return code. Maybe others have a better idea. > > > > That's indeed what I started to do although it's nasty to say the > > least... Moreover, the device_link_del() calls in miic_destroy() would > > have to be carefully made after all miic ports have been > > destroyed. Not sure this is going to be cleaner ! I'll try to think > > about it a bit more. > > Wait... the whole idea with AUTOREMOVE_CONSUMER is that you _don't_ > remove the device link.. you let it sit there such that the device core > knows there are other consumers it needs to remove when this driver > unbinds from the device. Hum ok, got it, so let's try this solution. -- Clément Léger, Embedded Linux and Kernel engineer at Bootlin https://bootlin.com