From nobody Wed Nov 5 05:06:23 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1533033042829699.3871942973275; Tue, 31 Jul 2018 03:30:42 -0700 (PDT) Received: from localhost ([::1]:58005 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fkRvN-0002OB-Me for importer@patchew.org; Tue, 31 Jul 2018 06:30:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57269) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fkRuD-0001Zp-IT for qemu-devel@nongnu.org; Tue, 31 Jul 2018 06:29:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fkRu9-0007SO-KN for qemu-devel@nongnu.org; Tue, 31 Jul 2018 06:29:29 -0400 Received: from mga06.intel.com ([134.134.136.31]:39279) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fkRu9-0007S6-B2 for qemu-devel@nongnu.org; Tue, 31 Jul 2018 06:29:25 -0400 Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Jul 2018 03:29:23 -0700 Received: from devel-ww.sh.intel.com ([10.239.48.110]) by orsmga007.jf.intel.com with ESMTP; 31 Jul 2018 03:29:07 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,427,1526367600"; d="scan'208";a="60879971" From: Wei Wang To: qemu-devel@nongnu.org, peterx@redhat.com, dgilbert@redhat.com, quintela@redhat.com Date: Tue, 31 Jul 2018 18:01:18 +0800 Message-Id: <1533031278-5615-1-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.31 Subject: [Qemu-devel] [PATCH v2] bitmap: fix BITMAP_LAST_WORD_MASK X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When "nbits =3D 0", which means no bits to mask, this macro is expected to return 0, instead of 0xffffffff. This patch changes the macro to return 0 when there is no bit needs to be masked. Signed-off-by: Wei Wang CC: Juan Quintela CC: Dr. David Alan Gilbert CC: Peter Xu Reviewed-by: Juan Quintela Reviewed-by: Peter Xu --- include/qemu/bitmap.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) v1->v2 ChangeLog: - fix the macro directly, instead of fixing the callers one by one. diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h index 509eedd..9372423 100644 --- a/include/qemu/bitmap.h +++ b/include/qemu/bitmap.h @@ -60,7 +60,10 @@ */ =20 #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG -= 1))) -#define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG -= 1))) +#define BITMAP_LAST_WORD_MASK(nbits) \ +( \ + nbits ? (~0UL >> (-(nbits) & (BITS_PER_LONG - 1))) : 0 \ +) =20 #define DECLARE_BITMAP(name,bits) \ unsigned long name[BITS_TO_LONGS(bits)] --=20 2.7.4