From nobody Sat Feb 7 03:05:36 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1729167056514506.0269358368337; Thu, 17 Oct 2024 05:10:56 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 659AC1201; Thu, 17 Oct 2024 08:10:40 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 9ED0D1352; Thu, 17 Oct 2024 08:09:31 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 26EB71201; Thu, 17 Oct 2024 08:09:22 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 889481218 for ; Thu, 17 Oct 2024 08:09:21 -0400 (EDT) Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-612-HFK0xM4OOl2VgKfjAwtB8w-1; Thu, 17 Oct 2024 08:09:19 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 144511955F41 for ; Thu, 17 Oct 2024 12:09:19 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.4]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4629E1955F43 for ; Thu, 17 Oct 2024 12:09:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: *** X-Spam-Status: No, score=3.0 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RCVD_IN_SBL_CSS, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729166961; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LjGjKR+o+1wF5aupDudKXXUpr85CPrh4nUAz/iYKc7E=; b=fxkQY9w6k27YJWYFFPaGi8+poY3n/p1HdaK36IRy5M1y6z3OR07lBIiQ8eqlDQePU2t02H z/21MPaE8g+4V+6EJM5IdZCsDz8L/es034sfJfFQRRW22jwLDR/YsDieprVQFblQcgeIAJ lL6lVBpQDyxoLMzaWALgpG10ZQ6A4EY= X-MC-Unique: HFK0xM4OOl2VgKfjAwtB8w-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 3/4] util: virbitmap: Extract clearing of unused bits at the end of the last unit Date: Thu, 17 Oct 2024 14:09:11 +0200 Message-ID: <5c9d2d797b271a3b13a15812286dbf6852bd9cb5.1729166910.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: N7DC6CNKQ6DUUHBKIBT5CYXNRAQXHYB6 X-Message-ID-Hash: N7DC6CNKQ6DUUHBKIBT5CYXNRAQXHYB6 X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1729167058126116600 Content-Type: text/plain; charset="utf-8" Extract the clearing of the traling bits from 'virBitmapSetAll' into a new helper. Signed-off-by: Peter Krempa --- src/util/virbitmap.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index 7dc63da6db..35cf729a22 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -757,6 +757,19 @@ virBitmapSize(virBitmap *bitmap) } +/** + * Internal helper that clears the unused bits at the end of the last bitm= ap unit. + */ +static void +virBitmapClearTail(virBitmap *bitmap) +{ + size_t tail =3D bitmap->nbits % VIR_BITMAP_BITS_PER_UNIT; + + if (tail) + bitmap->map[bitmap->map_len - 1] &=3D -1UL >> (VIR_BITMAP_BITS_PER= _UNIT - tail); +} + + /** * virBitmapSetAll: * @bitmap: the bitmap @@ -765,15 +778,10 @@ virBitmapSize(virBitmap *bitmap) */ void virBitmapSetAll(virBitmap *bitmap) { - int tail =3D bitmap->nbits % VIR_BITMAP_BITS_PER_UNIT; - memset(bitmap->map, 0xff, bitmap->map_len * (VIR_BITMAP_BITS_PER_UNIT / CHAR_BIT)); - /* Ensure tail bits are clear. */ - if (tail) - bitmap->map[bitmap->map_len - 1] &=3D - -1UL >> (VIR_BITMAP_BITS_PER_UNIT - tail); + virBitmapClearTail(bitmap); } --=20 2.47.0