From nobody Thu May 2 15:22:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1628762600; cv=none; d=zohomail.com; s=zohoarc; b=oERNvg5uHM/bIijzEGfHXX6uFrIWJValQ1tIgbbZcEvltTBl/8+mPusAEJ0OVpVEKBu51SqQLzwAghcJs3gFCMyJ5IugjfMFdpYFY45GWbyOl4cDL3FFbe3eB2WB7gpONFFk77jShnXwc6fa7bhuQvDG21SfMNpFA1ILJR08emA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628762600; h=Content-Type:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=VGJYCzjzp3MabFfGgO9SK+1mI6oyy4VKX/d5cECyFUg=; b=BGAoZ2/Jx0hhxYdu+089wblL1dPVcURJrORsVbG3oCnn1AiJlH2EsSW/yB6xMWT082sji1snIRTbtQpG6kOKJkaAYDaM3zPmKlkjDVMnryBc+T6oD4wFWYOnOOEGg67byv9q6zT/u3AuMr1Z9p4pjsIDad6jggaOzFmRLzE7fM0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1628762600075439.994339821421; Thu, 12 Aug 2021 03:03:20 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.166240.303545 (Exim 4.92) (envelope-from ) id 1mE7Y3-0003dF-V8; Thu, 12 Aug 2021 10:02:51 +0000 Received: by outflank-mailman (output) from mailman id 166240.303545; Thu, 12 Aug 2021 10:02:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mE7Y3-0003d8-SE; Thu, 12 Aug 2021 10:02:51 +0000 Received: by outflank-mailman (input) for mailman id 166240; Thu, 12 Aug 2021 10:02:51 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mE7Y2-0003d2-W7 for xen-devel@lists.xenproject.org; Thu, 12 Aug 2021 10:02:51 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 727e195f-fb54-11eb-a143-12813bfff9fa; Thu, 12 Aug 2021 10:02:49 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 727e195f-fb54-11eb-a143-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1628762568; h=from:to:cc:subject:date:message-id:mime-version; bh=itNvF37HisPGqME7wUhpuGr7Ake5JLmxHXB6g8r082c=; b=GombGYj+C1x3BEH/WlVvKMG5Vklx6jWSoqF0m/r5SzM96jynl4qHqbqb sl0IhMmryLsFF/SS5FgjnQN9WD1aCjWsxK3WzKLnSukbLBnND9+4kH7zS Kd+muGKnC5JrjOgxMajTp0Tuu9cnDz0Oma9j5aq8cxfh4dlKcPZabbg9W s=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: lEVOfWRU9cVk+zbyFsdbwMuJ9kCSBxsoUEssdCPbRiJcDa7AzqsWe9LW8GWGAKW2BZmg2ee2PJ C42yd60bOT+xs06L4Lh7CbJ/ktUlDPyCSpG5u+Lac9mpZEpzysGoYBpQQvkmEhMykpMss/aCSR atulQyVufSEJEAw2y58tMIH9Fkf2RTtv8UsUJf6YTQ4MEfU21JURfz20EcMK28ORsBl28JyK63 wXcFeucqQ7oGgK81GNfixvbEwNbFE9jYLREfAZAN3il5Ajv3SA42UboUNvsq2lxhgr1Bnn7RXn XDef6EIAkpiuLQBl+5+UZnsD X-SBRS: 5.1 X-MesageID: 50673457 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:kIDnR6qQHQO1du11pmC6+rcaV5ojeYIsimQD101hICG8cqSj9v xG/c5rsyMc5wxhO03I9eruBEDiewK6yXcW2/hyAV7KZmCP0wHEQL2KhbGSpwEIcBefygcy78 ldmtBFebjNMWQ= X-IronPort-AV: E=Sophos;i="5.84,315,1620705600"; d="scan'208";a="50673457" From: Jane Malalane To: Xen-devel CC: Jane Malalane , Andrew Cooper , George Dunlap , "Ian Jackson" , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH v2] xen/bitmap: Don't open code DIV_ROUND_UP() Date: Thu, 12 Aug 2021 11:02:25 +0100 Message-ID: <20210812100225.20037-1-jane.malalane@citrix.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1628762600803100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Also, change bitmap_long_to_byte() and bitmap_byte_to_long() to take 'unsigned int' instead of 'int' number of bits, to match the type of their callers. Suggested-by: Andrew Cooper Signed-off-by: Jane Malalane Reviewed-by: Jan Beulich --- CC: Andrew Cooper CC: George Dunlap CC: Ian Jackson CC: Jan Beulich CC: Julien Grall CC: Stefano Stabellini CC: Wei Liu v2: * Reorder #include and wrap text --- xen/common/bitmap.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/xen/common/bitmap.c b/xen/common/bitmap.c index bbc3554ae1..7d4551f782 100644 --- a/xen/common/bitmap.c +++ b/xen/common/bitmap.c @@ -11,6 +11,7 @@ #include #include #include +#include #include =20 /* @@ -338,7 +339,8 @@ EXPORT_SYMBOL(bitmap_allocate_region); =20 #ifdef __BIG_ENDIAN =20 -static void bitmap_long_to_byte(uint8_t *bp, const unsigned long *lp, int = nbits) +static void bitmap_long_to_byte(uint8_t *bp, const unsigned long *lp, + unsigned int nbits) { unsigned long l; int i, j, b; @@ -354,7 +356,8 @@ static void bitmap_long_to_byte(uint8_t *bp, const unsi= gned long *lp, int nbits) clamp_last_byte(bp, nbits); } =20 -static void bitmap_byte_to_long(unsigned long *lp, const uint8_t *bp, int = nbits) +static void bitmap_byte_to_long(unsigned long *lp, const uint8_t *bp, + unsigned int nbits) { unsigned long l; int i, j, b; @@ -371,18 +374,20 @@ static void bitmap_byte_to_long(unsigned long *lp, co= nst uint8_t *bp, int nbits) =20 #elif defined(__LITTLE_ENDIAN) =20 -static void bitmap_long_to_byte(uint8_t *bp, const unsigned long *lp, int = nbits) +static void bitmap_long_to_byte(uint8_t *bp, const unsigned long *lp, + unsigned int nbits) { - memcpy(bp, lp, (nbits+7)/8); + memcpy(bp, lp, DIV_ROUND_UP(nbits, BITS_PER_BYTE)); clamp_last_byte(bp, nbits); } =20 -static void bitmap_byte_to_long(unsigned long *lp, const uint8_t *bp, int = nbits) +static void bitmap_byte_to_long(unsigned long *lp, const uint8_t *bp, + unsigned int nbits) { /* We may need to pad the final longword with zeroes. */ if (nbits & (BITS_PER_LONG-1)) lp[BITS_TO_LONGS(nbits)-1] =3D 0; - memcpy(lp, bp, (nbits+7)/8); + memcpy(lp, bp, DIV_ROUND_UP(nbits, BITS_PER_BYTE)); } =20 #endif @@ -393,13 +398,14 @@ int bitmap_to_xenctl_bitmap(struct xenctl_bitmap *xen= ctl_bitmap, unsigned int guest_bytes, copy_bytes, i; uint8_t zero =3D 0; int err =3D 0; - uint8_t *bytemap =3D xmalloc_array(uint8_t, (nbits + 7) / 8); + unsigned int xen_bytes =3D DIV_ROUND_UP(nbits, BITS_PER_BYTE); + uint8_t *bytemap =3D xmalloc_array(uint8_t, xen_bytes); =20 if ( !bytemap ) return -ENOMEM; =20 - guest_bytes =3D (xenctl_bitmap->nr_bits + 7) / 8; - copy_bytes =3D min(guest_bytes, (nbits + 7) / 8); + guest_bytes =3D DIV_ROUND_UP(xenctl_bitmap->nr_bits, BITS_PER_BYTE); + copy_bytes =3D min(guest_bytes, xen_bytes); =20 bitmap_long_to_byte(bytemap, bitmap, nbits); =20 @@ -422,13 +428,14 @@ int xenctl_bitmap_to_bitmap(unsigned long *bitmap, { unsigned int guest_bytes, copy_bytes; int err =3D 0; - uint8_t *bytemap =3D xzalloc_array(uint8_t, (nbits + 7) / 8); + unsigned int xen_bytes =3D DIV_ROUND_UP(nbits, BITS_PER_BYTE); + uint8_t *bytemap =3D xzalloc_array(uint8_t, xen_bytes); =20 if ( !bytemap ) return -ENOMEM; =20 - guest_bytes =3D (xenctl_bitmap->nr_bits + 7) / 8; - copy_bytes =3D min(guest_bytes, (nbits + 7) / 8); + guest_bytes =3D DIV_ROUND_UP(xenctl_bitmap->nr_bits, BITS_PER_BYTE); + copy_bytes =3D min(guest_bytes, xen_bytes); =20 if ( copy_bytes ) { --=20 2.11.0