Skip to content

Commit

Permalink
net: bridge: reduce indentation level in fdb_create
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Vladimir Oltean authored and David S. Miller committed Oct 27, 2021
1 parent f6814fd commit 9574fb5
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions net/bridge/br_fdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 9574fb5

Please sign in to comment.