From patchwork Fri Jul 1 12:54:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12903256 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 CB018CCA482 for ; Fri, 1 Jul 2022 12:54:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C3536B0078; Fri, 1 Jul 2022 08:54:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 673596B007D; Fri, 1 Jul 2022 08:54:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C8DE6B007E; Fri, 1 Jul 2022 08:54:39 -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 3EB376B0078 for ; Fri, 1 Jul 2022 08:54:39 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 198FD2088A for ; Fri, 1 Jul 2022 12:54:39 +0000 (UTC) X-FDA: 79638525078.26.5D0D18C Received: from mail-qv1-f49.google.com (mail-qv1-f49.google.com [209.85.219.49]) by imf08.hostedemail.com (Postfix) with ESMTP id 5918016003B for ; Fri, 1 Jul 2022 12:54:38 +0000 (UTC) Received: by mail-qv1-f49.google.com with SMTP id 59so4036008qvb.3 for ; Fri, 01 Jul 2022 05:54:38 -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=Uv5+jKOQ8RUlLeEtR603JL5t9bPUgBYvDDCEsdLilng=; b=DgrFX41S4QAnDhT+O9vofHz+UIzBaHWOfvdam2kbZOA/1GRVDNK5IkINeLwZn4Qwyo i5lxfRi5K04xatGBzVFP6eULZBSSuLdIm+hnD8UbTVvvNg33Trn0cE+gjphOs/JMEAnP MvJGmPsNt7jsEca163rXibGFlry4EFCQ7js++wTpT6cJLtKjCx6NhhOvErjtu3kYYsoI YhoWfiXbPT9JyQOxW2t006onbU3EJfL5zDRDzzSQ3s+oPCRCEOgyUn5ueAiO3JOoNEWa NfzURxmFovE91+1o/yk2iVGrVb0XRcoK/YNio84yQ0rPOgpr3FZNuraqzSCDpx0dyNQ0 LAdw== 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=Uv5+jKOQ8RUlLeEtR603JL5t9bPUgBYvDDCEsdLilng=; b=iK3sfsIWcU8dBV+jkqpbgDGyWGbW+jittHghc75z/mW0/QXof7qbjmCqJu7vmuZmvp CqlLYPk1e/5QN26b+V0+mKqDIWVMC7HTrbsDAnXH2EVm/jFcV8Yqj6UNqcrbWAfRvUr3 azN6HYlMmEiBV1LthFOprD9Fqy1klEHskwCQu9abQg9yMoYhdzkpsLDfAoaV4zAw78rj Ly+202NSPaEj6S8in6M8vYjIo7qEJY1b0cs54nFfpxxwGBG2drQOTI+9kFtbJoEQbZ8q oKa0fiE6VuVaRTAk+p7+BSbATd7fMXVO/SJzyMgzyaDIyHXkba4ATQ4ZTGH/Ub7b3x9F ob3w== X-Gm-Message-State: AJIora/E+pZHagmiaIEfeA4ILkeP+jrQBu/UWEt5YrGYEfNaF1ZHOl67 bHsKSGkEluZAgZYUVqLH4GE= X-Google-Smtp-Source: AGRyM1u+eUVgVfIOLTb/JNzScesZqkE4s8uOoTxS28xuW8AF0r5ZqYbr8PsjBESSvR+hO6k9B4oRhg== X-Received: by 2002:a0c:e1c6:0:b0:472:d7d0:8e2 with SMTP id v6-20020a0ce1c6000000b00472d7d008e2mr508550qvl.39.1656680077510; Fri, 01 Jul 2022 05:54:37 -0700 (PDT) Received: from localhost ([2601:4c1:c100:1230:f902:9816:653f:2f66]) by smtp.gmail.com with ESMTPSA id s10-20020a05620a254a00b006a6d74f8fc9sm19217194qko.127.2022.07.01.05.54.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Jul 2022 05:54:37 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Andrew Morton , Andy Shevchenko , David Howells , 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 3/8] lib/bitmap: change type of bitmap_weight to unsigned int Date: Fri, 1 Jul 2022 05:54:25 -0700 Message-Id: <20220701125430.2907638-4-yury.norov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220701125430.2907638-1-yury.norov@gmail.com> References: <20220701125430.2907638-1-yury.norov@gmail.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656680078; a=rsa-sha256; cv=none; b=AeFiRzvRCdZ6PCLPOlB0vOkbrgW8yt3aNSf7lrwOCXRX0j9a4qNI5kP+9jm7/YZiEN33L/ twNiPV0be/Z93+d6KrsUeWjbgJ9m3pBfH/wffIgbsQdhTo1hQXLx/tvqquG2xX/TJGsdiL 1zbXHddKZKS337zI9+OE9Vfh7S68yi8= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=DgrFX41S; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf08.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.219.49 as permitted sender) smtp.mailfrom=yury.norov@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656680078; 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=Uv5+jKOQ8RUlLeEtR603JL5t9bPUgBYvDDCEsdLilng=; b=ojQLjn80U1XhtaUimX/YgiG8yzHr4WRulbPEqWw3w3DpR7nskc79ER6pff2j+XO1J6G6Tr qYHIVGejUODrh5jm9ewFnB3hPoYvHAvIl2Wu90HMHwO6SVEuidUmSyNT8RdXQHXEI2cmc2 Ic4mHrW87sVVEfJwG8MK5btgPQRpDNo= X-Stat-Signature: x83bkac6uzd56byaubkzqdunop9i8z9g X-Rspamd-Queue-Id: 5918016003B Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=DgrFX41S; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf08.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.219.49 as permitted sender) smtp.mailfrom=yury.norov@gmail.com X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1656680078-161785 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 int. It may help compiler to generate better code and catch bugs. Signed-off-by: Yury Norov --- include/linux/bitmap.h | 2 +- lib/bitmap.c | 5 ++--- tools/include/linux/bitmap.h | 4 ++-- tools/lib/bitmap.c | 4 ++-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index e1a438bdda52..812835d3149a 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); 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..c9c24dfe0443 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 int __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 int 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..974e51809f57 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 int __bitmap_weight(const unsigned long *bitmap, unsigned int bits) { - int k, w = 0, lim = bits/BITS_PER_LONG; + unsigned int k, w = 0, lim = bits/BITS_PER_LONG; for (k = 0; k < lim; k++) w += hweight_long(bitmap[k]);