Skip to content

Commit

Permalink
netns: Fail conspicously if someone uses net_generic at an inappropri…
Browse files Browse the repository at this point in the history
…ate time.

By definition net_generic should never be called when it can return
NULL.  Fail conspicously with a BUG_ON to make it clear when people mess
up that a NULL return should never happen.

Recently there was a bug in the CAIF subsystem where it was registered
with register_pernet_device instead of register_pernet_subsys.  It was
erroneously concluded that net_generic could validly return NULL and
that net_assign_generic was buggy (when it was just inefficient).
Hopefully this BUG_ON will prevent people to coming to similar erroneous
conclusions in the futrue.

Signed-off-by: Eric W. Biederman <[email protected]>
Tested-by: Sasha Levin <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
ebiederm authored and davem330 committed Jan 28, 2012
1 parent cc0d7b9 commit 5ee4433
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions include/net/netns/generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ static inline void *net_generic(const struct net *net, int id)
ptr = ng->ptr[id - 1];
rcu_read_unlock();

BUG_ON(!ptr);
return ptr;
}
#endif

0 comments on commit 5ee4433

Please sign in to comment.