Skip to contentSkip to conversation

bluetooth: fix error cases

PATCH In review Johannes Berg 3 participants 3 messages Jun 1, 2011

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

PATCH 1/1 bluetooth: fix error cases

From: Johannes Berg <[email protected]>

The error cases in a few functions can use a
socket variable that was never initialised,
gcc correctly warns about this:
net/bluetooth/l2cap_core.c: In function ‘l2cap_recv_frame’:
include/linux/spinlock.h:325:19: warning: ‘sk’ may be used uninitialized in this function [-Wuninitialized] net/bluetooth/l2cap_core.c:3789:15: note: ‘sk’ was declared here include/linux/spinlock.h:325:19: warning: ‘sk’ may be used uninitialized in this function [-Wuninitialized] net/bluetooth/l2cap_core.c:3756:15: note: ‘sk’ was declared here

Initialise the socket to NULL as clearly intended
by the error handling code.

Also fix a "set but not used" warning.

---
 net/bluetooth/l2cap_core.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
net/bluetooth/l2cap_core.c +2 -4
@@ -3667,7 +3667,6 @@ static inline int l2cap_data_channel(str
 {
 	struct l2cap_chan *chan;
 	struct sock *sk = NULL;
-	struct l2cap_pinfo *pi;
 	u16 control;
 	u8 tx_seq;
 	int len;
@@ -3679,7 +3678,6 @@ static inline int l2cap_data_channel(str
 	}
 
 	sk = chan->sk;
-	pi = l2cap_pi(sk);
 
 	BT_DBG("chan %p, len %d", chan, skb->len);
 
@@ -3755,7 +3753,7 @@ done:
 
 static inline int l2cap_conless_channel(struct l2cap_conn *conn, __le16 psm, struct sk_buff *skb)
 {
-	struct sock *sk;
+	struct sock *sk = NULL;
 	struct l2cap_chan *chan;
 
 	chan = l2cap_global_chan_by_psm(0, psm, conn->src);
@@ -3788,7 +3786,7 @@ done:
 
 static inline int l2cap_att_channel(struct l2cap_conn *conn, __le16 cid, struct sk_buff *skb)
 {
-	struct sock *sk;
+	struct sock *sk = NULL;
 	struct l2cap_chan *chan;
 
 	chan = l2cap_global_chan_by_scid(0, cid, conn->src);
#1 lore raw
Quoted 11 lines · Johannes Berg

From: Johannes Berg <[email protected]>

The error cases in a few functions can use a
socket variable that was never initialised,
gcc correctly warns about this:
net/bluetooth/l2cap_core.c: In function ‘l2cap_recv_frame’:
include/linux/spinlock.h:325:19: warning: ‘sk’ may be used uninitialized in this function [-Wuninitialized] net/bluetooth/l2cap_core.c:3789:15: note: ‘sk’ was declared here include/linux/spinlock.h:325:19: warning: ‘sk’ may be used uninitialized in this function [-Wuninitialized] net/bluetooth/l2cap_core.c:3756:15: note: ‘sk’ was declared here

Quoted 6 lines

Initialise the socket to NULL as clearly intended
by the error handling code.

Also fix a "set but not used" warning.

Dave fixed part of these a couple of weeks ago:

commit 6dcae1eaee2b437536b2fe928a609f9589691ebf

Author: David S. Miller <[email protected]>
Date:   Mon May 16 23:09:26 2011 -0400

bluetooth: Fix warnings in l2cap_core.c

net/bluetooth/l2cap_core.c: In function ‘l2cap_recv_frame’:
net/bluetooth/l2cap_core.c:3758:15: warning: ‘sk’ may be used uninitialized net/bluetooth/l2cap_core.c:3758:15: note: ‘sk’ was declared here net/bluetooth/l2cap_core.c:3791:15: warning: ‘sk’ may be used uninitialized net/bluetooth/l2cap_core.c:3791:15: note: ‘sk’ was declared here

The "set but not used" bit still applies...

Signature · 2 lines
John W. Linville		Someday the world will need a hero, and you
[email protected]			might be all we have.  Be ready.
#2 lore raw
Quoted 33 lines · John W. Linville
Quoted 11 lines · Johannes Berg

From: Johannes Berg <[email protected]>

The error cases in a few functions can use a
socket variable that was never initialised,
gcc correctly warns about this:
net/bluetooth/l2cap_core.c: In function ‘l2cap_recv_frame’:
include/linux/spinlock.h:325:19: warning: ‘sk’ may be used uninitialized in this function [-Wuninitialized] net/bluetooth/l2cap_core.c:3789:15: note: ‘sk’ was declared here include/linux/spinlock.h:325:19: warning: ‘sk’ may be used uninitialized in this function [-Wuninitialized] net/bluetooth/l2cap_core.c:3756:15: note: ‘sk’ was declared here

Quoted 6 lines

Initialise the socket to NULL as clearly intended
by the error handling code.

Also fix a "set but not used" warning.

Dave fixed part of these a couple of weeks ago:

commit 6dcae1eaee2b437536b2fe928a609f9589691ebf

Author: David S. Miller <[email protected]>
Date:   Mon May 16 23:09:26 2011 -0400

bluetooth: Fix warnings in l2cap_core.c

net/bluetooth/l2cap_core.c: In function ‘l2cap_recv_frame’:
net/bluetooth/l2cap_core.c:3758:15: warning: ‘sk’ may be used uninitialized net/bluetooth/l2cap_core.c:3758:15: note: ‘sk’ was declared here net/bluetooth/l2cap_core.c:3791:15: warning: ‘sk’ may be used uninitialized net/bluetooth/l2cap_core.c:3791:15: note: ‘sk’ was declared here

Quoted 3 lines

The "set but not used" bit still applies...

Those are fixed in my -next tree now.

Signature · 2 lines
Gustavo F. Padovan
http://profusion.mobi