Skip to contentSkip to conversation

Bluetooth: fix ->alloc_skb() error checking

PATCH In review Dan Carpenter 3 participants 3 messages Dec 16, 2013 1 message not in the archive

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

PATCH 1/1 Bluetooth: fix ->alloc_skb() error checking

There are two functions that implement ->alloc_skb().

a2mp_cahan_alloc_skb_cb() returns NULL.
l2cap_sock_alloc_skb_cb() returns an ERR_PTR.

The callers all check for ERR_PTRs and don't check for NULL. On the other hand bt_skb_alloc() and the core net alloc_skb() return NULL so returning an error pointer is inconsistent. This confusion between some alloc_skb() functions returning ERR_PTR and some returning NULL has been a source of bugs such as 787949039fcd ('Bluetooth: fix return value check'). This patch makes ->alloc_skb() return NULL and changes the callers to match.

net/bluetooth/l2cap_core.c +10 -10
index b0ad2c752d73..84c3ce04cb35 100644
@@ -2341,8 +2341,8 @@ static inline int l2cap_skbuff_fromiovec(struct l2cap_chan *chan,
 
 		tmp = chan->ops->alloc_skb(chan, count,
 					   msg->msg_flags & MSG_DONTWAIT);
-		if (IS_ERR(tmp))
-			return PTR_ERR(tmp);
+		if (!tmp)
+			return -ENOMEM;
 
 		*frag = tmp;
 
@@ -2379,8 +2379,8 @@ static struct sk_buff *l2cap_create_connless_pdu(struct l2cap_chan *chan,
 
 	skb = chan->ops->alloc_skb(chan, count + hlen,
 				   msg->msg_flags & MSG_DONTWAIT);
-	if (IS_ERR(skb))
-		return skb;
+	if (!skb)
+		return ERR_PTR(-ENOMEM);
 
 	skb->priority = priority;
 
@@ -2413,8 +2413,8 @@ static struct sk_buff *l2cap_create_basic_pdu(struct l2cap_chan *chan,
 
 	skb = chan->ops->alloc_skb(chan, count + L2CAP_HDR_SIZE,
 				   msg->msg_flags & MSG_DONTWAIT);
-	if (IS_ERR(skb))
-		return skb;
+	if (skb)
+		return ERR_PTR(-ENOMEM);
 
 	skb->priority = priority;
 
@@ -2457,8 +2457,8 @@ static struct sk_buff *l2cap_create_iframe_pdu(struct l2cap_chan *chan,
 
 	skb = chan->ops->alloc_skb(chan, count + hlen,
 				   msg->msg_flags & MSG_DONTWAIT);
-	if (IS_ERR(skb))
-		return skb;
+	if (!skb)
+		return ERR_PTR(-ENOMEM);
 
 	/* Create L2CAP header */
 	lh = (struct l2cap_hdr *) skb_put(skb, L2CAP_HDR_SIZE);
@@ -2578,8 +2578,8 @@ static struct sk_buff *l2cap_create_le_flowctl_pdu(struct l2cap_chan *chan,
 
 	skb = chan->ops->alloc_skb(chan, count + hlen,
 				   msg->msg_flags & MSG_DONTWAIT);
-	if (IS_ERR(skb))
-		return skb;
+	if (!skb)
+		return ERR_PTR(-ENOMEM);
 
 	/* Create L2CAP header */
 	lh = (struct l2cap_hdr *) skb_put(skb, L2CAP_HDR_SIZE);

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

Hi Dan,

net/bluetooth/l2cap_core.c static struct sk_buff *l2cap_create_basic_pdu(struct l2cap_chan *chan, · line 2417

Quoted 8 lines · Dan Carpenter
net/bluetooth/l2cap_core.c +2 -2
@@ -2413,8 +2413,8 @@ static struct sk_buff *l2cap_create_basic_pdu(struct l2cap_chan *chan,
 
        skb = chan->ops->alloc_skb(chan, count + L2CAP_HDR_SIZE,
                                   msg->msg_flags & MSG_DONTWAIT);
-       if (IS_ERR(skb))
-               return skb;
+       if (skb)
+               return ERR_PTR(-ENOMEM);

It should be "!skb" above right?

Review static struct sk_buff *l2cap_create_basic_pdu(struct l2cap_chan *chan, · line 2419

Quoted 3 lines
(quoted diff) +0 -0
        skb->priority = priority;
 

Best Regards,

Signature · 3 lines
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil
#3 lore raw
Quoted 5 lines · Anderson Lizardo

Hi Dan,

Quoted 2 lines · Dan Carpenter
(quoted diff) +0 -0
@@ -2413,8 +2413,8 @@ static struct sk_buff *l2cap_create_basic_pdu(struct l2cap_chan *chan,
 
Quoted 9 lines

net/bluetooth/l2cap_core.c static struct sk_buff *l2cap_create_basic_pdu(struct l2cap_chan *chan, · line 2417

Quoted 6 lines
net/bluetooth/l2cap_core.c +2 -2
        skb = chan->ops->alloc_skb(chan, count + L2CAP_HDR_SIZE,
                                   msg->msg_flags & MSG_DONTWAIT);
-       if (IS_ERR(skb))
-               return skb;
+       if (skb)
+               return ERR_PTR(-ENOMEM);

It should be "!skb" above right?

Gar.... I'm so sorry about that.

regards,
dan carpenter