From patchwork Wed Apr 16 13:09:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 339582 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id DDBA31400B8 for ; Wed, 16 Apr 2014 23:11:53 +1000 (EST) Received: from localhost ([::1]:54565 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WaPd1-0002G8-RG for incoming@patchwork.ozlabs.org; Wed, 16 Apr 2014 09:11:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51909) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WaPad-0005ow-F7 for qemu-devel@nongnu.org; Wed, 16 Apr 2014 09:09:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WaPaW-0007Ar-Vd for qemu-devel@nongnu.org; Wed, 16 Apr 2014 09:09:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:62548) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WaPaW-0007Ad-Mq for qemu-devel@nongnu.org; Wed, 16 Apr 2014 09:09:16 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s3GD9GZU023014 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 16 Apr 2014 09:09:16 -0400 Received: from noname.redhat.com (ovpn-116-41.ams2.redhat.com [10.36.116.41]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s3GD9EUK024125; Wed, 16 Apr 2014 09:09:15 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Wed, 16 Apr 2014 15:09:13 +0200 Message-Id: <1397653753-23237-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH] block: Check bdrv_getlength() return value in bdrv_make_zero() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index d268ece..8510ba2 100644 --- a/block.c +++ b/block.c @@ -2757,10 +2757,16 @@ int bdrv_write_zeroes(BlockDriverState *bs, int64_t sector_num, */ int bdrv_make_zero(BlockDriverState *bs, BdrvRequestFlags flags) { - int64_t target_size = bdrv_getlength(bs) / BDRV_SECTOR_SIZE; + int64_t target_size; int64_t ret, nb_sectors, sector_num = 0; int n; + target_size = bdrv_getlength(bs); + if (target_size < 0) { + return target_size; + } + target_size /= BDRV_SECTOR_SIZE; + for (;;) { nb_sectors = target_size - sector_num; if (nb_sectors <= 0) {