netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: akpm@linux-foundation.org
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, akpm@linux-foundation.org
Subject: [patch 2/4] net: use mutex_is_locked() for ASSERT_RTNL()
Date: Thu, 13 Dec 2007 16:02:36 -0800	[thread overview]
Message-ID: <200712140002.lBE02aGO025491@imap1.linux-foundation.org> (raw)

From: Andrew Morton <akpm@linux-foundation.org>

ASSERT_RTNL() uses mutex_trylock(), but it's better to use mutex_is_locked().

Make that change, and remove rtnl_trylock() altogether.

(not tested yet!)

Cc: "David S. Miller" <davem@davemloft.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 drivers/net/cxgb3/cxgb3_main.c |    3 +--
 include/linux/rtnetlink.h      |    5 ++---
 net/core/rtnetlink.c           |    7 ++++---
 3 files changed, 7 insertions(+), 8 deletions(-)

diff -puN drivers/net/cxgb3/cxgb3_main.c~net-use-mutex_is_locked-for-assert_rtnl drivers/net/cxgb3/cxgb3_main.c
--- a/drivers/net/cxgb3/cxgb3_main.c~net-use-mutex_is_locked-for-assert_rtnl
+++ a/drivers/net/cxgb3/cxgb3_main.c
@@ -2191,7 +2191,7 @@ static void check_t3b2_mac(struct adapte
 {
 	int i;
 
-	if (!rtnl_trylock())	/* synchronize with ifdown */
+	if (rtnl_is_locked())	/* synchronize with ifdown */
 		return;
 
 	for_each_port(adapter, i) {
@@ -2219,7 +2219,6 @@ static void check_t3b2_mac(struct adapte
 			p->mac.stats.num_resets++;
 		}
 	}
-	rtnl_unlock();
 }
 
 
diff -puN include/linux/rtnetlink.h~net-use-mutex_is_locked-for-assert_rtnl include/linux/rtnetlink.h
--- a/include/linux/rtnetlink.h~net-use-mutex_is_locked-for-assert_rtnl
+++ a/include/linux/rtnetlink.h
@@ -751,14 +751,13 @@ extern void rtmsg_ifinfo(int type, struc
 /* RTNL is used as a global lock for all changes to network configuration  */
 extern void rtnl_lock(void);
 extern void rtnl_unlock(void);
-extern int rtnl_trylock(void);
+extern int rtnl_is_locked(void);
 
 extern void rtnetlink_init(void);
 extern void __rtnl_unlock(void);
 
 #define ASSERT_RTNL() do { \
-	if (unlikely(rtnl_trylock())) { \
-		rtnl_unlock(); \
+	if (unlikely(!rtnl_is_locked())) { \
 		printk(KERN_ERR "RTNL: assertion failed at %s (%d)\n", \
 		       __FILE__,  __LINE__); \
 		dump_stack(); \
diff -puN net/core/rtnetlink.c~net-use-mutex_is_locked-for-assert_rtnl net/core/rtnetlink.c
--- a/net/core/rtnetlink.c~net-use-mutex_is_locked-for-assert_rtnl
+++ a/net/core/rtnetlink.c
@@ -77,9 +77,10 @@ void rtnl_unlock(void)
 	netdev_run_todo();
 }
 
-int rtnl_trylock(void)
+/* Return non-zero if rtnl_mutex is presently held */
+int rtnl_is_locked(void)
 {
-	return mutex_trylock(&rtnl_mutex);
+	return mutex_is_locked(&rtnl_mutex);
 }
 
 int rtattr_parse(struct rtattr *tb[], int maxattr, struct rtattr *rta, int len)
@@ -1424,7 +1425,7 @@ EXPORT_SYMBOL(rtattr_parse);
 EXPORT_SYMBOL(__rtattr_parse_nested_compat);
 EXPORT_SYMBOL(rtnetlink_put_metrics);
 EXPORT_SYMBOL(rtnl_lock);
-EXPORT_SYMBOL(rtnl_trylock);
+EXPORT_SYMBOL(rtnl_is_locked);
 EXPORT_SYMBOL(rtnl_unlock);
 EXPORT_SYMBOL(rtnl_unicast);
 EXPORT_SYMBOL(rtnl_notify);
_

             reply	other threads:[~2007-12-14  0:02 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-14  0:02 akpm [this message]
2007-12-14  8:10 ` [patch 2/4] net: use mutex_is_locked() for ASSERT_RTNL() Herbert Xu
2007-12-14  8:22   ` Andrew Morton
2007-12-14  8:30     ` Herbert Xu
2007-12-14 19:15       ` David Miller
2007-12-14 23:11         ` Andrew Morton
2007-12-15  4:18           ` Herbert Xu
2007-12-15  5:44             ` Andrew Morton
2007-12-15  6:10               ` Herbert Xu
2007-12-15 10:48                 ` Andrew Morton
2007-12-15 13:10                   ` Herbert Xu
2007-12-16  5:44                     ` David Miller
2007-12-16  7:13                       ` Herbert Xu
2007-12-16 18:06                   ` Jarek Poplawski
2007-12-17  1:26                     ` Herbert Xu
2007-12-17  7:26                       ` Jarek Poplawski
2007-12-17  7:31                         ` Herbert Xu
2007-12-17  7:57                           ` Jarek Poplawski
2007-12-17  7:44                         ` Jarek Poplawski
2007-12-16  5:37               ` David Miller
2007-12-14 12:37     ` Johannes Berg
2007-12-14 12:46       ` Herbert Xu
2007-12-14 12:54         ` Johannes Berg
2007-12-14 19:30 ` David Miller

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=200712140002.lBE02aGO025491@imap1.linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).