Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: dsa: call teardown method on probe failure

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.

Fixes: 5e3f847a02aa ("net: dsa: Add teardown callback for drivers")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Link: https://lore.kernel.org/r/20210204163351.2929670-1-vladimir.oltean@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Vladimir Oltean and committed by
Jakub Kicinski
8fd54a73 07bf34a5

+5 -2
+5 -2
net/dsa/dsa2.c
··· 462 462 ds->slave_mii_bus = devm_mdiobus_alloc(ds->dev); 463 463 if (!ds->slave_mii_bus) { 464 464 err = -ENOMEM; 465 - goto unregister_notifier; 465 + goto teardown; 466 466 } 467 467 468 468 dsa_slave_mii_bus_init(ds); 469 469 470 470 err = mdiobus_register(ds->slave_mii_bus); 471 471 if (err < 0) 472 - goto unregister_notifier; 472 + goto teardown; 473 473 } 474 474 475 475 ds->setup = true; 476 476 477 477 return 0; 478 478 479 + teardown: 480 + if (ds->ops->teardown) 481 + ds->ops->teardown(ds); 479 482 unregister_notifier: 480 483 dsa_switch_unregister_notifier(ds); 481 484 unregister_devlink_ports: