@@ -150,7 +150,7 @@ static int is_bidirectional_neigh(struct orig_node *orig_node,
150150 struct batman_if * if_incoming )
151151{
152152 struct bat_priv * bat_priv = netdev_priv (if_incoming -> soft_iface );
153- struct neigh_node * neigh_node = NULL , * tmp_neigh_node = NULL ;
153+ struct neigh_node * neigh_node = NULL , * tmp_neigh_node ;
154154 struct hlist_node * node ;
155155 unsigned char total_count ;
156156 uint8_t orig_eq_count , neigh_rq_count , tq_own ;
@@ -161,27 +161,27 @@ static int is_bidirectional_neigh(struct orig_node *orig_node,
161161 hlist_for_each_entry_rcu (tmp_neigh_node , node ,
162162 & orig_node -> neigh_list , list ) {
163163
164- if (compare_eth (tmp_neigh_node -> addr ,
165- orig_neigh_node -> orig ) &&
166- (tmp_neigh_node -> if_incoming == if_incoming ))
167- neigh_node = tmp_neigh_node ;
164+ if (!compare_eth (tmp_neigh_node -> addr ,
165+ orig_neigh_node -> orig ))
166+ continue ;
167+
168+ if (tmp_neigh_node -> if_incoming != if_incoming )
169+ continue ;
170+
171+ if (!atomic_inc_not_zero (& tmp_neigh_node -> refcount ))
172+ continue ;
173+
174+ neigh_node = tmp_neigh_node ;
168175 }
176+ rcu_read_unlock ();
169177
170178 if (!neigh_node )
171179 neigh_node = create_neighbor (orig_node ,
172180 orig_neigh_node ,
173181 orig_neigh_node -> orig ,
174182 if_incoming );
175- /* create_neighbor failed, return 0 */
176183 if (!neigh_node )
177- goto unlock ;
178-
179- if (!atomic_inc_not_zero (& neigh_node -> refcount )) {
180- neigh_node = NULL ;
181- goto unlock ;
182- }
183-
184- rcu_read_unlock ();
184+ goto out ;
185185
186186 neigh_node -> last_valid = jiffies ;
187187 } else {
@@ -190,27 +190,27 @@ static int is_bidirectional_neigh(struct orig_node *orig_node,
190190 hlist_for_each_entry_rcu (tmp_neigh_node , node ,
191191 & orig_neigh_node -> neigh_list , list ) {
192192
193- if (compare_eth (tmp_neigh_node -> addr ,
194- orig_neigh_node -> orig ) &&
195- (tmp_neigh_node -> if_incoming == if_incoming ))
196- neigh_node = tmp_neigh_node ;
193+ if (!compare_eth (tmp_neigh_node -> addr ,
194+ orig_neigh_node -> orig ))
195+ continue ;
196+
197+ if (tmp_neigh_node -> if_incoming != if_incoming )
198+ continue ;
199+
200+ if (!atomic_inc_not_zero (& tmp_neigh_node -> refcount ))
201+ continue ;
202+
203+ neigh_node = tmp_neigh_node ;
197204 }
205+ rcu_read_unlock ();
198206
199207 if (!neigh_node )
200208 neigh_node = create_neighbor (orig_neigh_node ,
201209 orig_neigh_node ,
202210 orig_neigh_node -> orig ,
203211 if_incoming );
204- /* create_neighbor failed, return 0 */
205212 if (!neigh_node )
206- goto unlock ;
207-
208- if (!atomic_inc_not_zero (& neigh_node -> refcount )) {
209- neigh_node = NULL ;
210- goto unlock ;
211- }
212-
213- rcu_read_unlock ();
213+ goto out ;
214214 }
215215
216216 orig_node -> last_valid = jiffies ;
@@ -265,10 +265,6 @@ static int is_bidirectional_neigh(struct orig_node *orig_node,
265265 if (batman_packet -> tq >= TQ_TOTAL_BIDRECT_LIMIT )
266266 ret = 1 ;
267267
268- goto out ;
269-
270- unlock :
271- rcu_read_unlock ();
272268out :
273269 if (neigh_node )
274270 neigh_node_free_ref (neigh_node );
@@ -423,11 +419,6 @@ static void update_orig(struct bat_priv *bat_priv,
423419 orig_node_free_ref (orig_tmp );
424420 if (!neigh_node )
425421 goto unlock ;
426-
427- if (!atomic_inc_not_zero (& neigh_node -> refcount )) {
428- neigh_node = NULL ;
429- goto unlock ;
430- }
431422 } else
432423 bat_dbg (DBG_BATMAN , bat_priv ,
433424 "Updating existing last-hop neighbor of originator\n" );
0 commit comments