From: "Michael S. Tsirkin" <mst@redhat.com>
To: wangyunjian <wangyunjian@huawei.com>
Cc: kuba@kernel.org, davem@davemloft.net, netdev@vger.kernel.org,
jasowang@redhat.com, dingxiaoxiong@huawei.com
Subject: Re: [PATCH net-next] virtio_net: check virtqueue_add_sgs() return value
Date: Fri, 9 Jul 2021 07:17:48 -0400 [thread overview]
Message-ID: <20210709071626-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <1625826091-42668-1-git-send-email-wangyunjian@huawei.com>
On Fri, Jul 09, 2021 at 06:21:31PM +0800, wangyunjian wrote:
> From: Yunjian Wang <wangyunjian@huawei.com>
>
> As virtqueue_add_sgs() can fail, we should check the return value.
>
> Addresses-Coverity-ID: 1464439 ("Unchecked return value")
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> ---
> 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..30a0ca2fef1a 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 vq: %d\n.", ret);
That's not too clear. Pls make it clear that it's the command vq
that failed.
> + return false;
> + }
>
> if (unlikely(!virtqueue_kick(vi->cvq)))
> return vi->ctrl->status == VIRTIO_NET_OK;
> --
> 2.23.0
prev parent reply other threads:[~2021-07-09 11:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-09 10:21 [PATCH net-next] virtio_net: check virtqueue_add_sgs() return value wangyunjian
2021-07-09 11:17 ` Michael S. Tsirkin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210709071626-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=davem@davemloft.net \
--cc=dingxiaoxiong@huawei.com \
--cc=jasowang@redhat.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=wangyunjian@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).