2013-12-14 04:43:57

by Wei Yongjun

[permalink] [raw]
Subject: [PATCH -next] Bluetooth: fix return value check

From: Wei Yongjun <[email protected]>

In case of error, the function bt_skb_alloc() returns NULL pointer
not ERR_PTR(). The IS_ERR() test in the return value check should
be replaced with NULL test.

Signed-off-by: Wei Yongjun <[email protected]>
---
net/bluetooth/6lowpan.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
index 37239db..fb38c78 100644
--- a/net/bluetooth/6lowpan.c
+++ b/net/bluetooth/6lowpan.c
@@ -337,8 +337,8 @@ static inline int skbuff_copy(void *msg, int len, int count, int mtu,
count = min_t(unsigned int, mtu, len);

tmp = bt_skb_alloc(count, GFP_ATOMIC);
- if (IS_ERR(tmp))
- return PTR_ERR(tmp);
+ if (!tmp)
+ return PTR_ERR(-ENOMEM);

*frag = tmp;

@@ -384,8 +384,8 @@ static struct sk_buff *create_pdu(struct l2cap_conn *conn, void *msg,
BT_DBG("conn %p len %zu mtu %d count %d", conn, len, conn->mtu, count);

skb = bt_skb_alloc(count + L2CAP_HDR_SIZE, GFP_ATOMIC);
- if (IS_ERR(skb))
- return skb;
+ if (!skb)
+ return ERR_PTR(-ENOMEM);

skb->priority = priority;



2013-12-14 09:49:05

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH -next] Bluetooth: fix return value check

Hi Wei,

> In case of error, the function bt_skb_alloc() returns NULL pointer
> not ERR_PTR(). The IS_ERR() test in the return value check should
> be replaced with NULL test.
>
> Signed-off-by: Wei Yongjun <[email protected]>
> ---
> net/bluetooth/6lowpan.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
> index 37239db..fb38c78 100644
> --- a/net/bluetooth/6lowpan.c
> +++ b/net/bluetooth/6lowpan.c
> @@ -337,8 +337,8 @@ static inline int skbuff_copy(void *msg, int len, int count, int mtu,
> count = min_t(unsigned int, mtu, len);
>
> tmp = bt_skb_alloc(count, GFP_ATOMIC);
> - if (IS_ERR(tmp))
> - return PTR_ERR(tmp);
> + if (!tmp)
> + return PTR_ERR(-ENOMEM);
>
> *frag = tmp;

net/bluetooth/6lowpan.c: In function ?skbuff_copy?:
net/bluetooth/6lowpan.c:340:4: warning: passing argument 1 of ?PTR_ERR? makes pointer from integer without a cast [enabled by default]
return PTR_ERR(-ENOMEM);
^
In file included from /data/kernel/bluetooth-next/arch/x86/include/asm/processor.h:31:0,
from /data/kernel/bluetooth-next/arch/x86/include/asm/thread_info.h:22,
from include/linux/thread_info.h:54,
from /data/kernel/bluetooth-next/arch/x86/include/asm/preempt.h:6,
from include/linux/preempt.h:18,
from include/linux/spinlock.h:50,
from include/linux/mm_types.h:8,
from include/linux/kmemcheck.h:4,
from include/linux/skbuff.h:18,
from include/linux/if_arp.h:26,
from net/bluetooth/6lowpan.c:14:
include/linux/err.h:27:127: note: expected ?const void *? but argument is of type ?int?
static inline long __must_check PTR_ERR(__force const void *ptr)

Have you actually compiled your code?

>
> @@ -384,8 +384,8 @@ static struct sk_buff *create_pdu(struct l2cap_conn *conn, void *msg,
> BT_DBG("conn %p len %zu mtu %d count %d", conn, len, conn->mtu, count);
>
> skb = bt_skb_alloc(count + L2CAP_HDR_SIZE, GFP_ATOMIC);
> - if (IS_ERR(skb))
> - return skb;
> + if (!skb)
> + return ERR_PTR(-ENOMEM);
>
> skb->priority = priority;

Regards

Marcel