Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp98590iof; Sun, 5 Jun 2022 22:18:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmzA6EQG+VdfR7dwtdBDZhVCudTpipiTrkJl2oaEsFwjn0W3BFOUHnwE0AjpUnsLh3iy0u X-Received: by 2002:a17:902:e5c4:b0:166:44af:3c35 with SMTP id u4-20020a170902e5c400b0016644af3c35mr19657369plf.101.1654492733769; Sun, 05 Jun 2022 22:18:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654492733; cv=none; d=google.com; s=arc-20160816; b=KgTpzSvGUP3ovDedfRp4iOi1FiAhVEheD6XDSLwlNlV371RkC57y+tG/zErdxH85BL WHjZFqP5Pz4H6mKBh/nIprvKb2LWdkpHx1x81UEu/s10jgY44HHV9OwzZB6mvKEm7G9H br5lYU62xXnfyYtmmPpnqYkTOBZuGsCKbaj5IgnMS3EHdo1h9uDRUgqcIXUcqSNhMolv 91gaYRwwnjJWJYU7ewM4jKKZYXvie6Bi1PRtaEZifAns5G1aKnlg2orWn3ucJQOZ7S4k os/v4qaF6TCLj5x8YX1IUrC2+4ESdmfU14oQyFeS7ckn7FNHaVW2Jdx8z6fsFuKw3pRx 3Q3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=TfOfY9nDE6EgdzK7eHo1wPWpr31B0AhtWoqNGscvDio=; b=BS9bw9EBm95tObwuhJM0QkRZl6aj7/C/XRRetMkxMh3sa5YkCUwp9FXVIWn/Cs+Hvn EZKXnOGtq5rIdauDV3IN6iyr4FDM8gSGxBAI/AAnVTsF4R3CdL+IfXnsgdYzERYIEZK4 h3/DW8yQDItjNT4UljxNf4Fs9tBXSeyYGraX8jTzmvTYbqINr1sd4cJfBWFnfjC+Wfwm WfafpnKdKLYeFlgbVJXxuYMYH0Fk8owkOEJH6RuzX/3xZC4Hemf8bIbs9HAnXr/tdB5l VNaoNb5t5cydmaAiIX2ZcyVRLfyAL/bNUQTLAcmMIrAo/8yJ2tIECaY9qmJwSHv/E7aC Fa7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@riotgames.com header.s=riotgames header.b=EB0xhxnr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=riotgames.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id gt16-20020a17090af2d000b001e03e2be710si22227284pjb.118.2022.06.05.22.18.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 22:18:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@riotgames.com header.s=riotgames header.b=EB0xhxnr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=riotgames.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 21B4E187063; Sun, 5 Jun 2022 21:23:59 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229540AbiFCEb4 (ORCPT + 99 others); Fri, 3 Jun 2022 00:31:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237890AbiFCEby (ORCPT ); Fri, 3 Jun 2022 00:31:54 -0400 Received: from mail-ua1-x963.google.com (mail-ua1-x963.google.com [IPv6:2607:f8b0:4864:20::963]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 947F62180 for ; Thu, 2 Jun 2022 21:31:53 -0700 (PDT) Received: by mail-ua1-x963.google.com with SMTP id z15so2202620uad.7 for ; Thu, 02 Jun 2022 21:31:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:dkim-signature:mime-version:references :in-reply-to:from:date:message-id:subject:to:cc; bh=TfOfY9nDE6EgdzK7eHo1wPWpr31B0AhtWoqNGscvDio=; b=ioiRTafpOE2wSHTS4AYSBmd0KKQennzL2LCi1YXKVTAdwabeFOLlhtyPQ5a7gJjK84 0hqsChxsAW01WDn3qMras0ZNxOLfguHaK6ziNjks9UNi3qfsWZ1DAnQRm3QtvSB6YxEJ YO7SvXNdG8zusECZPCf1qed3jToZ6CXjQdMuHAoaLxsFkWcv62Hp9zPiLb71Oga5UNn0 cz/2GTrq33uGAumodBuW8c/s9AHhAhIgqVLBvm1qt5fXFKLht5i6bdZZsOnAvUKCAV0s +RjAZNKoT/iUTW6W0iT4+a9y0xw10AAsMuIdcL46Qx/0cFJXN5vMKAGyhcpwcZx2wAoU f9WQ== X-Gm-Message-State: AOAM533EfvLy4AQhj2A78j3yYJ0AruBMgtU7Evc5FbJaQEoqjbrKoBbb eQ1xa1qsPjkXfRS2zrewaG78qYQ/xitGHtiTX2fqi7oyJbJcfQ== X-Received: by 2002:a9f:386c:0:b0:362:9220:ce10 with SMTP id q41-20020a9f386c000000b003629220ce10mr25930067uad.68.1654230681079; Thu, 02 Jun 2022 21:31:21 -0700 (PDT) Received: from netskope.com ([163.116.128.209]) by smtp-relay.gmail.com with ESMTPS id b23-20020ab03917000000b003735b2deef2sm819089uaw.13.2022.06.02.21.31.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 21:31:21 -0700 (PDT) X-Relaying-Domain: riotgames.com Received: by mail-qk1-f197.google.com with SMTP id j12-20020ae9c20c000000b0069e8ac6b244so5189437qkg.1 for ; Thu, 02 Jun 2022 21:31:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riotgames.com; s=riotgames; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=TfOfY9nDE6EgdzK7eHo1wPWpr31B0AhtWoqNGscvDio=; b=EB0xhxnrrBnHMP+Yw1n+L6/aBww/dvWK+IVeF09JEDipF5Hblr7ZZ3BsnJKTyT+ru6 lMbAs+t8Vw0xSjQDS8SvPfKDDZ2fXhgGGIEZQvhFveC26VsbjQ68eNbjAgPCO5AovCG8 mNwCZojcO25AASOYLNPvXo+S4c7KbmB7K9ies= X-Received: by 2002:a05:620a:4154:b0:6a5:7577:3e1b with SMTP id k20-20020a05620a415400b006a575773e1bmr5309327qko.694.1654230678936; Thu, 02 Jun 2022 21:31:18 -0700 (PDT) X-Received: by 2002:a05:620a:4154:b0:6a5:7577:3e1b with SMTP id k20-20020a05620a415400b006a575773e1bmr5309317qko.694.1654230678725; Thu, 02 Jun 2022 21:31:18 -0700 (PDT) MIME-Version: 1.0 References: <20220603041701.2799595-1-irogers@google.com> In-Reply-To: <20220603041701.2799595-1-irogers@google.com> From: Zvi Effron Date: Thu, 2 Jun 2022 21:31:07 -0700 Message-ID: Subject: Re: [PATCH] libbpf: Fix is_pow_of_2 To: Ian Rogers Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Yuze Chi Content-Type: text/plain; charset="UTF-8" x-netskope-inspected: true X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 2, 2022 at 9:17 PM Ian Rogers wrote: > > From: Yuze Chi > > There is a missing not. Consider a power of 2 number like 4096: > > x && (x & (x - 1)) > 4096 && (4096 & (4096 - 1)) > 4096 && (4096 & 4095) > 4096 && 0 > 0 > > with the not this is: > x && !(x & (x - 1)) > 4096 && !(4096 & (4096 - 1)) > 4096 && !(4096 & 4095) > 4096 && !0 > 4096 && 1 > 1 > > Reported-by: Yuze Chi > Signed-off-by: Yuze Chi > Signed-off-by: Ian Rogers > --- > tools/lib/bpf/libbpf.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > index 3f4f18684bd3..fd0414ea00df 100644 > --- a/tools/lib/bpf/libbpf.c > +++ b/tools/lib/bpf/libbpf.c > @@ -4956,7 +4956,7 @@ static void bpf_map__destroy(struct bpf_map *map); > > static bool is_pow_of_2(size_t x) > { > - return x && (x & (x - 1)); > + return x && !(x & (x - 1)); No idea if anyone cares about the consistency, but in linker.c (same directory) the same static function is defined using == 0 at the end instead of using the not operator. Aside from the consistency issue, personally I find the == 0 version a little bit easier to read and understand because it's a bit less dense (and a "!" next to a "(" is an easy character to overlook). > } > > static size_t adjust_ringbuf_sz(size_t sz) > -- > 2.36.1.255.ge46751e96f-goog >