Commit 0c69aecc5b1a57d62c39cf8c552a9e823409db60

Authored by Antonio Quartulli
Committed by Antonio Quartulli
1 parent 8257f55ae2

batman-adv: invoke dev_get_by_index() outside of is_wifi_iface()

Upcoming changes need to perform other checks on the
incoming net_device struct.

To avoid performing dev_get_by_index() for each and every
check, it is better to move it outside of is_wifi_iface()
and search the netdev object once only.

Signed-off-by: Antonio Quartulli <antonio@open-mesh.com>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>

Showing 3 changed files with 12 additions and 31 deletions Side-by-side Diff

net/batman-adv/hard-interface.c
... ... @@ -125,8 +125,11 @@
125 125 *
126 126 * Returns true if the net device is a 802.11 wireless device, false otherwise.
127 127 */
128   -static bool batadv_is_wifi_netdev(struct net_device *net_device)
  128 +bool batadv_is_wifi_netdev(struct net_device *net_device)
129 129 {
  130 + if (!net_device)
  131 + return false;
  132 +
130 133 #ifdef CONFIG_WIRELESS_EXT
131 134 /* pre-cfg80211 drivers have to implement WEXT, so it is possible to
132 135 * check for wireless_handlers != NULL
... ... @@ -140,34 +143,6 @@
140 143 return true;
141 144  
142 145 return false;
143   -}
144   -
145   -/**
146   - * batadv_is_wifi_iface - check if the given interface represented by ifindex
147   - * is a wifi interface
148   - * @ifindex: interface index to check
149   - *
150   - * Returns true if the interface represented by ifindex is a 802.11 wireless
151   - * device, false otherwise.
152   - */
153   -bool batadv_is_wifi_iface(int ifindex)
154   -{
155   - struct net_device *net_device = NULL;
156   - bool ret = false;
157   -
158   - if (ifindex == BATADV_NULL_IFINDEX)
159   - goto out;
160   -
161   - net_device = dev_get_by_index(&init_net, ifindex);
162   - if (!net_device)
163   - goto out;
164   -
165   - ret = batadv_is_wifi_netdev(net_device);
166   -
167   -out:
168   - if (net_device)
169   - dev_put(net_device);
170   - return ret;
171 146 }
172 147  
173 148 static struct batadv_hard_iface *
net/batman-adv/hard-interface.h
... ... @@ -41,6 +41,7 @@
41 41  
42 42 extern struct notifier_block batadv_hard_if_notifier;
43 43  
  44 +bool batadv_is_wifi_netdev(struct net_device *net_device);
44 45 struct batadv_hard_iface*
45 46 batadv_hardif_get_by_netdev(const struct net_device *net_dev);
46 47 int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
... ... @@ -51,7 +52,6 @@
51 52 int batadv_hardif_min_mtu(struct net_device *soft_iface);
52 53 void batadv_update_min_mtu(struct net_device *soft_iface);
53 54 void batadv_hardif_free_rcu(struct rcu_head *rcu);
54   -bool batadv_is_wifi_iface(int ifindex);
55 55  
56 56 static inline void
57 57 batadv_hardif_free_ref(struct batadv_hard_iface *hard_iface)
net/batman-adv/translation-table.c
... ... @@ -477,11 +477,15 @@
477 477 struct batadv_priv *bat_priv = netdev_priv(soft_iface);
478 478 struct batadv_tt_local_entry *tt_local;
479 479 struct batadv_tt_global_entry *tt_global;
  480 + struct net_device *in_dev = NULL;
480 481 struct hlist_head *head;
481 482 struct batadv_tt_orig_list_entry *orig_entry;
482 483 int hash_added, table_size, packet_size_max;
483 484 bool ret = false, roamed_back = false;
484 485  
  486 + if (ifindex != BATADV_NULL_IFINDEX)
  487 + in_dev = dev_get_by_index(&init_net, ifindex);
  488 +
485 489 tt_local = batadv_tt_local_hash_find(bat_priv, addr, vid);
486 490 tt_global = batadv_tt_global_hash_find(bat_priv, addr, vid);
487 491  
... ... @@ -542,7 +546,7 @@
542 546 */
543 547 tt_local->common.flags = BATADV_TT_CLIENT_NEW;
544 548 tt_local->common.vid = vid;
545   - if (batadv_is_wifi_iface(ifindex))
  549 + if (batadv_is_wifi_netdev(in_dev))
546 550 tt_local->common.flags |= BATADV_TT_CLIENT_WIFI;
547 551 atomic_set(&tt_local->common.refcount, 2);
548 552 tt_local->last_seen = jiffies;
... ... @@ -595,6 +599,8 @@
595 599 ret = true;
596 600  
597 601 out:
  602 + if (in_dev)
  603 + dev_put(in_dev);
598 604 if (tt_local)
599 605 batadv_tt_local_entry_free_ref(tt_local);
600 606 if (tt_global)