From: Ingo Oeser <ioe-lkml@rameria.de>
To: Mark McLoughlin <markmc@redhat.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>,
virtualization@lists.linux-foundation.org,
linux-kernel@vger.kernel.org, Avi Kivity <avi@redhat.com>
Subject: Re: [PATCH 2/3] virtio: indirect ring entries (VIRTIO_RING_F_INDIRECT_DESC)
Date: Sat, 20 Dec 2008 12:38:06 +0100 [thread overview]
Message-ID: <200812201238.07510.ioe-lkml@rameria.de> (raw)
In-Reply-To: <1229620222-22216-3-git-send-email-markmc@redhat.com>
Hi Mark,
On Thursday 18 December 2008, Mark McLoughlin wrote:
> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> index 5777196..2330c4b 100644
> --- a/drivers/virtio/virtio_ring.c
> +++ b/drivers/virtio/virtio_ring.c
> @@ -70,6 +73,55 @@ struct vring_virtqueue
>
> #define to_vvq(_vq) container_of(_vq, struct vring_virtqueue, vq)
>
> +/* Set up an indirect table of descriptors and add it to the queue. */
> +static int vring_add_indirect(struct vring_virtqueue *vq,
> + struct scatterlist sg[],
> + unsigned int out,
> + unsigned int in)
> +{
> + struct vring_desc *desc;
> + unsigned head;
> + int i;
> +
> + desc = kmalloc((out + in) * sizeof(struct vring_desc), GFP_ATOMIC);
kmalloc() returns ZERO_SIZE_PTR, if (out + in) == 0
> + if (!desc)
> + return vq->vring.num;
> +
> + /* Transfer entries from the sg list into the indirect page */
> + for (i = 0; i < out; i++) {
> + desc[i].flags = VRING_DESC_F_NEXT;
> + desc[i].addr = sg_phys(sg);
> + desc[i].len = sg->length;
> + desc[i].next = i+1;
> + sg++;
> + }
> + for (; i < (out + in); i++) {
> + desc[i].flags = VRING_DESC_F_NEXT|VRING_DESC_F_WRITE;
> + desc[i].addr = sg_phys(sg);
> + desc[i].len = sg->length;
> + desc[i].next = i+1;
> + sg++;
> + }
> +
> + /* Last one doesn't continue. */
> + desc[i-1].flags &= ~VRING_DESC_F_NEXT;
> + desc[i-1].next = 0;
So this array index can fail (be -1).
Please check and avoid within this function.
Best Regards
Ingo Oeser
next prev parent reply other threads:[~2008-12-20 11:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-18 17:10 [PATCH 0/3] virtio: indirect ring entries Mark McLoughlin
2008-12-18 17:10 ` [PATCH 1/3] virtio: teach virtio_has_feature() about transport features Mark McLoughlin
2008-12-18 17:10 ` [PATCH 2/3] virtio: indirect ring entries (VIRTIO_RING_F_INDIRECT_DESC) Mark McLoughlin
2008-12-18 17:10 ` [PATCH 3/3] lguest: add support for indirect ring entries Mark McLoughlin
2008-12-20 11:38 ` Ingo Oeser [this message]
2008-12-22 10:17 ` [PATCH 2/3] virtio: indirect ring entries (VIRTIO_RING_F_INDIRECT_DESC) Mark McLoughlin
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=200812201238.07510.ioe-lkml@rameria.de \
--to=ioe-lkml@rameria.de \
--cc=avi@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=markmc@redhat.com \
--cc=rusty@rustcorp.com.au \
--cc=virtualization@lists.linux-foundation.org \
/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
Powered by JetHome