From nobody Thu May 2 01:09:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1576145020; cv=none; d=zohomail.com; s=zohoarc; b=gi6n0Agqg6q19mJKzc32blsPyTyNT6L2dm/nH7829tf70vmmRwAudUz2SOqqq8Y6UePn/stlfdliQKO4R48P1ybUsaG6G6vvnbcAdCUum2BPKJBzNj/ezM0fU23XTIWVvfXt7SopQcal/EKsF82thzyyhCdqqtlqp4mnkY1AaAg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576145020; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=UMboNIpM9Pc78IbDMq/NwOVDG82ceynpGZAYDEzIBpY=; b=IroaQH3nL8MlZ7qoBlpiIdDbxVV6My7vxPnx/Zeijcw4y++GhIxhMjR10/MbRzB3sdzeXlXxEpeF6uaqD2zVdGScdMAajukkp0BLXDc/MwSuIGD25WKY+tXfgqe1ZVjxXgqwFp1D/Vl/K+9NSSvVJMw/kZGWz4yewl8pbRslx7g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576145019587916.5054863798675; Thu, 12 Dec 2019 02:03:39 -0800 (PST) Received: from localhost ([::1]:57068 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifLJq-0003X4-CU for importer@patchew.org; Thu, 12 Dec 2019 05:03:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54377) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ifLIg-0002R5-HE for qemu-devel@nongnu.org; Thu, 12 Dec 2019 05:02:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ifLId-00076i-A0 for qemu-devel@nongnu.org; Thu, 12 Dec 2019 05:02:26 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:56693) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ifLIc-0006Wp-ME; Thu, 12 Dec 2019 05:02:23 -0500 Received: from 82-181-217-9.bb.dnainternet.fi ([82.181.217.9] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1ifLII-0006iz-Q1; Thu, 12 Dec 2019 11:02:02 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1ifLHq-0007iW-1N; Thu, 12 Dec 2019 12:01:34 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject:Cc:To:From; bh=UMboNIpM9Pc78IbDMq/NwOVDG82ceynpGZAYDEzIBpY=; b=li5LNSTQMvlYVgsphspMuzWuIbNeo6MoQroAume/V2V+pH0T6cYOkMbKIXS1GAAx8Gac2KhTSiZQ3W46bsUt6z0DTQwW9fWfrk7UmDXVOp39bxg+gmCOmH0E/F4ZRWQK+fHIgPaw4ocNtE/QarClfgrV54ESK63l/+yTLytDvC7upSUnDMQBALnQ25oD4jihde9sfUTBfAIjbwzk1U8zbC9X2+/M5awzybRl6/pfl68IYoBNqUoMNoKjnbN4VmD4KLm7hqQ5OlGmvtKpIp/+O7KngaPwf/secLKjqbI0dzVRoeyKvN3DUycz6ne5Qa2qGxGjcVzf46EdoDYeUPa7TQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH] qcow2: Use offset_into_cluster() Date: Thu, 12 Dec 2019 12:01:21 +0200 Message-Id: <20191212100121.29621-1-berto@igalia.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" There's a couple of places left in the qcow2 code that still do the calculation manually, so let's replace them. Signed-off-by: Alberto Garcia Reviewed-by: Eric Blake --- block/qcow2.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 7c18721741..3866b47946 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -367,7 +367,7 @@ static int qcow2_read_extensions(BlockDriverState *bs, = uint64_t start_offset, return -EINVAL; } =20 - if (bitmaps_ext.bitmap_directory_offset & (s->cluster_size - 1= )) { + if (offset_into_cluster(s, bitmaps_ext.bitmap_directory_offset= )) { error_setg(errp, "bitmaps_ext: " "invalid bitmap directory offset"); return -EINVAL; @@ -1958,9 +1958,8 @@ static int coroutine_fn qcow2_co_block_status(BlockDr= iverState *bs, { BDRVQcow2State *s =3D bs->opaque; uint64_t cluster_offset; - int index_in_cluster, ret; unsigned int bytes; - int status =3D 0; + int ret, status =3D 0; =20 qemu_co_mutex_lock(&s->lock); =20 @@ -1981,8 +1980,7 @@ static int coroutine_fn qcow2_co_block_status(BlockDr= iverState *bs, =20 if ((ret =3D=3D QCOW2_CLUSTER_NORMAL || ret =3D=3D QCOW2_CLUSTER_ZERO_= ALLOC) && !s->crypto) { - index_in_cluster =3D offset & (s->cluster_size - 1); - *map =3D cluster_offset | index_in_cluster; + *map =3D cluster_offset | offset_into_cluster(s, offset); *file =3D s->data_file->bs; status |=3D BDRV_BLOCK_OFFSET_VALID; } --=20 2.20.1