Skip to contentSkip to conversation

virtio_net: replace if (cond) BUG() with BUG_ON()

PATCH In review Jiapeng Chong 2 participants 2 messages Mar 17, 2021 – Mar 18, 2021

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

PATCH 1/1 virtio_net: replace if (cond) BUG() with BUG_ON()

Fix the following coccicheck warnings:

./drivers/net/virtio_net.c:1551:2-5: WARNING: Use BUG_ON instead of if condition followed by BUG.

---
 drivers/net/virtio_net.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/virtio_net.c +2 -4
index 82e520d..093530b 100644
@@ -1545,10 +1545,8 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb)
 	else
 		hdr = skb_vnet_hdr(skb);
 
-	if (virtio_net_hdr_from_skb(skb, &hdr->hdr,
-				    virtio_is_little_endian(vi->vdev), false,
-				    0))
-		BUG();
+	BUG_ON(virtio_net_hdr_from_skb(skb, &hdr->hdr,  virtio_is_little_endian(vi->vdev),
+				       false, 0));
 
 	if (vi->mergeable_rx_bufs)
 		hdr->num_buffers = 0;
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 16 lines · Jiapeng Chong

Fix the following coccicheck warnings:

./drivers/net/virtio_net.c:1551:2-5: WARNING: Use BUG_ON instead of if condition followed by BUG.

---
 drivers/net/virtio_net.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/virtio_net.c +0 -0
index 82e520d..093530b 100644

drivers/net/virtio_net.c static int xmit_skb(struct send_queue *sq, struct sk_buff *skb) · line 1549

Quoted 9 lines
drivers/net/virtio_net.c +2 -4
@@ -1545,10 +1545,8 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb)
 	else
 		hdr = skb_vnet_hdr(skb);
 
-	if (virtio_net_hdr_from_skb(skb, &hdr->hdr,
-				    virtio_is_little_endian(vi->vdev), false,
-				    0))
-		BUG();
+	BUG_ON(virtio_net_hdr_from_skb(skb, &hdr->hdr,  virtio_is_little_endian(vi->vdev),
+				       false, 0));

This BUG() in virtio isn't supposed to be in the first place. You should return -EINVAL instead of crashing system.

Thanks

Quoted 6 lines
drivers/net/virtio_net.c +0 -1
 	if (vi->mergeable_rx_bufs)
 		hdr->num_buffers = 0;
--

1.8.3.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization