On Thu, Feb 04, 2021 at 05:06:15PM +0000, Vladimir Oltean wrote: > On Thu, Feb 04, 2021 at 06:00:26PM +0100, Andrew Lunn wrote: > > On Thu, Feb 04, 2021 at 06:33:51PM +0200, Vladimir Oltean wrote: > > > Since teardown is supposed to undo the effects of the setup method, it > > > should be called in the error path for dsa_switch_setup, not just in > > > dsa_switch_teardown. > > > > I disagree with this. If setup failed, it should of cleaned itself up. > > That is the generally accepted way of doing things. If a function is > > going to exit with an error, it should first undo whatever it did > > before exiting. > > > > You are adding extra semantics to the teardown op. It can no longer > > assume setup was successful. So it needs to be very careful about what > > it tears down, it cannot assume everything has been setup. I doubt the > > existing implementations actually do that. > > I'm sorry, I don't understand. > I write a driver, I implement .setup(). I allocate some memory, I expect > that I can deallocate it in .teardown(). > Now dsa_switch_setup comes, calls my .setup() which succedes. But then > mdiobus_register(ds->slave_mii_bus) which comes right after .setup() > fails. Are you saying we shouldn't call the driver's .teardown()? > Why not?
Hi Vladimir Ah, sorry. Read you commit message wrongly. I though you were calling teardown if setup failed. But that is not what the patch does. It calls it if things after setup fail. Reviewed-by: Andrew Lunn <and...@lunn.ch> Andrew