From patchwork Wed Jul 6 17:42:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12908418 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F116CCA47F for ; Wed, 6 Jul 2022 17:43:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 81F486B0075; Wed, 6 Jul 2022 13:43:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A72E6B0078; Wed, 6 Jul 2022 13:43:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 536396B007B; Wed, 6 Jul 2022 13:43:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 449626B0075 for ; Wed, 6 Jul 2022 13:43:01 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id D7960601FA for ; Wed, 6 Jul 2022 17:43:00 +0000 (UTC) X-FDA: 79657395720.09.5606E25 Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) by imf10.hostedemail.com (Postfix) with ESMTP id 73730C002F for ; Wed, 6 Jul 2022 17:43:00 +0000 (UTC) Received: by mail-qt1-f170.google.com with SMTP id x1so19281817qtv.8 for ; Wed, 06 Jul 2022 10:43:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5zrDKrgWjWYoqhLNgKXCX7OnjR9UTrCEG+O0rRKPH50=; b=heIFXapJdEzowqiFB2mS/xtMJxdMxoc2ubC65bgzqOxHnqbym8ZEcyKW7PFMQuQ0FO U/VqAR1hkNcMHGaETyC9JqpX/Ak1kpp4auixjtWIsc3C0SYoaz0KLazSBI8jT6Iyb7j0 AGFcrdV+9ut6Knb9YEtH1ef3hGVjZfE9lvsyC5b4/0aqs7MckkfzQdmG1rqbQBenK7LD 3A5+KzBgFXm0ePeRRo+I8O8TOvleYFVDuD4YE8OE1YgKTuqjnpiADOVq/zkimux1xOjj DqqYwC8LabwWYX0gke3X5o7qzErBACQTn5tAb+kUmpApr8GPeEl9bWbYPJMxZDdXbSnZ Jtxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5zrDKrgWjWYoqhLNgKXCX7OnjR9UTrCEG+O0rRKPH50=; b=PNoGKQEnJNdSjd4C7Y/3s1Cwk3YbtZQefSa7lZL9c4HIMPMxL1iYm3cVpFkQ7vG/r+ P7TWB9yOlQa1DoyFJStGUa0c80R9zMvQszNgxah0lfcJzCfftP8kBgKXsqbrSbf7py91 gmrjrka2+NQvmt+LMRiuIdMOpSuViIMwJXdnFV/V20FVxRq6omz6tV4IJgWkvm3WSnWn KRatfGAcQv6T1qqdGEYovNdlSv8anskMm+cYVXsePe4TSIww5Ha/peieSn2+O8iJLlod 0zOXLJLnDEc2+BDczUYYo3wBlm7J+lalHNnpjHDOKWaFKFKVSeypXsDZviWXxTwJxk5e LKgQ== X-Gm-Message-State: AJIora/o5wC54/zn1VHQdpyCCEexnMH3GG3k83n6gnKGyzD0FB2cY5v+ KLp/VO0hh5ufU60p5X40H6Q= X-Google-Smtp-Source: AGRyM1sgYG5ZA1Q43on9m/YHXkTTeIV7n/NLBKoToO6i4hQ4nI2FamaIV6GitTV1JyZvJs3oDAcsXQ== X-Received: by 2002:a05:6214:2506:b0:470:2c9c:65fa with SMTP id gf6-20020a056214250600b004702c9c65famr37643155qvb.117.1657129379917; Wed, 06 Jul 2022 10:42:59 -0700 (PDT) Received: from localhost (c-69-254-185-160.hsd1.ar.comcast.net. [69.254.185.160]) by smtp.gmail.com with ESMTPSA id x2-20020ae9e902000000b006a6a6f148e6sm29882134qkf.17.2022.07.06.10.42.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 10:42:59 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Andrew Morton , Andy Shevchenko , David Howells , Ingo Molnar , Geert Uytterhoeven , Jonathan Corbet , "Kirill A . Shutemov" , Matthew Wilcox , NeilBrown , Rasmus Villemoes , Russell King , Vlastimil Babka , William Kucharski , linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org Cc: Yury Norov Subject: [PATCH 03/10] lib/bitmap: change type of bitmap_weight to unsigned long Date: Wed, 6 Jul 2022 10:42:46 -0700 Message-Id: <20220706174253.4175492-4-yury.norov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220706174253.4175492-1-yury.norov@gmail.com> References: <20220706174253.4175492-1-yury.norov@gmail.com> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657129380; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=5zrDKrgWjWYoqhLNgKXCX7OnjR9UTrCEG+O0rRKPH50=; b=VVvm+a9QxQ541PAWipyn/O9fqwzTusA2kvvlFPTiZRdxrgP6pWWQ83BRmnYijRDwN9T34a lo9A+ZJF2d/QJAX51OKORj2OJo2Yp9DtEURCTO4aL5+RkMrT0NiF1IZLMWh/C3x1RPL/qA LlRkD7KwkLA7mlNYfhQbebogsSVOky8= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=heIFXapJ; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.160.170 as permitted sender) smtp.mailfrom=yury.norov@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657129380; a=rsa-sha256; cv=none; b=1KeWn82fLANBLisc9iO9MxUafBrUk/8Hq7BbNm2IEJqTCCMPPacC+s1+VSt9JwvTLWVDsH esyFe3Y6OvmOGSMFdm2aM5NJlAEv0ukuie+Wjh6B923I3bga+Ku+HO3hQ/nUbOBIF0LsCK 5Ah0LtALljvveVN1BTWW8WZlKlWpIWQ= X-Rspamd-Server: rspam11 X-Rspam-User: X-Stat-Signature: e16ggk5ir1d4876gs6c886dcxp6gj76y X-Rspamd-Queue-Id: 73730C002F Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=heIFXapJ; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.160.170 as permitted sender) smtp.mailfrom=yury.norov@gmail.com X-HE-Tag: 1657129380-945868 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: bitmap_weight() doesn't return negative values, so change it's type to unsigned long. It may help compiler to generate better code and catch bugs. Signed-off-by: Yury Norov --- include/linux/bitmap.h | 5 +++-- lib/bitmap.c | 5 ++--- tools/include/linux/bitmap.h | 4 ++-- tools/lib/bitmap.c | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 85aace699b2b..a92149f415d2 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -163,7 +163,7 @@ bool __bitmap_intersects(const unsigned long *bitmap1, const unsigned long *bitmap2, unsigned int nbits); bool __bitmap_subset(const unsigned long *bitmap1, const unsigned long *bitmap2, unsigned int nbits); -int __bitmap_weight(const unsigned long *bitmap, unsigned int nbits); +unsigned long __bitmap_weight(const unsigned long *bitmap, unsigned int nbits); void __bitmap_set(unsigned long *map, unsigned int start, int len); void __bitmap_clear(unsigned long *map, unsigned int start, int len); @@ -419,7 +419,8 @@ static inline bool bitmap_full(const unsigned long *src, unsigned int nbits) return find_first_zero_bit(src, nbits) == nbits; } -static __always_inline int bitmap_weight(const unsigned long *src, unsigned int nbits) +static __always_inline +unsigned long bitmap_weight(const unsigned long *src, unsigned int nbits) { if (small_const_nbits(nbits)) return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits)); diff --git a/lib/bitmap.c b/lib/bitmap.c index 098fd9db2363..b580b381eca1 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -333,10 +333,9 @@ bool __bitmap_subset(const unsigned long *bitmap1, } EXPORT_SYMBOL(__bitmap_subset); -int __bitmap_weight(const unsigned long *bitmap, unsigned int bits) +unsigned long __bitmap_weight(const unsigned long *bitmap, unsigned int bits) { - unsigned int k, lim = bits/BITS_PER_LONG; - int w = 0; + unsigned long k, w = 0, lim = bits/BITS_PER_LONG; for (k = 0; k < lim; k++) w += hweight_long(bitmap[k]); diff --git a/tools/include/linux/bitmap.h b/tools/include/linux/bitmap.h index 2ae7ab8ed7d1..ae1852e39142 100644 --- a/tools/include/linux/bitmap.h +++ b/tools/include/linux/bitmap.h @@ -11,7 +11,7 @@ #define DECLARE_BITMAP(name,bits) \ unsigned long name[BITS_TO_LONGS(bits)] -int __bitmap_weight(const unsigned long *bitmap, int bits); +unsigned long __bitmap_weight(const unsigned long *bitmap, unsigned int bits); void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1, const unsigned long *bitmap2, int bits); bool __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, @@ -61,7 +61,7 @@ static inline bool bitmap_full(const unsigned long *src, unsigned int nbits) return find_first_zero_bit(src, nbits) == nbits; } -static inline int bitmap_weight(const unsigned long *src, unsigned int nbits) +static inline unsigned long bitmap_weight(const unsigned long *src, unsigned int nbits) { if (small_const_nbits(nbits)) return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits)); diff --git a/tools/lib/bitmap.c b/tools/lib/bitmap.c index 2e351d63fdba..e1fafc131a49 100644 --- a/tools/lib/bitmap.c +++ b/tools/lib/bitmap.c @@ -5,9 +5,9 @@ */ #include -int __bitmap_weight(const unsigned long *bitmap, int bits) +unsigned long __bitmap_weight(const unsigned long *bitmap, unsigned int bits) { - int k, w = 0, lim = bits/BITS_PER_LONG; + unsigned long k, w = 0, lim = bits/BITS_PER_LONG; for (k = 0; k < lim; k++) w += hweight_long(bitmap[k]);