* [patch] Bluetooth: fix ->alloc_skb() error checking
@ 2013-12-16 20:28 Dan Carpenter
[not found] ` <20131216202857.GB19601-mgFCXtclrQlZLf2FXnZxJA@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2013-12-16 20:28 UTC (permalink / raw)
To: Marcel Holtmann
Cc: Gustavo Padovan, Johan Hedberg, David S. Miller,
linux-bluetooth-u79uwXL29TY76Z2rM5mHXA,
netdev-u79uwXL29TY76Z2rM5mHXA,
kernel-janitors-u79uwXL29TY76Z2rM5mHXA
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.
Signed-off-by: Dan Carpenter <dan.carpenter-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index b0ad2c752d73..84c3ce04cb35 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -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);
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [patch] Bluetooth: fix ->alloc_skb() error checking
[not found] ` <20131216202857.GB19601-mgFCXtclrQlZLf2FXnZxJA@public.gmane.org>
@ 2013-12-16 20:35 ` Anderson Lizardo
2013-12-16 20:57 ` Dan Carpenter
0 siblings, 1 reply; 3+ messages in thread
From: Anderson Lizardo @ 2013-12-16 20:35 UTC (permalink / raw)
To: Dan Carpenter
Cc: Marcel Holtmann, Gustavo Padovan, Johan Hedberg, David S. Miller,
BlueZ development, netdev-u79uwXL29TY76Z2rM5mHXA,
kernel-janitors-u79uwXL29TY76Z2rM5mHXA
Hi Dan,
On Mon, Dec 16, 2013 at 4:28 PM, Dan Carpenter <dan.carpenter-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org> wrote:
> @@ -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?
>
> skb->priority = priority;
>
Best Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [patch] Bluetooth: fix ->alloc_skb() error checking
2013-12-16 20:35 ` Anderson Lizardo
@ 2013-12-16 20:57 ` Dan Carpenter
0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2013-12-16 20:57 UTC (permalink / raw)
To: Anderson Lizardo
Cc: Marcel Holtmann, Gustavo Padovan, Johan Hedberg, David S. Miller,
BlueZ development, netdev, kernel-janitors
On Mon, Dec 16, 2013 at 04:35:25PM -0400, Anderson Lizardo wrote:
> Hi Dan,
>
> On Mon, Dec 16, 2013 at 4:28 PM, Dan Carpenter <dan.carpenter@oracle.com> wrote:
> > @@ -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?
>
Gar.... I'm so sorry about that.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-12-16 20:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-16 20:28 [patch] Bluetooth: fix ->alloc_skb() error checking Dan Carpenter
[not found] ` <20131216202857.GB19601-mgFCXtclrQlZLf2FXnZxJA@public.gmane.org>
2013-12-16 20:35 ` Anderson Lizardo
2013-12-16 20:57 ` Dan Carpenter
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).