net: dsa: Properly propagate errors from dsa_switch_setup_one
authorFlorian Fainelli <f.fainelli@gmail.com>
Fri, 29 May 2015 17:29:46 +0000 (10:29 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 1 Jun 2015 04:50:34 +0000 (21:50 -0700)
commit24595346d79b6bd98a77d24c493e8490639788fc
tree54dd40e424ac6e63a508ac960931111b065ade48
parent9f950415e4e28e7cfae2e416b43e862e8101d996
net: dsa: Properly propagate errors from dsa_switch_setup_one

While shuffling some code around, dsa_switch_setup_one() was introduced,
and it was modified to return either an error code using ERR_PTR() or a
NULL pointer when running out of memory or failing to setup a switch.

This is a problem for its caler: dsa_switch_setup() which uses IS_ERR()
and expects to find an error code, not a NULL pointer, so we still try
to proceed with dsa_switch_setup() and operate on invalid memory
addresses. This can be easily reproduced by having e.g: the bcm_sf2
driver built-in, but having no such switch, such that drv->setup will
fail.

Fix this by using PTR_ERR() consistently which is both more informative
and avoids for the caller to use IS_ERR_OR_NULL().

Fixes: df197195a5248 ("net: dsa: split dsa_switch_setup into two functions")
Reported-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Tested-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/dsa/dsa.c