Skip to contentSkip to conversation

rxrpc: recvmsg: use BUG_ON instead of if condition followed by BUG

PATCH In review Gustavo A. R. Silva 2 participants 3 messages Oct 24, 2017 – Oct 25, 2017

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

PATCH 1/1 rxrpc: recvmsg: use BUG_ON instead of if condition followed by BUG

Use BUG_ON instead of if condition followed by BUG.

This issue was detected with the help of Coccinelle.

---
 net/rxrpc/recvmsg.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
net/rxrpc/recvmsg.c +2 -4
index bdece21..9598b92 100644
@@ -243,8 +243,7 @@ static int rxrpc_verify_packet(struct rxrpc_call *call, struct sk_buff *skb,
 	 */
 	if ((annotation & RXRPC_RX_ANNO_JUMBO) > 1) {
 		__be16 tmp;
-		if (skb_copy_bits(skb, offset - 2, &tmp, 2) < 0)
-			BUG();
+		BUG_ON(skb_copy_bits(skb, offset - 2, &tmp, 2) < 0);
 		cksum = ntohs(tmp);
 		seq += (annotation & RXRPC_RX_ANNO_JUMBO) - 1;
 	}
@@ -503,8 +502,7 @@ int rxrpc_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
 
 	release_sock(&rx->sk);
 
-	if (test_bit(RXRPC_CALL_RELEASED, &call->flags))
-		BUG();
+	BUG_ON(test_bit(RXRPC_CALL_RELEASED, &call->flags));
 
 	if (test_bit(RXRPC_CALL_HAS_USERID, &call->flags)) {
 		if (flags & MSG_CMSG_COMPAT) {
Signature · 1 line
2.7.4
#1 lore raw

Please combine these related patches fixing BUG in rxrpc into a patch set with proper annotation,

Also, can any of these BUG_ONs be replaced by WARN_ONs? Warnings are generally preferable to crashing the system.

Tom

Quoted 36 lines · Gustavo A. R. Silva

Use BUG_ON instead of if condition followed by BUG.

This issue was detected with the help of Coccinelle.

---
 net/rxrpc/recvmsg.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
net/rxrpc/recvmsg.c +2 -5
index bdece21..9598b92 100644
@@ -243,8 +243,7 @@ static int rxrpc_verify_packet(struct rxrpc_call *call, struct sk_buff *skb,
         */
        if ((annotation & RXRPC_RX_ANNO_JUMBO) > 1) {
                __be16 tmp;
-               if (skb_copy_bits(skb, offset - 2, &tmp, 2) < 0)
-                       BUG();
+               BUG_ON(skb_copy_bits(skb, offset - 2, &tmp, 2) < 0);
                cksum = ntohs(tmp);
                seq += (annotation & RXRPC_RX_ANNO_JUMBO) - 1;
        }
@@ -503,8 +502,7 @@ int rxrpc_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
 
        release_sock(&rx->sk);
 
-       if (test_bit(RXRPC_CALL_RELEASED, &call->flags))
-               BUG();
+       BUG_ON(test_bit(RXRPC_CALL_RELEASED, &call->flags));
 
        if (test_bit(RXRPC_CALL_HAS_USERID, &call->flags)) {
                if (flags & MSG_CMSG_COMPAT) {
--

2.7.4

#2 lore raw

Hi Tom,

Quoting Tom Herbert <[email protected]>:

Quoted 3 lines

Please combine these related patches fixing BUG in rxrpc into a patch set with proper annotation,

I can do that.

Quoted 3 lines

Also, can any of these BUG_ONs be replaced by WARN_ONs? Warnings are generally preferable to crashing the system.

What about WARN_ON_ONCE instead?

Thanks
--
Gustavo A. R. Silva

Quoted 43 lines

Tom

Quoted 38 lines · Gustavo A. R. Silva

Use BUG_ON instead of if condition followed by BUG.

This issue was detected with the help of Coccinelle.

---
 net/rxrpc/recvmsg.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
net/rxrpc/recvmsg.c +1 -2
index bdece21..9598b92 100644
@@ -243,8 +243,7 @@ static int rxrpc_verify_packet(struct  
 rxrpc_call *call, struct sk_buff *skb,
         */
        if ((annotation & RXRPC_RX_ANNO_JUMBO) > 1) {
                __be16 tmp;
-               if (skb_copy_bits(skb, offset - 2, &tmp, 2) < 0)
-                       BUG();
+               BUG_ON(skb_copy_bits(skb, offset - 2, &tmp, 2) < 0);
                cksum = ntohs(tmp);
                seq += (annotation & RXRPC_RX_ANNO_JUMBO) - 1;
        }
net/rxrpc/recvmsg.c +1 -2
@@ -503,8 +502,7 @@ int rxrpc_recvmsg(struct socket *sock, struct  
 msghdr *msg, size_t len,
 
        release_sock(&rx->sk);
 
-       if (test_bit(RXRPC_CALL_RELEASED, &call->flags))
-               BUG();
+       BUG_ON(test_bit(RXRPC_CALL_RELEASED, &call->flags));
 
        if (test_bit(RXRPC_CALL_HAS_USERID, &call->flags)) {
                if (flags & MSG_CMSG_COMPAT) {

--
2.7.4