Skip to contentSkip to conversation

mac80211: fix RCU warnings in mesh

PATCH Superseded Johannes Berg 2 participants 3 messages Nov 21, 2011 – Nov 22, 2011 mac80211

lore
Share & tools
lore

Johannes Berg

author maintainer
#0 lore raw

PATCH 1/1 mac80211: fix RCU warnings in mesh

From: Johannes Berg <[email protected]>

Sparse RCU checking reports two warnings in the mesh path table code. These are due to questionable uses of rcu_dereference.

To fix the first one, get rid of mesh_gate_add() and just make mesh_path_add_gate() do the correct deref.

To fix the second one, simply remove rcu_dereference() in mesh_gate_del() -- it already gets a proper pointer as indicated by the prototype (no __rcu annotation) and confirmed by the code.

Cc Javier Cardona <[email protected]>
Cc Thomas Pedersen <[email protected]>
---
 net/mac80211/mesh_pathtbl.c |   26 ++++----------------------
 1 file changed, 4 insertions(+), 22 deletions(-)
net/mac80211/mesh_pathtbl.c +4 -22
@@ -69,8 +69,6 @@ static inline struct mesh_table *resize_
 		lockdep_is_held(&pathtbl_resize_lock));
 }
 
-static int mesh_gate_add(struct mesh_table *tbl, struct mesh_path *mpath);
-
 /*
  * CAREFUL -- "tbl" must not be an expression,
  * in particular not an rcu_dereference(), since
@@ -420,21 +418,17 @@ static void mesh_gate_node_reclaim(struc
 }
 
 /**
- * mesh_gate_add - mark mpath as path to a mesh gate and add to known_gates
- * @mesh_tbl: table which contains known_gates list
- * @mpath: mpath to known mesh gate
- *
- * Returns: 0 on success
- *
+ * mesh_path_add_gate - add the given mpath to a mesh gate to our path table
+ * @mpath: gate path to add to table
  */
-static int mesh_gate_add(struct mesh_table *tbl, struct mesh_path *mpath)
+static int mesh_path_add_gate(struct mesh_table *tbl, struct mesh_path *mpath)
 {
 	struct mpath_node *gate, *new_gate;
 	struct hlist_node *n;
 	int err;
 
 	rcu_read_lock();
-	tbl = rcu_dereference(tbl);
+	tbl = rcu_dereference(mesh_paths);
 
 	hlist_for_each_entry_rcu(gate, n, tbl->known_gates, list)
 		if (gate->mpath == mpath) {
@@ -478,8 +472,6 @@ static int mesh_gate_del(struct mesh_tab
 	struct mpath_node *gate;
 	struct hlist_node *p, *q;
 
-	tbl = rcu_dereference(tbl);
-
 	hlist_for_each_entry_safe(gate, p, q, tbl->known_gates, list)
 		if (gate->mpath == mpath) {
 			spin_lock_bh(&tbl->gates_lock);
@@ -498,16 +490,6 @@ static int mesh_gate_del(struct mesh_tab
 }
 
 /**
- *
- * mesh_path_add_gate - add the given mpath to a mesh gate to our path table
- * @mpath: gate path to add to table
- */
-int mesh_path_add_gate(struct mesh_path *mpath)
-{
-	return mesh_gate_add(mesh_paths, mpath);
-}
-
-/**
  * mesh_gate_num - number of gates known to this interface
  * @sdata: subif data
  */
author maintainer
#1 lore raw

PATCH v2 1/1 mac80211: fix RCU warnings in mesh

From: Johannes Berg <[email protected]>

Sparse RCU checking reports two warnings in the mesh path table code. These are due to questionable uses of rcu_dereference.

To fix the first one, get rid of mesh_gate_add() and just make mesh_path_add_gate() do the correct deref.

To fix the second one, simply remove rcu_dereference() in mesh_gate_del() -- it already gets a proper pointer as indicated by the prototype (no __rcu annotation) and confirmed by the code.

Cc Javier Cardona <[email protected]>
Cc Thomas Pedersen <[email protected]>

---
v2: oops. fix prototypes

 net/mac80211/mesh_pathtbl.c |   27 +++++----------------------
 1 file changed, 5 insertions(+), 22 deletions(-)
net/mac80211/mesh_pathtbl.c +5 -22
@@ -69,8 +69,6 @@ static inline struct mesh_table *resize_
 		lockdep_is_held(&pathtbl_resize_lock));
 }
 
-static int mesh_gate_add(struct mesh_table *tbl, struct mesh_path *mpath);
-
 /*
  * CAREFUL -- "tbl" must not be an expression,
  * in particular not an rcu_dereference(), since
@@ -420,21 +418,18 @@ static void mesh_gate_node_reclaim(struc
 }
 
 /**
- * mesh_gate_add - mark mpath as path to a mesh gate and add to known_gates
- * @mesh_tbl: table which contains known_gates list
- * @mpath: mpath to known mesh gate
- *
- * Returns: 0 on success
- *
+ * mesh_path_add_gate - add the given mpath to a mesh gate to our path table
+ * @mpath: gate path to add to table
  */
-static int mesh_gate_add(struct mesh_table *tbl, struct mesh_path *mpath)
+int mesh_path_add_gate(struct mesh_path *mpath)
 {
+	struct mesh_table *tbl;
 	struct mpath_node *gate, *new_gate;
 	struct hlist_node *n;
 	int err;
 
 	rcu_read_lock();
-	tbl = rcu_dereference(tbl);
+	tbl = rcu_dereference(mesh_paths);
 
 	hlist_for_each_entry_rcu(gate, n, tbl->known_gates, list)
 		if (gate->mpath == mpath) {
@@ -478,8 +473,6 @@ static int mesh_gate_del(struct mesh_tab
 	struct mpath_node *gate;
 	struct hlist_node *p, *q;
 
-	tbl = rcu_dereference(tbl);
-
 	hlist_for_each_entry_safe(gate, p, q, tbl->known_gates, list)
 		if (gate->mpath == mpath) {
 			spin_lock_bh(&tbl->gates_lock);
@@ -498,16 +491,6 @@ static int mesh_gate_del(struct mesh_tab
 }
 
 /**
- *
- * mesh_path_add_gate - add the given mpath to a mesh gate to our path table
- * @mpath: gate path to add to table
- */
-int mesh_path_add_gate(struct mesh_path *mpath)
-{
-	return mesh_gate_add(mesh_paths, mpath);
-}
-
-/**
  * mesh_gate_num - number of gates known to this interface
  * @sdata: subif data
  */
#2 lore raw

Hi Johannes,

Quoted 6 lines · Johannes Berg

From: Johannes Berg <[email protected]>

Sparse RCU checking reports two warnings in the mesh path table code. These are due to questionable uses of rcu_dereference.

Quoted 8 lines

To fix the first one, get rid of mesh_gate_add() and just make mesh_path_add_gate() do the correct deref.

To fix the second one, simply remove rcu_dereference() in mesh_gate_del() -- it already gets a proper pointer as indicated by the prototype (no __rcu annotation) and confirmed by the code.

Sorry you had to clean up my mess, ACK :)

Thomas

Quoted 76 lines
Cc Javier Cardona <[email protected]>
Cc Thomas Pedersen <[email protected]>

---
v2: oops. fix prototypes

 net/mac80211/mesh_pathtbl.c |   27 +++++----------------------

 1 file changed, 5 insertions(+), 22 deletions(-)
net/mac80211/mesh_pathtbl.c       2011-11-21 11:23:19.000000000 +0100 renamed from net/mac80211/mesh_pathtbl.c       2011-11-21 11:19:44.000000000 +0100 +5 -22
@@ -69,8 +69,6 @@ static inline struct mesh_table *resize_
                lockdep_is_held(&pathtbl_resize_lock));
  }
 
-static int mesh_gate_add(struct mesh_table *tbl, struct mesh_path *mpath);
-
  /*
  * CAREFUL -- "tbl" must not be an expression,
  * in particular not an rcu_dereference(), since
@@ -420,21 +418,18 @@ static void mesh_gate_node_reclaim(struc
  }
 
  /**
- * mesh_gate_add - mark mpath as path to a mesh gate and add to known_gates
- * @mesh_tbl: table which contains known_gates list
- * @mpath: mpath to known mesh gate
- *
- * Returns: 0 on success
- *
+ * mesh_path_add_gate - add the given mpath to a mesh gate to our path table
+ * @mpath: gate path to add to table
  */
-static int mesh_gate_add(struct mesh_table *tbl, struct mesh_path *mpath)
+int mesh_path_add_gate(struct mesh_path *mpath)
  {
+       struct mesh_table *tbl;
        struct mpath_node *gate, *new_gate;
        struct hlist_node *n;
        int err;
 
        rcu_read_lock();
-       tbl = rcu_dereference(tbl);
+       tbl = rcu_dereference(mesh_paths);
 
        hlist_for_each_entry_rcu(gate, n, tbl->known_gates, list)
                if (gate->mpath == mpath) {
@@ -478,8 +473,6 @@ static int mesh_gate_del(struct mesh_tab
        struct mpath_node *gate;
        struct hlist_node *p, *q;
 
-       tbl = rcu_dereference(tbl);
-
        hlist_for_each_entry_safe(gate, p, q, tbl->known_gates, list)
                if (gate->mpath == mpath) {
                        spin_lock_bh(&tbl->gates_lock);
@@ -498,16 +491,6 @@ static int mesh_gate_del(struct mesh_tab
  }
 
  /**
- *
- * mesh_path_add_gate - add the given mpath to a mesh gate to our path table
- * @mpath: gate path to add to table
- */
-int mesh_path_add_gate(struct mesh_path *mpath)
-{
-       return mesh_gate_add(mesh_paths, mpath);
-}
-
-/**
  * mesh_gate_num - number of gates known to this interface
  * @sdata: subif data
  */