diff options
author | Vladimir Oltean <vladimir.oltean@nxp.com> | 2021-10-26 17:27:40 +0300 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2021-10-27 16:54:02 +0300 |
commit | 9574fb558044ce99cba8a9f062a4c9de9817d8ba (patch) | |
tree | c4523ffb5fc9369084e85284f4850f5af0e0e736 /net/bridge | |
parent | f6814fdcfe1ba0a56eb14e16349dfbd21dadf333 (diff) | |
download | linux-9574fb558044ce99cba8a9f062a4c9de9817d8ba.tar.xz |
net: bridge: reduce indentation level in fdb_create
We can express the same logic without an "if" condition as big as the
function, just return early if the kmem_cache_alloc() call fails.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Acked-by: Nikolay Aleksandrov <nikolay@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/bridge')
-rw-r--r-- | net/bridge/br_fdb.c | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c index 09e7a1dd9e3c..f2b909aedabf 100644 --- a/net/bridge/br_fdb.c +++ b/net/bridge/br_fdb.c @@ -382,23 +382,26 @@ static struct net_bridge_fdb_entry *fdb_create(struct net_bridge *br, unsigned long flags) { struct net_bridge_fdb_entry *fdb; + int err; fdb = kmem_cache_alloc(br_fdb_cache, GFP_ATOMIC); - if (fdb) { - memcpy(fdb->key.addr.addr, addr, ETH_ALEN); - WRITE_ONCE(fdb->dst, source); - fdb->key.vlan_id = vid; - fdb->flags = flags; - fdb->updated = fdb->used = jiffies; - if (rhashtable_lookup_insert_fast(&br->fdb_hash_tbl, - &fdb->rhnode, - br_fdb_rht_params)) { - kmem_cache_free(br_fdb_cache, fdb); - fdb = NULL; - } else { - hlist_add_head_rcu(&fdb->fdb_node, &br->fdb_list); - } + if (!fdb) + return NULL; + + memcpy(fdb->key.addr.addr, addr, ETH_ALEN); + WRITE_ONCE(fdb->dst, source); + fdb->key.vlan_id = vid; + fdb->flags = flags; + fdb->updated = fdb->used = jiffies; + err = rhashtable_lookup_insert_fast(&br->fdb_hash_tbl, &fdb->rhnode, + br_fdb_rht_params); + if (err) { + kmem_cache_free(br_fdb_cache, fdb); + return NULL; } + + hlist_add_head_rcu(&fdb->fdb_node, &br->fdb_list); + return fdb; } |