2021-09-15 23:38:19

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH v4 3/4] Bluetooth: Fix passing NULL to PTR_ERR

From: Luiz Augusto von Dentz <[email protected]>

Passing NULL to PTR_ERR will result in 0 (success), also since the likes of
bt_skb_sendmsg does never return NULL it is safe to replace the instances of
IS_ERR_OR_NULL with IS_ERR when checking its return.

Reported-by: Dan Carpenter <[email protected]>
Signed-off-by: Luiz Augusto von Dentz <[email protected]>
---
include/net/bluetooth/bluetooth.h | 2 +-
net/bluetooth/rfcomm/sock.c | 2 +-
net/bluetooth/sco.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
index aa221c1a27c6..3271870fd85e 100644
--- a/include/net/bluetooth/bluetooth.h
+++ b/include/net/bluetooth/bluetooth.h
@@ -496,7 +496,7 @@ static inline struct sk_buff *bt_skb_sendmmsg(struct sock *sk,
struct sk_buff *tmp;

tmp = bt_skb_sendmsg(sk, msg, len, mtu, headroom, tailroom);
- if (IS_ERR_OR_NULL(tmp)) {
+ if (IS_ERR(tmp)) {
kfree_skb(skb);
return tmp;
}
diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
index 5938af3e9936..4bf4ea6cbb5e 100644
--- a/net/bluetooth/rfcomm/sock.c
+++ b/net/bluetooth/rfcomm/sock.c
@@ -583,7 +583,7 @@ static int rfcomm_sock_sendmsg(struct socket *sock, struct msghdr *msg,

skb = bt_skb_sendmmsg(sk, msg, len, d->mtu, RFCOMM_SKB_HEAD_RESERVE,
RFCOMM_SKB_TAIL_RESERVE);
- if (IS_ERR_OR_NULL(skb))
+ if (IS_ERR(skb))
return PTR_ERR(skb);

sent = rfcomm_dlc_send(d, skb);
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index 446f871f11ed..f51399d1b9cb 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -733,7 +733,7 @@ static int sco_sock_sendmsg(struct socket *sock, struct msghdr *msg,
return -EOPNOTSUPP;

skb = bt_skb_sendmsg(sk, msg, len, len, 0, 0);
- if (IS_ERR_OR_NULL(skb))
+ if (IS_ERR(skb))
return PTR_ERR(skb);

lock_sock(sk);
--
2.31.1


2021-09-16 00:09:10

by Tedd Ho-Jeong An

[permalink] [raw]
Subject: Re: [PATCH v4 3/4] Bluetooth: Fix passing NULL to PTR_ERR

Hi Luiz,

On Wed, 2021-09-15 at 16:35 -0700, Luiz Augusto von Dentz wrote:
> From: Luiz Augusto von Dentz <[email protected]>
>
> Passing NULL to PTR_ERR will result in 0 (success), also since the likes of
> bt_skb_sendmsg does never return NULL it is safe to replace the instances of
> IS_ERR_OR_NULL with IS_ERR when checking its return.
>
> Reported-by: Dan Carpenter <[email protected]>
> Signed-off-by: Luiz Augusto von Dentz <[email protected]>

Tested-by: Tedd Ho-Jeong An <[email protected]>