From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54585) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHt1I-0001NW-Bp for qemu-devel@nongnu.org; Thu, 14 Aug 2014 07:16:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XHt1D-0006jR-Gj for qemu-devel@nongnu.org; Thu, 14 Aug 2014 07:16:36 -0400 Date: Thu, 14 Aug 2014 13:16:43 +0200 From: "Michael S. Tsirkin" Message-ID: <20140814111643.GA31742@redhat.com> References: <1408001361-13580-1-git-send-email-zhang.zhanghailiang@huawei.com> <1408001361-13580-4-git-send-email-zhang.zhanghailiang@huawei.com> <20140814103718.GJ31346@redhat.com> <53EC91DA.2080406@msgid.tls.msk.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <53EC91DA.2080406@msgid.tls.msk.ru> Subject: Re: [Qemu-devel] [PATCH v6 03/10] virtio-blk: fix reference a pointer which might be freed List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Michael Tokarev Cc: kwolf@redhat.com, lkurusa@redhat.com, zhanghailiang , qemu-trivial@nongnu.org, jan.kiszka@siemens.com, riku.voipio@iki.fi, luonengjun@huawei.com, qemu-devel@nongnu.org, lcapitulino@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, peter.huangpeng@huawei.com, alex.bennee@linaro.org, rth@twiddle.net On Thu, Aug 14, 2014 at 02:39:22PM +0400, Michael Tokarev wrote: > 14.08.2014 14:37, Michael S. Tsirkin wrote: > > On Thu, Aug 14, 2014 at 03:29:14PM +0800, zhanghailiang wrote: > >> In function virtio_blk_handle_request, it may freed memory pointed by req, > >> So do not access member of req after calling this function. > >> > >> Reviewed-by: Stefan Hajnoczi > >> Signed-off-by: zhanghailiang > > > > Reviewed-by: Michael S. Tsirkin > > Just a small nitpick... > > > Stefan want to pick up this one? > > > >> --- > >> hw/block/virtio-blk.c | 5 +++-- > >> 1 file changed, 3 insertions(+), 2 deletions(-) > >> > >> diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c > >> index c241c50..54a853a 100644 > >> --- a/hw/block/virtio-blk.c > >> +++ b/hw/block/virtio-blk.c > >> @@ -458,7 +458,7 @@ static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq) > >> static void virtio_blk_dma_restart_bh(void *opaque) > >> { > >> VirtIOBlock *s = opaque; > >> - VirtIOBlockReq *req = s->rq; > >> + VirtIOBlockReq *req = s->rq, *next = NULL; > > There's no need to initialize next here. > With init like this I for one instinctively start searching below > how this `NULL' is used (which it isn't). > > I'd declare it inside the loop too, since it is a local-to-loop > var, but that doesn't matter much. > > /mjt Good point, I agree. > >> MultiReqBuffer mrb = { > >> .num_writes = 0, > >> }; > >> @@ -469,8 +469,9 @@ static void virtio_blk_dma_restart_bh(void *opaque) > >> s->rq = NULL; > >> > >> while (req) { > >> + next = req->next; > >> virtio_blk_handle_request(req, &mrb); > >> - req = req->next; > >> + req = next; > >> } > >> > >> virtio_submit_multiwrite(s->bs, &mrb); > >> -- > >> 1.7.12.4 > >>