netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] tipc: eliminate smatch warnings
@ 2014-02-14 21:40 Jon Maloy
  2014-02-14 21:40 ` [PATCH net-next 1/2] tipc: fix a loop style problem Jon Maloy
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jon Maloy @ 2014-02-14 21:40 UTC (permalink / raw)
  To: davem
  Cc: netdev, Paul Gortmaker, erik.hugne, ying.xue, maloy,
	tipc-discussion, Jon Maloy

We fix a couple of issues introduced by the series 
"tipc: clean up media and bearer layer". 

Thanks to Dan Carpenter and Walter Harms for highlighting this.

Jon Maloy (2):
  tipc: fix a loop style problem
  tipc: correct usage of spin_lock() vs spin_lock_bh()

 net/tipc/link.c |    6 +++---
 net/tipc/node.c |   10 +++++-----
 2 files changed, 8 insertions(+), 8 deletions(-)

-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH net-next 1/2] tipc: fix a loop style problem
  2014-02-14 21:40 [PATCH net-next 0/2] tipc: eliminate smatch warnings Jon Maloy
@ 2014-02-14 21:40 ` Jon Maloy
  2014-02-14 21:40 ` [PATCH net-next 2/2] tipc: correct usage of spin_lock() vs spin_lock_bh() Jon Maloy
  2014-02-17  5:26 ` [PATCH net-next 0/2] tipc: eliminate smatch warnings David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Jon Maloy @ 2014-02-14 21:40 UTC (permalink / raw)
  To: davem
  Cc: netdev, Paul Gortmaker, erik.hugne, ying.xue, maloy,
	tipc-discussion, Jon Maloy

In commit 7d33939f475d403e79124e3143d7951dcfe8629f
("tipc: delay delete of link when failover is needed") we
introduced a loop for finding and removing a link pointer
in an array. The removal is done after we have left the loop,
giving the impression that one may remove the wrong pointer
if no matching element is found.

This is not really a bug, since we know that there will always
be a matching element, but it looks wrong, and causes a smatch
warning.

We fix this loop with this commit.

Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
---
 net/tipc/node.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/net/tipc/node.c b/net/tipc/node.c
index 833324b..8596880 100644
--- a/net/tipc/node.c
+++ b/net/tipc/node.c
@@ -252,12 +252,12 @@ void tipc_node_detach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr)
 	int i;
 
 	for (i = 0; i < MAX_BEARERS; i++) {
-		if (l_ptr == n_ptr->links[i])
-			break;
+		if (l_ptr != n_ptr->links[i])
+			continue;
+		n_ptr->links[i] = NULL;
+		atomic_dec(&tipc_num_links);
+		n_ptr->link_cnt--;
 	}
-	n_ptr->links[i] = NULL;
-	atomic_dec(&tipc_num_links);
-	n_ptr->link_cnt--;
 }
 
 static void node_established_contact(struct tipc_node *n_ptr)
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH net-next 2/2] tipc: correct usage of spin_lock() vs spin_lock_bh()
  2014-02-14 21:40 [PATCH net-next 0/2] tipc: eliminate smatch warnings Jon Maloy
  2014-02-14 21:40 ` [PATCH net-next 1/2] tipc: fix a loop style problem Jon Maloy
@ 2014-02-14 21:40 ` Jon Maloy
  2014-02-17  5:26 ` [PATCH net-next 0/2] tipc: eliminate smatch warnings David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Jon Maloy @ 2014-02-14 21:40 UTC (permalink / raw)
  To: davem
  Cc: netdev, Paul Gortmaker, erik.hugne, ying.xue, maloy,
	tipc-discussion, Jon Maloy

I commit e099e86c9e24fe9aff36773600543eb31d8954d
("tipc: add node_lock protection to link lookup function")
we are calling spin_lock(&node->lock) directly instead of indirectly
via the tipc_node_lock(node) function. However, tipc_node_lock() is
using spin_lock_bh(), not spin_lock(), something leading to
unbalanced usage in one place, and a smatch warning.

We fix this by consistently using tipc_node_lock()/unlock() in
in the places touched by the mentioned commit.

Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
---
 net/tipc/link.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/tipc/link.c b/net/tipc/link.c
index 4fb4ae0..5422e96 100644
--- a/net/tipc/link.c
+++ b/net/tipc/link.c
@@ -2410,7 +2410,7 @@ static struct tipc_node *tipc_link_find_owner(const char *link_name,
 
 	*bearer_id = 0;
 	list_for_each_entry_safe(n_ptr, tmp_n_ptr, &tipc_node_list, list) {
-		spin_lock(&n_ptr->lock);
+		tipc_node_lock(n_ptr);
 		for (i = 0; i < MAX_BEARERS; i++) {
 			l_ptr = n_ptr->links[i];
 			if (l_ptr && !strcmp(l_ptr->name, link_name)) {
@@ -2419,7 +2419,7 @@ static struct tipc_node *tipc_link_find_owner(const char *link_name,
 				break;
 			}
 		}
-		spin_unlock(&n_ptr->lock);
+		tipc_node_unlock(n_ptr);
 		if (found_node)
 			break;
 	}
@@ -2603,7 +2603,7 @@ struct sk_buff *tipc_link_cmd_reset_stats(const void *req_tlv_area, int req_tlv_
 		read_unlock_bh(&tipc_net_lock);
 		return tipc_cfg_reply_error_string("link not found");
 	}
-	spin_lock(&node->lock);
+	tipc_node_lock(node);
 	l_ptr = node->links[bearer_id];
 	if (!l_ptr) {
 		tipc_node_unlock(node);
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next 0/2] tipc: eliminate smatch warnings
  2014-02-14 21:40 [PATCH net-next 0/2] tipc: eliminate smatch warnings Jon Maloy
  2014-02-14 21:40 ` [PATCH net-next 1/2] tipc: fix a loop style problem Jon Maloy
  2014-02-14 21:40 ` [PATCH net-next 2/2] tipc: correct usage of spin_lock() vs spin_lock_bh() Jon Maloy
@ 2014-02-17  5:26 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2014-02-17  5:26 UTC (permalink / raw)
  To: jon.maloy; +Cc: netdev, tipc-discussion

From: Jon Maloy <jon.maloy@ericsson.com>
Date: Fri, 14 Feb 2014 16:40:42 -0500

> We fix a couple of issues introduced by the series 
> "tipc: clean up media and bearer layer". 
> 
> Thanks to Dan Carpenter and Walter Harms for highlighting this.

Both patches applied, thanks.

------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-02-17  5:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-14 21:40 [PATCH net-next 0/2] tipc: eliminate smatch warnings Jon Maloy
2014-02-14 21:40 ` [PATCH net-next 1/2] tipc: fix a loop style problem Jon Maloy
2014-02-14 21:40 ` [PATCH net-next 2/2] tipc: correct usage of spin_lock() vs spin_lock_bh() Jon Maloy
2014-02-17  5:26 ` [PATCH net-next 0/2] tipc: eliminate smatch warnings David Miller

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).