LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* /net/tipc/port.c: Use tipc_port_unlock
@ 2008-01-04 14:47 Julia Lawall
  2008-01-08 15:34 ` RE : [tipc-discussion] " Jon Paul Maloy
  0 siblings, 1 reply; 3+ messages in thread
From: Julia Lawall @ 2008-01-04 14:47 UTC (permalink / raw)
  To: per.liden, jon.maloy, allan.stephens, tipc-discussion,
	linux-kernel, kernel-janitors

From: Julia Lawall <julia@diku.dk>

The file net/tipc/port.c takes a lock using the function tipc_port_lock and
then releases the lock sometimes using tipc_port_unlock and sometimes using
spin_unlock_bh(p_ptr->publ.lock).  tipc_port_unlock simply does the
spin_unlock_bh, but it seems cleaner to use it everywhere.


The problem was fixed using the following semantic patch.
(http://www.emn.fr/x-info/coccinelle/)

// <smpl>
@@
struct port *p_ptr;
@@

   p_ptr = tipc_port_lock(...)
   ...
(
   p_ptr = tipc_port_lock(...);
|
?- spin_unlock_bh(p_ptr->publ.lock);
+  tipc_port_unlock(p_ptr);
)
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
---

diff -u -p a/net/tipc/port.c b/net/tipc/port.c
--- a/net/tipc/port.c 2008-01-01 10:43:55.000000000 +0100
+++ b/net/tipc/port.c 2008-01-04 10:51:05.000000000 +0100
@@ -340,7 +340,7 @@ int tipc_portunreliable(u32 ref, unsigne
 	if (!p_ptr)
 		return -EINVAL;
 	*isunreliable = port_unreliable(p_ptr);
-	spin_unlock_bh(p_ptr->publ.lock);
+	tipc_port_unlock(p_ptr);
 	return TIPC_OK;
 }

@@ -369,7 +369,7 @@ int tipc_portunreturnable(u32 ref, unsig
 	if (!p_ptr)
 		return -EINVAL;
 	*isunrejectable = port_unreturnable(p_ptr);
-	spin_unlock_bh(p_ptr->publ.lock);
+	tipc_port_unlock(p_ptr);
 	return TIPC_OK;
 }

@@ -843,7 +843,7 @@ static void port_dispatcher_sigh(void *d
 				u32 peer_port = port_peerport(p_ptr);
 				u32 peer_node = port_peernode(p_ptr);

-				spin_unlock_bh(p_ptr->publ.lock);
+				tipc_port_unlock(p_ptr);
 				if (unlikely(!connected)) {
 					if (unlikely(published))
 						goto reject;
@@ -867,7 +867,7 @@ static void port_dispatcher_sigh(void *d
 		case TIPC_DIRECT_MSG:{
 				tipc_msg_event cb = up_ptr->msg_cb;

-				spin_unlock_bh(p_ptr->publ.lock);
+				tipc_port_unlock(p_ptr);
 				if (unlikely(connected))
 					goto reject;
 				if (unlikely(!cb))
@@ -882,7 +882,7 @@ static void port_dispatcher_sigh(void *d
 		case TIPC_NAMED_MSG:{
 				tipc_named_msg_event cb = up_ptr->named_msg_cb;

-				spin_unlock_bh(p_ptr->publ.lock);
+				tipc_port_unlock(p_ptr);
 				if (unlikely(connected))
 					goto reject;
 				if (unlikely(!cb))
@@ -913,7 +913,7 @@ err:
 				u32 peer_port = port_peerport(p_ptr);
 				u32 peer_node = port_peernode(p_ptr);

-				spin_unlock_bh(p_ptr->publ.lock);
+				tipc_port_unlock(p_ptr);
 				if (!connected || !cb)
 					break;
 				if (msg_origport(msg) != peer_port)
@@ -929,7 +929,7 @@ err:
 		case TIPC_DIRECT_MSG:{
 				tipc_msg_err_event cb = up_ptr->err_cb;

-				spin_unlock_bh(p_ptr->publ.lock);
+				tipc_port_unlock(p_ptr);
 				if (connected || !cb)
 					break;
 				skb_pull(buf, msg_hdr_sz(msg));
@@ -942,7 +942,7 @@ err:
 				tipc_named_msg_err_event cb =
 					up_ptr->named_err_cb;

-				spin_unlock_bh(p_ptr->publ.lock);
+				tipc_port_unlock(p_ptr);
 				if (connected || !cb)
 					break;
 				dseq.type =  msg_nametype(msg);
@@ -1107,7 +1107,7 @@ int tipc_portimportance(u32 ref, unsigne
 	if (!p_ptr)
 		return -EINVAL;
 	*importance = (unsigned int)msg_importance(&p_ptr->publ.phdr);
-	spin_unlock_bh(p_ptr->publ.lock);
+	tipc_port_unlock(p_ptr);
 	return TIPC_OK;
 }

@@ -1122,7 +1122,7 @@ int tipc_set_portimportance(u32 ref, uns
 	if (!p_ptr)
 		return -EINVAL;
 	msg_set_importance(&p_ptr->publ.phdr, (u32)imp);
-	spin_unlock_bh(p_ptr->publ.lock);
+	tipc_port_unlock(p_ptr);
 	return TIPC_OK;
 }


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

* RE : [tipc-discussion] /net/tipc/port.c: Use tipc_port_unlock
  2008-01-04 14:47 /net/tipc/port.c: Use tipc_port_unlock Julia Lawall
@ 2008-01-08 15:34 ` Jon Paul Maloy
  2008-01-09  7:48   ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: Jon Paul Maloy @ 2008-01-08 15:34 UTC (permalink / raw)
  To: Julia Lawall, per.liden, jon.maloy, allan.stephens,
	tipc-discussion, linux-kernel, kernel-janitors

I have no objections.
///jon

--- Julia Lawall <julia@diku.dk> a écrit :

> From: Julia Lawall <julia@diku.dk>
> 
> The file net/tipc/port.c takes a lock using the
> function tipc_port_lock and
> then releases the lock sometimes using
> tipc_port_unlock and sometimes using
> spin_unlock_bh(p_ptr->publ.lock).  tipc_port_unlock
> simply does the
> spin_unlock_bh, but it seems cleaner to use it
> everywhere.
> 
> 
> The problem was fixed using the following semantic
> patch.
> (http://www.emn.fr/x-info/coccinelle/)
> 
> // <smpl>
> @@
> struct port *p_ptr;
> @@
> 
>    p_ptr = tipc_port_lock(...)
>    ...
> (
>    p_ptr = tipc_port_lock(...);
> |
> ?- spin_unlock_bh(p_ptr->publ.lock);
> +  tipc_port_unlock(p_ptr);
> )
> // </smpl>
> 
> Signed-off-by: Julia Lawall <julia@diku.dk>
> ---
> 
> diff -u -p a/net/tipc/port.c b/net/tipc/port.c
> --- a/net/tipc/port.c 2008-01-01 10:43:55.000000000
> +0100
> +++ b/net/tipc/port.c 2008-01-04 10:51:05.000000000
> +0100
> @@ -340,7 +340,7 @@ int tipc_portunreliable(u32 ref,
> unsigne
>  	if (!p_ptr)
>  		return -EINVAL;
>  	*isunreliable = port_unreliable(p_ptr);
> -	spin_unlock_bh(p_ptr->publ.lock);
> +	tipc_port_unlock(p_ptr);
>  	return TIPC_OK;
>  }
> 
> @@ -369,7 +369,7 @@ int tipc_portunreturnable(u32
> ref, unsig
>  	if (!p_ptr)
>  		return -EINVAL;
>  	*isunrejectable = port_unreturnable(p_ptr);
> -	spin_unlock_bh(p_ptr->publ.lock);
> +	tipc_port_unlock(p_ptr);
>  	return TIPC_OK;
>  }
> 
> @@ -843,7 +843,7 @@ static void
> port_dispatcher_sigh(void *d
>  				u32 peer_port = port_peerport(p_ptr);
>  				u32 peer_node = port_peernode(p_ptr);
> 
> -				spin_unlock_bh(p_ptr->publ.lock);
> +				tipc_port_unlock(p_ptr);
>  				if (unlikely(!connected)) {
>  					if (unlikely(published))
>  						goto reject;
> @@ -867,7 +867,7 @@ static void
> port_dispatcher_sigh(void *d
>  		case TIPC_DIRECT_MSG:{
>  				tipc_msg_event cb = up_ptr->msg_cb;
> 
> -				spin_unlock_bh(p_ptr->publ.lock);
> +				tipc_port_unlock(p_ptr);
>  				if (unlikely(connected))
>  					goto reject;
>  				if (unlikely(!cb))
> @@ -882,7 +882,7 @@ static void
> port_dispatcher_sigh(void *d
>  		case TIPC_NAMED_MSG:{
>  				tipc_named_msg_event cb = up_ptr->named_msg_cb;
> 
> -				spin_unlock_bh(p_ptr->publ.lock);
> +				tipc_port_unlock(p_ptr);
>  				if (unlikely(connected))
>  					goto reject;
>  				if (unlikely(!cb))
> @@ -913,7 +913,7 @@ err:
>  				u32 peer_port = port_peerport(p_ptr);
>  				u32 peer_node = port_peernode(p_ptr);
> 
> -				spin_unlock_bh(p_ptr->publ.lock);
> +				tipc_port_unlock(p_ptr);
>  				if (!connected || !cb)
>  					break;
>  				if (msg_origport(msg) != peer_port)
> @@ -929,7 +929,7 @@ err:
>  		case TIPC_DIRECT_MSG:{
>  				tipc_msg_err_event cb = up_ptr->err_cb;
> 
> -				spin_unlock_bh(p_ptr->publ.lock);
> +				tipc_port_unlock(p_ptr);
>  				if (connected || !cb)
>  					break;
>  				skb_pull(buf, msg_hdr_sz(msg));
> @@ -942,7 +942,7 @@ err:
>  				tipc_named_msg_err_event cb =
>  					up_ptr->named_err_cb;
> 
> -				spin_unlock_bh(p_ptr->publ.lock);
> +				tipc_port_unlock(p_ptr);
>  				if (connected || !cb)
>  					break;
>  				dseq.type =  msg_nametype(msg);
> @@ -1107,7 +1107,7 @@ int tipc_portimportance(u32
> ref, unsigne
>  	if (!p_ptr)
>  		return -EINVAL;
>  	*importance = (unsigned
> int)msg_importance(&p_ptr->publ.phdr);
> -	spin_unlock_bh(p_ptr->publ.lock);
> +	tipc_port_unlock(p_ptr);
>  	return TIPC_OK;
>  }
> 
> @@ -1122,7 +1122,7 @@ int
> tipc_set_portimportance(u32 ref, uns
>  	if (!p_ptr)
>  		return -EINVAL;
>  	msg_set_importance(&p_ptr->publ.phdr, (u32)imp);
> -	spin_unlock_bh(p_ptr->publ.lock);
> +	tipc_port_unlock(p_ptr);
>  	return TIPC_OK;
>  }
> 
> 
>
-------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio
> 2005.
>
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> tipc-discussion mailing list
> tipc-discussion@lists.sourceforge.net
>
https://lists.sourceforge.net/lists/listinfo/tipc-discussion
> 


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

* Re: RE : [tipc-discussion] /net/tipc/port.c: Use tipc_port_unlock
  2008-01-08 15:34 ` RE : [tipc-discussion] " Jon Paul Maloy
@ 2008-01-09  7:48   ` David Miller
  0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2008-01-09  7:48 UTC (permalink / raw)
  To: maloy
  Cc: julia, per.liden, jon.maloy, allan.stephens, tipc-discussion,
	linux-kernel, kernel-janitors

From: Jon Paul Maloy <maloy@donjonn.com>
Date: Tue, 8 Jan 2008 10:34:58 -0500 (EST)

> I have no objections.

I've applied this patch, thanks everyone.

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

end of thread, other threads:[~2008-01-09  7:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-04 14:47 /net/tipc/port.c: Use tipc_port_unlock Julia Lawall
2008-01-08 15:34 ` RE : [tipc-discussion] " Jon Paul Maloy
2008-01-09  7:48   ` 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).