Received: from eggs.gnu.org ([208.118.235.92]:43718) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S8eqr-0002FJ-6d for qemu-devel@nongnu.org; Fri, 16 Mar 2012 17:38:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S8eqp-0005DG-BG for qemu-devel@nongnu.org; Fri, 16 Mar 2012 17:38:20 -0400 Received: from isrv.corpit.ru ([86.62.121.231]:37487) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S8eqp-0005Cw-3B for qemu-devel@nongnu.org; Fri, 16 Mar 2012 17:38:19 -0400 From: Michael Tokarev Date: Sat, 17 Mar 2012 01:34:27 +0400 Message-Id: <1331933677-29628-2-git-send-email-mjt@msgid.tls.msk.ru> In-Reply-To: <1331933677-29628-1-git-send-email-mjt@msgid.tls.msk.ru> References: <1331933677-29628-1-git-send-email-mjt@msgid.tls.msk.ru> Subject: [Qemu-devel] [PATCHv5 01/11] virtio-serial-bus: use correct lengths in control_out() message List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori , qemu-devel@nongnu.org Cc: Paolo Bonzini , Michael Tokarev Original code has one thing to process (cur_len), requests to convert from iovec to buf another thing (len which is actually max_len), and processes something else (copied). Whole thing is very difficult to understand, even if it does a right thing. The iov_to_buf() conversion in this case will always return cur_len, because it is the length of the iovec it was asked to process, and the size we asked to convert is the same or larger, and iov_to_buf() will stop at reaching either iov or buf. Make the code saner by doing the only sane thing: dropping `copied' which is always the same as `cur_len' but just introduces questions. Signed-off-by: Michael Tokarev --- hw/virtio-serial-bus.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c index e22940e..abe48ec 100644 --- a/hw/virtio-serial-bus.c +++ b/hw/virtio-serial-bus.c @@ -454,7 +454,7 @@ static void control_out(VirtIODevice *vdev, VirtQueue *vq) len = 0; buf = NULL; while (virtqueue_pop(vq, &elem)) { - size_t cur_len, copied; + size_t cur_len; cur_len = iov_size(elem.out_sg, elem.out_num); /* @@ -467,9 +467,9 @@ static void control_out(VirtIODevice *vdev, VirtQueue *vq) buf = g_malloc(cur_len); len = cur_len; } - copied = iov_to_buf(elem.out_sg, elem.out_num, buf, 0, len); + iov_to_buf(elem.out_sg, elem.out_num, buf, 0, cur_len); - handle_control_message(vser, buf, copied); + handle_control_message(vser, buf, cur_len); virtqueue_push(vq, &elem, 0); } g_free(buf); -- 1.7.9.1