From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43043) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSGKQ-0002b9-JD for qemu-devel@nongnu.org; Wed, 27 Jul 2016 00:20:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bSGKM-0003LX-8H for qemu-devel@nongnu.org; Wed, 27 Jul 2016 00:20:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35450) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSGKM-0003LC-2E for qemu-devel@nongnu.org; Wed, 27 Jul 2016 00:20:14 -0400 Date: Wed, 27 Jul 2016 07:20:08 +0300 From: "Michael S. Tsirkin" Message-ID: <20160727072002-mutt-send-email-mst@kernel.org> References: <1469447015-2276-1-git-send-email-shmulik.ladkani@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1469447015-2276-1-git-send-email-shmulik.ladkani@oracle.com> Subject: Re: [Qemu-devel] [PATCH] util: Relax assertion in iov_copy() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Shmulik Ladkani Cc: qemu-devel@nongnu.org, Dmitry Fleytman , Paolo Bonzini , Jason Wang , Shmulik Ladkani On Mon, Jul 25, 2016 at 02:43:35PM +0300, Shmulik Ladkani wrote: > From: Shmulik Ladkani > > In cases where iov_copy() is passed with zero 'bytes' argument and a > non-zero 'offset' argument, nothing gets copied - as expected. > > However since no copy iterations are performed, 'offset' is left > unaltered, leading to the final assert(offset == 0) to fail. > > Relax the assertion: if j (number of dst elements assigned) is zero, no > need to err. > > Only if j!=0 (some dst elements assigned) AND offset!=0 we should err. > > Signed-off-by: Shmulik Ladkani Reviewed-by: Michael S. Tsirkin > --- > util/iov.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > Flow that led to the assertion was: > net_tx_pkt_rebuild_payload() > iov_copy(... , pkt->payload_len) > > where pkt->payload_len was correctly calculated to be 0 (a packet > carrying just ipv4 header, without any payload). > > An alternative is to place the below code, early in iov_copy(): > if (!bytes) > return 0; > > diff --git a/util/iov.c b/util/iov.c > index 003fcce..17de52d 100644 > --- a/util/iov.c > +++ b/util/iov.c > @@ -260,7 +260,7 @@ unsigned iov_copy(struct iovec *dst_iov, unsigned int dst_iov_cnt, > bytes -= len; > offset = 0; > } > - assert(offset == 0); > + assert(j == 0 || offset == 0); > return j; > } > > -- > 1.9.1 >