Skip to content

Commit 222722b

Browse files
wyjwangdavem330
authored andcommitted
virtio_net: check virtqueue_add_sgs() return value
As virtqueue_add_sgs() can fail, we should check the return value. Addresses-Coverity-ID: 1464439 ("Unchecked return value") Signed-off-by: Yunjian Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 849fd44 commit 222722b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

drivers/net/virtio_net.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1743,6 +1743,7 @@ static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
17431743
{
17441744
struct scatterlist *sgs[4], hdr, stat;
17451745
unsigned out_num = 0, tmp;
1746+
int ret;
17461747

17471748
/* Caller should know better */
17481749
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,
17621763
sgs[out_num] = &stat;
17631764

17641765
BUG_ON(out_num + 1 > ARRAY_SIZE(sgs));
1765-
virtqueue_add_sgs(vi->cvq, sgs, out_num, 1, vi, GFP_ATOMIC);
1766+
ret = virtqueue_add_sgs(vi->cvq, sgs, out_num, 1, vi, GFP_ATOMIC);
1767+
if (ret < 0) {
1768+
dev_warn(&vi->vdev->dev,
1769+
"Failed to add sgs for command vq: %d\n.", ret);
1770+
return false;
1771+
}
17661772

17671773
if (unlikely(!virtqueue_kick(vi->cvq)))
17681774
return vi->ctrl->status == VIRTIO_NET_OK;

0 commit comments

Comments
 (0)