[PATCH net-next v3] virtio_net: check virtqueue_add_sgs() return value

Subsystems: networking drivers, the rest, virtio net driver

STALE1878d

2 messages, 2 authors, 2021-07-10 · open the first message on its own page

[PATCH net-next v3] virtio_net: check virtqueue_add_sgs() return value

From: wangyunjian <hidden>
Date: 2021-07-10 03:32:56

From: Yunjian Wang <redacted>

As virtqueue_add_sgs() can fail, we should check the return value.

Addresses-Coverity-ID: 1464439 ("Unchecked return value")
Signed-off-by: Yunjian Wang <redacted>
---
v3:
  fix log message
v2:
  add warn log and remove fix tag
---
 drivers/net/virtio_net.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index b0b81458ca94..13952e2dba5e 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -1743,6 +1743,7 @@ static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
 {
 	struct scatterlist *sgs[4], hdr, stat;
 	unsigned out_num = 0, tmp;
+	int ret;
 
 	/* Caller should know better */
 	BUG_ON(!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ));
@@ -1762,7 +1763,12 @@ static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
 	sgs[out_num] = &stat;
 
 	BUG_ON(out_num + 1 > ARRAY_SIZE(sgs));
-	virtqueue_add_sgs(vi->cvq, sgs, out_num, 1, vi, GFP_ATOMIC);
+	ret = virtqueue_add_sgs(vi->cvq, sgs, out_num, 1, vi, GFP_ATOMIC);
+	if (ret < 0) {
+		dev_warn(&vi->vdev->dev,
+			 "Failed to add sgs for command vq: %d\n.", ret);
+		return false;
+	}
 
 	if (unlikely(!virtqueue_kick(vi->cvq)))
 		return vi->ctrl->status == VIRTIO_NET_OK;
-- 
2.23.0

Re: [PATCH net-next v3] virtio_net: check virtqueue_add_sgs() return value

From: patchwork-bot+netdevbpf@kernel.org
Date: 2021-07-10 18:40:41

Hello:

This patch was applied to netdev/net.git (refs/heads/master):

On Sat, 10 Jul 2021 11:32:49 +0800 you wrote:
From: Yunjian Wang <redacted>

As virtqueue_add_sgs() can fail, we should check the return value.

Addresses-Coverity-ID: 1464439 ("Unchecked return value")
Signed-off-by: Yunjian Wang <redacted>

[...]
Here is the summary with links:
  - [net-next,v3] virtio_net: check virtqueue_add_sgs() return value
    https://git.kernel.org/netdev/net/c/222722bc6ebf

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help