From: Antonio Quartulli <antonio@meshcoding.com>
To: b.a.t.m.a.n@lists.open-mesh.org
Cc: Antonio Quartulli <antonio@meshcoding.com>
Subject: [B.A.T.M.A.N.] [PATCHv3 next 02/11] batman-adv: don't mess up with the netdev refcounting if not needed
Date: Wed, 19 Mar 2014 18:41:48 +0100 [thread overview]
Message-ID: <1395250917-19621-2-git-send-email-antonio@meshcoding.com> (raw)
In-Reply-To: <1395250917-19621-1-git-send-email-antonio@meshcoding.com>
Looking for an interface and increasing its refcounter only
to check if it really exists is not really useful and makes
the code look more complex without a real gain.
Change batadv_mcast_has_bridge() accordingly and avoid to
use the pointer to the interface outside of the
rcu_read_lock/unlock context.
Introduced by e368857f66620b8483166e8e6556d9c87f9b3e71
("batman-adv: Multicast Listener Announcements via Translation Table")
Cc: Linus Lüssing <linus.luessing@web.de>
Signed-off-by: Antonio Quartulli <antonio@meshcoding.com>
---
compat.h | 19 ++++---------------
multicast.c | 33 +++++++--------------------------
2 files changed, 11 insertions(+), 41 deletions(-)
diff --git a/compat.h b/compat.h
index e14c6bb..5eb5fe6 100644
--- a/compat.h
+++ b/compat.h
@@ -164,14 +164,8 @@ static inline int batadv_param_set_copystring(const char *val,
#define NET_ADDR_RANDOM 0
#define netdev_master_upper_dev_get_rcu(dev) \
- upper; \
- if (dev->br_port ? 1 : 0) { \
- rcu_read_unlock(); \
- dev_hold(dev); \
- return dev; \
- } else {\
- dev = NULL; \
- }
+ (dev->br_port ? dev : NULL); \
+ break;
#endif /* < KERNEL_VERSION(2, 6, 36) */
@@ -375,13 +369,8 @@ static int __batadv_interface_tx(struct sk_buff *skb, \
#ifndef netdev_master_upper_dev_get_rcu
#define netdev_master_upper_dev_get_rcu(dev) \
- upper; \
- if (dev->priv_flags & IFF_BRIDGE_PORT) { \
- rcu_read_unlock(); \
- dev_hold(dev); \
- return dev; \
- } else \
- dev = NULL;
+ (dev->priv_flags & IFF_BRIDGE_PORT ? dev : NULL); \
+ break;
#endif /* netdev_master_upper_dev_get_rcu */
diff --git a/multicast.c b/multicast.c
index d92de1e..af3fe49 100644
--- a/multicast.c
+++ b/multicast.c
@@ -156,16 +156,16 @@ static void batadv_mcast_mla_tt_add(struct batadv_priv *bat_priv,
}
/**
- * batadv_mcast_get_bridge - get the bridge interface on our soft interface
+ * batadv_mcast_has_bridge - check whether the soft-iface is bridged
* @bat_priv: the bat priv with all the soft interface information
*
- * Return the next bridge interface on top of our soft interface and increase
- * its refcount. If no such bridge interface exists, then return NULL.
+ * Check whether there is a bridge on top of our soft interface. Return
+ * true if so, false otherwise.
*/
-static struct net_device *
-batadv_mcast_get_bridge(struct batadv_priv *bat_priv)
+static bool batadv_mcast_has_bridge(struct batadv_priv *bat_priv)
{
struct net_device *upper = bat_priv->soft_iface;
+ bool has_bridge = false;
rcu_read_lock();
@@ -174,30 +174,11 @@ batadv_mcast_get_bridge(struct batadv_priv *bat_priv)
} while (upper && !(upper->priv_flags & IFF_EBRIDGE));
if (upper)
- dev_hold(upper);
+ has_bridge = true;
rcu_read_unlock();
- return upper;
-}
-
-/**
- * batadv_mcast_has_bridge - check whether the soft-iface is bridged
- * @bat_priv: the bat priv with all the soft interface information
- *
- * Check whether there is a bridge on top of our soft interface. Return
- * true if so, false otherwise.
- */
-static bool batadv_mcast_has_bridge(struct batadv_priv *bat_priv)
-{
- struct net_device *bridge;
-
- bridge = batadv_mcast_get_bridge(bat_priv);
- if (!bridge)
- return false;
-
- dev_put(bridge);
- return true;
+ return has_bridge;
}
/**
--
1.8.3.2
next prev parent reply other threads:[~2014-03-19 17:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-19 17:41 [B.A.T.M.A.N.] [PATCHv3 next 01/11] batman-adv: remove useless goto Antonio Quartulli
2014-03-19 17:41 ` Antonio Quartulli [this message]
2014-03-19 17:41 ` [B.A.T.M.A.N.] [PATCHv3 next 03/11] batman-adv: fix multicast kerneldoc Antonio Quartulli
2014-03-19 17:41 ` [B.A.T.M.A.N.] [PATCHv3 next 04/11] " Antonio Quartulli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1395250917-19621-2-git-send-email-antonio@meshcoding.com \
--to=antonio@meshcoding.com \
--cc=b.a.t.m.a.n@lists.open-mesh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.