Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2683928iog; Mon, 20 Jun 2022 02:21:03 -0700 (PDT) X-Google-Smtp-Source: AGRyM1spEhMV/7YV43AAE0+SHYi6gzIj5bSScXSICFqcTkoAoiKZB+g5WEbWPNuZhQrZf3Bse4oj X-Received: by 2002:a17:906:b05a:b0:718:cc6b:61e0 with SMTP id bj26-20020a170906b05a00b00718cc6b61e0mr20542757ejb.501.1655716863283; Mon, 20 Jun 2022 02:21:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655716863; cv=none; d=google.com; s=arc-20160816; b=UxwQITVj5pu+hA/Lop81aa/jvEY1b/pV0IW5UyH4UYujjctVVYrMjIWiPQFkTcUHQi OU6qEphgVlLLceZ2aMuKPesosgWs6FWZaKdnOCbpktxruP7vc9nyB3wK/LXXC+59rm+D Iv6TNV9oJckaRuRrpS5uPVzfOAwD2dB7An4a4dGyTHgv6e+bbEe/UCSZV5hWximJgQrL mpWayHJrSfw3Z3GieCBgDoHSZ+cxjKueWGC3zn9ZAIlWv6FUJ4ufYLhwe/XK/qGAEsph kYmLBO5kaxewnMYf0wlaqZ+9O+X0nDdC6WgHs9G8Nu2pRigD887PpPajHUC20mps8/ic e8cQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=LFBfQSp7S14/7l79i7QlTGM+D+dtyUxOKHRGdCeF5uw=; b=nLqZPiFK1FkjEV31gGETYC61V45xGtppCwQ45BjJYFRI/H25GLPCfSSJXxcjzW/TEa J6O123fLfy1miA2G4CrZQ61Cl/Gq4+0Ejlcad95jdWjYfexoxiTSLd1w8WdE7X9AiPoO cfI5IjhDSt/kmx7vJq9L+H8RsJCQxEmycvl+sT3tKSOiSU9J1U+fS4g4+6B/fUxiX0qG wo7cD5dcQ9L08j07RVi3w26JRO8VurN+x3N9OgI8G9nEMJOW+Qpioid/5ESbuV5JieQ6 Hp5OPJ7byASuYjx2SP8zeA2yVxeTpKEYWC6yaAADSPKXoVjbETJeVGInPXo/t0/PgkQY Dlxg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p26-20020a056402501a00b00435659808b2si8437155eda.298.2022.06.20.02.20.37; Mon, 20 Jun 2022 02:21:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239506AbiFTIXm (ORCPT + 99 others); Mon, 20 Jun 2022 04:23:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239911AbiFTIXd (ORCPT ); Mon, 20 Jun 2022 04:23:33 -0400 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CA2F0105; Mon, 20 Jun 2022 01:23:30 -0700 (PDT) Received: from linux.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9BxaeR8LrBiO65OAA--.25988S2; Mon, 20 Jun 2022 16:23:24 +0800 (CST) From: Tiezhu Yang To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Pavel Machek , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v2] libbpf: Include linux/log2.h to use is_power_of_2() Date: Mon, 20 Jun 2022 16:23:24 +0800 Message-Id: <1655713404-7133-1-git-send-email-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.1.0 X-CM-TRANSID: AQAAf9BxaeR8LrBiO65OAA--.25988S2 X-Coremail-Antispam: 1UD129KBjvJXoW7ZFyrZFWDuFWUGF43KrWUCFg_yoW8tw4DpF 4DCr18Gr1rWr15ZFyDuF1F93y5K3W7WFW7KFy7GryjvwnIqFsrXr1qyFnI9r13W395Ww15 ArWY9ryUZr1UX3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkab7Iv0xC_Kw4lb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xII jxv20xvEc7CjxVAFwI0_Cr0_Gr1UM28EF7xvwVC2z280aVAFwI0_Cr1j6rxdM28EF7xvwV C2z280aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC 0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Gr0_Cr 1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxkIecxEwVAFwVW8ZwCF04k2 0xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI 8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41l IxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIx AIcVCF04k26cxKx2IYs7xG6rWUJVWrZr1UMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvE x4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07bwYFZUUUUU= X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 is_power_of_2() is already defined in tools/include/linux/log2.h [1], so no need to define it again in tools/lib/bpf/libbpf_internal.h, so just include linux/log2.h directly. [1] https://lore.kernel.org/bpf/20220619171248.GC3362@bug/ Suggested-by: Pavel Machek Signed-off-by: Tiezhu Yang --- tools/lib/bpf/libbpf.c | 2 +- tools/lib/bpf/libbpf_internal.h | 6 +----- tools/lib/bpf/linker.c | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 49e359c..5252e51 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -5131,7 +5131,7 @@ static size_t adjust_ringbuf_sz(size_t sz) * a power-of-2 multiple of kernel's page size. If user diligently * satisified these conditions, pass the size through. */ - if ((sz % page_sz) == 0 && is_pow_of_2(sz / page_sz)) + if ((sz % page_sz) == 0 && is_power_of_2(sz / page_sz)) return sz; /* Otherwise find closest (page_sz * power_of_2) product bigger than diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h index a1ad145..021946a 100644 --- a/tools/lib/bpf/libbpf_internal.h +++ b/tools/lib/bpf/libbpf_internal.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include "libbpf_legacy.h" @@ -582,9 +583,4 @@ struct bpf_link * usdt_manager_attach_usdt(struct usdt_manager *man, const char *usdt_provider, const char *usdt_name, __u64 usdt_cookie); -static inline bool is_pow_of_2(size_t x) -{ - return x && (x & (x - 1)) == 0; -} - #endif /* __LIBBPF_LIBBPF_INTERNAL_H */ diff --git a/tools/lib/bpf/linker.c b/tools/lib/bpf/linker.c index 4ac02c2..b2edb5f 100644 --- a/tools/lib/bpf/linker.c +++ b/tools/lib/bpf/linker.c @@ -719,7 +719,7 @@ static int linker_sanity_check_elf(struct src_obj *obj) return -EINVAL; } - if (sec->shdr->sh_addralign && !is_pow_of_2(sec->shdr->sh_addralign)) + if (sec->shdr->sh_addralign && !is_power_of_2(sec->shdr->sh_addralign)) return -EINVAL; if (sec->shdr->sh_addralign != sec->data->d_align) return -EINVAL; -- 2.1.0