Skip to content

Commit

Permalink
net: dsa: Properly propagate errors from dsa_switch_setup_one
Browse files Browse the repository at this point in the history
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: df19719 ("net: dsa: split dsa_switch_setup into two functions")
Reported-by: Andrew Lunn <[email protected]>
Signed-off-by: Florian Fainelli <[email protected]>
Tested-by: Andrew Lunn <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
ffainelli authored and davem330 committed Jun 1, 2015
1 parent 9f95041 commit 2459534
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions net/dsa/dsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,
*/
ds = kzalloc(sizeof(*ds) + drv->priv_size, GFP_KERNEL);
if (ds == NULL)
return NULL;
return ERR_PTR(-ENOMEM);

ds->dst = dst;
ds->index = index;
Expand All @@ -370,7 +370,7 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,

ret = dsa_switch_setup_one(ds, parent);
if (ret)
return NULL;
return ERR_PTR(ret);

return ds;
}
Expand Down

0 comments on commit 2459534

Please sign in to comment.