diff options
author | Antonio Quartulli <antonio@open-mesh.com> | 2013-10-12 20:50:18 -0400 |
---|---|---|
committer | Antonio Quartulli <antonio@meshcoding.com> | 2013-10-23 11:03:44 -0400 |
commit | 0c69aecc5b1a57d62c39cf8c552a9e823409db60 (patch) | |
tree | 7e4fe1bdec04e8fec9b3b7c802bfa17be0c05782 /net/batman-adv/hard-interface.c | |
parent | 8257f55ae277dd94c015f7cf32f4afd1db59fe8d (diff) |
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>
Diffstat (limited to 'net/batman-adv/hard-interface.c')
-rw-r--r-- | net/batman-adv/hard-interface.c | 33 |
1 files changed, 4 insertions, 29 deletions
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c index 1ba8a552b62b..57c2a19dcb5c 100644 --- a/net/batman-adv/hard-interface.c +++ b/net/batman-adv/hard-interface.c | |||
@@ -125,8 +125,11 @@ static int batadv_is_valid_iface(const struct net_device *net_dev) | |||
125 | * | 125 | * |
126 | * Returns true if the net device is a 802.11 wireless device, false otherwise. | 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 | #ifdef CONFIG_WIRELESS_EXT | 133 | #ifdef CONFIG_WIRELESS_EXT |
131 | /* pre-cfg80211 drivers have to implement WEXT, so it is possible to | 134 | /* pre-cfg80211 drivers have to implement WEXT, so it is possible to |
132 | * check for wireless_handlers != NULL | 135 | * check for wireless_handlers != NULL |
@@ -142,34 +145,6 @@ static bool batadv_is_wifi_netdev(struct net_device *net_device) | |||
142 | return false; | 145 | return false; |
143 | } | 146 | } |
144 | 147 | ||
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 | } | ||
172 | |||
173 | static struct batadv_hard_iface * | 148 | static struct batadv_hard_iface * |
174 | batadv_hardif_get_active(const struct net_device *soft_iface) | 149 | batadv_hardif_get_active(const struct net_device *soft_iface) |
175 | { | 150 | { |