In preparation of a future change where fdb_add_entry() will do some
work with the &br->hash_lock not held, make the noisy change of taking
that lock inside the function separately.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
net/bridge/br_fdb.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c
index 9c57040d8341..421b8960945a 100644
--- a/net/bridge/br_fdb.c
+++ b/net/bridge/br_fdb.c
@@ -893,19 +893,27 @@ static int fdb_add_entry(struct net_bridge *br, struct net_bridge_port *source,
return -EINVAL;
}
+ spin_lock_bh(&br->hash_lock);
+
fdb = br_fdb_find(br, addr, vid);
if (fdb == NULL) {
- if (!(flags & NLM_F_CREATE))
+ if (!(flags & NLM_F_CREATE)) {
+ spin_unlock_bh(&br->hash_lock);
return -ENOENT;
+ }
fdb = fdb_create(br, source, addr, vid, 0);
- if (!fdb)
+ if (!fdb) {
+ spin_unlock_bh(&br->hash_lock);
return -ENOMEM;
+ }
modified = true;
} else {
- if (flags & NLM_F_EXCL)
+ if (flags & NLM_F_EXCL) {
+ spin_unlock_bh(&br->hash_lock);
return -EEXIST;
+ }
if (READ_ONCE(fdb->dst) != source) {
WRITE_ONCE(fdb->dst, source);@@ -948,6 +956,8 @@ static int fdb_add_entry(struct net_bridge *br, struct net_bridge_port *source,
fdb_notify(br, fdb, RTM_NEWNEIGH, true);
}
+ spin_unlock_bh(&br->hash_lock);
+
return 0;
}
@@ -980,9 +990,7 @@ static int __br_fdb_add(struct ndmsg *ndm, struct net_bridge *br,
}
err = br_fdb_external_learn_add(br, p, addr, vid, true);
} else {
- spin_lock_bh(&br->hash_lock);
err = fdb_add_entry(br, p, addr, ndm, nlh_flags, vid, nfea_tb);
- spin_unlock_bh(&br->hash_lock);
}
return err;--
2.25.1