From nobody Fri May 3 10:11:53 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=1628695313; cv=none; d=zohomail.com; s=zohoarc; b=M7oH4xBvu/8m43ExAOl4d5Lepkk+dfDU+LnerGdTXv7Mo9wi8RgOeI2e+fDIRnpdvjhyiLauNx1oR6DlHfC1BzTVFHk5KByyQ929esROu12cDrmdXspYRTU4x2RNy1D6L4apZVBK+R3JSV0IQhjK0e3s/s19N4ruoiCbWH8Y8eE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628695313; h=Content-Type:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=cP5D4UavnWNxZcAx4+E1NxZF5Ya7C6WZYWbotaPVLr0=; b=YoOaCZKqCaraPXlU+xHmKKVdU23seLKZEz3lh/sG0TT9hWKM3g95xbl/L0O3343BQ3JXcFVtk8HqfK24iQj6wqeZpreEOAX96Fujy7cWFv6gDVg4R20vZbf6sU9XYGcMRuDC9foW92LlhVWLGINpKzXrF6soo2fjLd6lt7g5grI= 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 1628695313877704.2941719323898; Wed, 11 Aug 2021 08:21:53 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.166136.303399 (Exim 4.92) (envelope-from ) id 1mDq2v-0002Wr-QX; Wed, 11 Aug 2021 15:21:33 +0000 Received: by outflank-mailman (output) from mailman id 166136.303399; Wed, 11 Aug 2021 15:21:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mDq2v-0002Wk-NS; Wed, 11 Aug 2021 15:21:33 +0000 Received: by outflank-mailman (input) for mailman id 166136; Wed, 11 Aug 2021 15:21:32 +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 1mDq2u-0002Wa-Kw for xen-devel@lists.xenproject.org; Wed, 11 Aug 2021 15:21:32 +0000 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id cdc785d6-fab7-11eb-a09b-12813bfff9fa; Wed, 11 Aug 2021 15:21:31 +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: cdc785d6-fab7-11eb-a09b-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1628695291; h=from:to:cc:subject:date:message-id:mime-version; bh=eCKeutI27x2rCC5owfVia7tk2HpSAR1VD75w6n4F5QQ=; b=N7AKZRj1px9HlSm5I7ZnLZkJXWBn/j5KIFLY14I2B6gwN6ITpH0trIbD pwUaFKfVVSzTeeKzycR9T6sFT2/ITP+I7oIonR+gOviwxgH39klUq2zIf 8ywtnHUQ6VTiugrtWqSNe9hQTQdphYPHy+/nLKz1N6KxEFGmSLDpO88Mj A=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: mllvw5Ah7dOv3sTIV03vzLNpVF3aaNgMPs+rIXGBHqCTNrcNS99mZtlQE+B8YQtb0ulpgvcOFC lpjvqsALTCgEzuSXX1vk1fYapQE8HEkOAgI25q42lis9yi1MDR3ouG66Vj4rqjWowLAK8lUmJi hYRpCoDz4DTaeCEW+4hawM2wFdZdsLET9FHUhvz1aqK3Iu7rZPxNhCFIxgTYDdwPPvZsdRTNb+ fwC2AeAoWRFnUXb8U+K6/+/u/rM3VtC2ddUFmfqJ48p6mHgZfcGKpzZnlxJ/8zrP/yPXMIXuSk uWn8K6XJ2i9F7kJtElmcdHYc X-SBRS: 5.1 X-MesageID: 50223934 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:6YfCRqD0MoWQgmjlHem655DYdb4zR+YMi2TC1yhKJyC9E/bo8P xG88566faZslossRIb6LS90cu7MBDhHPdOiOF7V9qftWHdyQ6VxepZjLcKrQeOJ8SHzJ8+6Z td X-IronPort-AV: E=Sophos;i="5.84,313,1620705600"; d="scan'208";a="50223934" 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] xen/bitmap: Don't open code DIV_ROUND_UP() Date: Wed, 11 Aug 2021 16:20:55 +0100 Message-ID: <20210811152055.22962-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: 1628695314453100001 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 --- xen/common/bitmap.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/xen/common/bitmap.c b/xen/common/bitmap.c index bbc3554ae1..b78cb6029f 100644 --- a/xen/common/bitmap.c +++ b/xen/common/bitmap.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include =20 @@ -338,7 +339,7 @@ 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, unsi= gned int nbits) { unsigned long l; int i, j, b; @@ -354,7 +355,7 @@ 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, unsi= gned int nbits) { unsigned long l; int i, j, b; @@ -371,18 +372,18 @@ 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, unsi= gned 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, unsi= gned 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 +394,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 +424,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