Skip to contentSkip to conversation

irda: Fix RCU lock pairing on error path

PATCH Applied Josh Triplett 4 participants 6 messages Jun 29, 2006 – Jun 30, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 irda: Fix RCU lock pairing on error path

irlan_client_discovery_indication calls rcu_read_lock and rcu_read_unlock, but returns without unlocking in an error case. Fix that by replacing the return with a goto so that the rcu_read_unlock always gets executed.

---

 net/irda/irlan/irlan_client.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

e20ab96944814489277c3bfd4e69133854ab01e9

net/irda/irlan/irlan_client.c +2 -1
index f8e6cb0..5ce7d2e 100644
@@ -173,13 +173,14 @@ void irlan_client_discovery_indication(d
 	rcu_read_lock();
 	self = irlan_get_any();
 	if (self) {
-		IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
+		IRDA_ASSERT(self->magic == IRLAN_MAGIC, goto out;);
 
 		IRDA_DEBUG(1, "%s(), Found instance (%08x)!\n", __FUNCTION__ ,
 		      daddr);
 		
 		irlan_client_wakeup(self, saddr, daddr);
 	}
+out:
 	rcu_read_unlock();
 }
 	
Acked-by on v1 1/1
#1 lore raw
Quoted 3 lines · Josh Triplett

irlan_client_discovery_indication calls rcu_read_lock and rcu_read_unlock, but returns without unlocking in an error case. Fix that by replacing the return with a goto so that the rcu_read_unlock always gets executed.

Good catch!!! Looks good from an RCU viewpoint, in fact, looks absolutely necessary to permit IRDA to work in debug mode, particularly in either a CONFIG_PREEMPT or a -rt kernel.

One question below, but up to the maintainer. ;-)

Thanx, Paul

Quoted 15 lines

---

 net/irda/irlan/irlan_client.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

e20ab96944814489277c3bfd4e69133854ab01e9

net/irda/irlan/irlan_client.c +0 -0
index f8e6cb0..5ce7d2e 100644
@@ -173,13 +173,14 @@ void irlan_client_discovery_indication(d
 	rcu_read_lock();
 	self = irlan_get_any();

net/irda/irlan/irlan_client.c void irlan_client_discovery_indication(d · line 183

Quoted 10 lines
net/irda/irlan/irlan_client.c +2 -1
 	if (self) {
-		IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
+		IRDA_ASSERT(self->magic == IRLAN_MAGIC, goto out;);
 
 		IRDA_DEBUG(1, "%s(), Found instance (%08x)!\n", __FUNCTION__ ,
 		      daddr);
 
 		irlan_client_wakeup(self, saddr, daddr);
 	}
+out:

Should the above label instead be as follows?

IRDA_ASSERT_LABEL(out:)

Just in case some variant of gcc, sparse, or whatever complains about labels that don't have a corresponding goto (in CONFIG_IRDA_DEBUG=n builds).

Quoted 5 lines
net/irda/irlan/irlan_client.c +0 -0
 	rcu_read_unlock();
 }
 
#2 lore raw

Hi Paul, hi Josh,

Quoted 10 lines · Paul E. McKenney
Quoted 5 lines · Josh Triplett

irlan_client_discovery_indication calls rcu_read_lock and rcu_read_unlock, but
returns without unlocking in an error case. Fix that by replacing the return
with a goto so that the rcu_read_unlock always gets executed.

Good catch!!! Looks good from an RCU viewpoint, in fact, looks absolutely necessary to permit IRDA to work in debug mode, particularly in either a CONFIG_PREEMPT or a -rt kernel.

Indeed, nice catch.

Quoted 1 line

One question below, but up to the maintainer. ;-)

Yes, definitely, IRDA_ASSERT_LABEL(out:) makes sense. I will forward the patch to davem's netdev tree, thanks.

Cheers,
Samuel.

Quoted 44 lines

Thanx, Paul

Quoted 16 lines

---

 net/irda/irlan/irlan_client.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

e20ab96944814489277c3bfd4e69133854ab01e9

net/irda/irlan/irlan_client.c +0 -0
index f8e6cb0..5ce7d2e 100644
@@ -173,13 +173,14 @@ void irlan_client_discovery_indication(d
 	rcu_read_lock();
 	self = irlan_get_any();

net/irda/irlan/irlan_client.c void irlan_client_discovery_indication(d · line 183

Quoted 10 lines
net/irda/irlan/irlan_client.c +2 -1
 	if (self) {
-		IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
+		IRDA_ASSERT(self->magic == IRLAN_MAGIC, goto out;);
 
 		IRDA_DEBUG(1, "%s(), Found instance (%08x)!\n", __FUNCTION__ ,
 		      daddr);
 
 		irlan_client_wakeup(self, saddr, daddr);
 	}
+out:

Should the above label instead be as follows?

IRDA_ASSERT_LABEL(out:)

Just in case some variant of gcc, sparse, or whatever complains about labels that don't have a corresponding goto (in CONFIG_IRDA_DEBUG=n builds).

Quoted 5 lines
net/irda/irlan/irlan_client.c +0 -0
 	rcu_read_unlock();
 }
 
#3 lore raw

PATCH 1/2 Fix RCU lock pairing on error path

In reply to Paul E. McKenney

Hi Dave,

irlan_client_discovery_indication calls rcu_read_lock and rcu_read_unlock, but returns without unlocking in an error case. Fix that by replacing the return with a goto so that the rcu_read_unlock always gets executed.

---
 net/irda/irlan/irlan_client.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
net/irda/irlan/irlan_client.c +2 -1
index f8e6cb0..95cf123 100644
@@ -173,13 +173,14 @@ void irlan_client_discovery_indication(d
 	rcu_read_lock();
 	self = irlan_get_any();
 	if (self) {
-		IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
+		IRDA_ASSERT(self->magic == IRLAN_MAGIC, goto out;);
 
 		IRDA_DEBUG(1, "%s(), Found instance (%08x)!\n", __FUNCTION__ ,
 		      daddr);
 		
 		irlan_client_wakeup(self, saddr, daddr);
 	}
+IRDA_ASSERT_LABEL(out:)
 	rcu_read_unlock();
 }
 	
Signature · 1 line
1.4.0
maintainer Applied
#4 lore raw

Re: [PATCH 1/2] [IrDA] Fix RCU lock pairing on error path

From: Samuel Ortiz <[email protected]>
Date: Fri, 30 Jun 2006 09:55:34 +0300

Quoted 7 lines

irlan_client_discovery_indication calls rcu_read_lock and rcu_read_unlock, but returns without unlocking in an error case. Fix that by replacing the return with a goto so that the rcu_read_unlock always gets executed.

Applied, thanks.

Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642