From: Vladimir Oltean <olte...@gmail.com> Date: Sat, 31 Aug 2019 15:46:19 +0300
> When a function such as dsa_slave_create fails, currently the following > stack trace can be seen: ... > devlink_free is complaining right here: > > WARN_ON(!list_empty(&devlink->port_list)); > > This happens because devlink_port_unregister is no longer done right > away in dsa_port_setup when a DSA_PORT_TYPE_USER has failed. > Vivien said about this change that: > > Also no need to call devlink_port_unregister from within dsa_port_setup > as this step is inconditionally handled by dsa_port_teardown on error. > > which is not really true. The devlink_port_unregister function _is_ > being called unconditionally from within dsa_port_setup, but not for > this port that just failed, just for the previous ones which were set > up. > > ports_teardown: > for (i = 0; i < port; i++) > dsa_port_teardown(&ds->ports[i]); > > Initially I was tempted to fix this by extending the "for" loop to also > cover the port that failed during setup. But this could have potentially > unforeseen consequences unrelated to devlink_port or even other types of > ports than user ports, which I can't really test for. For example, if > for some reason devlink_port_register itself would fail, then > unconditionally unregistering it in dsa_port_teardown would not be a > smart idea. The list might go on. > > So just make dsa_port_setup undo the setup it had done upon failure, and > let the for loop undo the work of setting up the previous ports, which > are guaranteed to be brought up to a consistent state. > > Fixes: 955222ca5281 ("net: dsa: use a single switch statement for port setup") > Signed-off-by: Vladimir Oltean <olte...@gmail.com> Applied to net-next, thanks.