X-Received: by 2002:a05:6402:278e:b0:412:dac7:27fe with SMTP id b14-20020a056402278e00b00412dac727femr1036008ede.191.1645647161086; Wed, 23 Feb 2022 12:12:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645647161; cv=none; d=google.com; s=arc-20160816; b=yvgu8rNzlsErHv1YoCwoB5sdNMiqFPyij0qa/mj+OgODa0IafCKosq11IoLM4uxB5d G1uJcPj03kQVBwnqF6qsaIKUpF2FQkithAkbdTZOWmR3zMrlr806YTYTojkv4SnC8Fp4 yYkpEpYx8cDhQ6HenIfYJxeK9OMvg8KUD8BYUC9IBeWMO+EGe0k81m1q4LmJH149dMRS XIltDsy/tvvhzl3QAi5i+9wK12s42sXVVE8rwfZpg610duXCMfgvVSsgeDU4A5XYQtO5 jKcdfirNgQdC+1PBwufFMsUWS9vpWkPtjxoN0wGtloo/bUH+QfYoOTfA1pjTlG2ll9IH VPDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=iDb45oPj0ifDcB8Xoh2dodzalPDAwvLvo6tLmA+1g1A=; b=q6k5IJapYnzo+yAarZQL5ijtiknBBStPs7JMn58vmO/v02HXUKlAxRm5uCaO9DOXxJ 2yVFLcNnIiCBFi51FQZN/wqv9B/SyIcdDWXeyjvGNo0ESPLu3Mer6YEkPd4nYg27t9H9 KAVJNPxgtddq4b5RpOefUYvXOlxrXWB2mKjcb0RiyEUW84unU9kyAqb5bK2s9zOMmd+D WkKNjsi0TAVXU58AFVrCHqkK9bSEkYtpDNKUTj8agUVb//edcJXgiqUyIGbU8C9x/hUJ qBz7KGuEnqctO67wBWyte6f6acECeTqiy9WYryvjnjm8BC1uYVcmMs3Nk8Cie/NFqKlU Dv5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=pZyB5i3E; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y9si304735edv.319.2022.02.23.12.12.18; Wed, 23 Feb 2022 12:12:41 -0800 (PST) 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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=pZyB5i3E; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239000AbiBWIeb (ORCPT + 99 others); Wed, 23 Feb 2022 03:34:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233549AbiBWIe2 (ORCPT ); Wed, 23 Feb 2022 03:34:28 -0500 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A970674C4; Wed, 23 Feb 2022 00:34:02 -0800 (PST) Received: by mail-pj1-x102f.google.com with SMTP id j10-20020a17090a94ca00b001bc2a9596f6so2024409pjw.5; Wed, 23 Feb 2022 00:34:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=iDb45oPj0ifDcB8Xoh2dodzalPDAwvLvo6tLmA+1g1A=; b=pZyB5i3EDjAvoOu1W4jIwUnpSx7RWt7r5xjs0PYS8CWbj9v/+h6LN5hErKk9z+R5tF 3MK33kzZg+4iafVWLruxFp+YPsCSgYshqQy5MwK6eYG9h0d3tlqTJ6od746GCspi3onX xnO7jWcH5ymHmNkpRplsON3xjlfiMKGCfYXm+GpIHnUtRHzNQqUYj+lTAvPH/CrMK6EY snxwzaLrt4fp8VbMaoyw8FLwrR9702Qy/U4H0gjia+elRMlqIQEJPvDbzyvqBJa/QKPh 6kH0c7Y2exw98Im4vIstHP54myt2aWXNIzXBi0/6htlpvmdWWBJS7lGkdO4dJxBn7Cb/ H6hw== 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:mime-version :content-transfer-encoding; bh=iDb45oPj0ifDcB8Xoh2dodzalPDAwvLvo6tLmA+1g1A=; b=wRZt2jF9Q9Q2dv69l+QYBDUP2Fybnilnk3PVqFFxN4ETNpe8QOY2/rQXygs5hj7AMT e5n3n8mYTIz9YgiHpbnaBfj+/41rkR7Kw/IJYY0QI7driHpaCKi5i120L0PFcfllATrb pTKqAf0tbw/j9Xnsi5RtgiKi+QMjuJZLdsU/T06H9sTuGzn2u2ZY6rUKyEIGTE+Bfpy7 yrvKSRgSA2vt2687pprcHf63im1iLDat6MsMKNIw7vEHIOGRbvMCY7n5MpBfNW3wy7WK WJeTce03gKVPiPGodQY9J12UC1+zv47PfpmCOZhteE2uvQrsI9F4OJ2C4s3QLdJSLpDW LCKA== X-Gm-Message-State: AOAM533NBPVQpOK5d1RI+aSQfuDjVTmy/MjdtebqbWqvjWd8xJzHJI+Q hP3zjoLi74F2816f4TYv19KZLeom+M5zrKYPZho= X-Received: by 2002:a17:90a:ac1:b0:1b9:7dd3:ba5f with SMTP id r1-20020a17090a0ac100b001b97dd3ba5fmr8126134pje.178.1645605241389; Wed, 23 Feb 2022 00:34:01 -0800 (PST) Received: from localhost.localdomain ([43.132.141.8]) by smtp.gmail.com with ESMTPSA id bd14sm9338613pfb.165.2022.02.23.00.33.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 00:34:00 -0800 (PST) From: Yuntao Wang To: bpf@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Yuntao Wang Subject: [PATCH] libbpf: Simplify the find_elf_sec_sz() function Date: Wed, 23 Feb 2022 16:33:00 +0800 Message-Id: <20220223083300.3054673-1-ytcoode@gmail.com> X-Mailer: git-send-email 2.35.0.rc2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,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 The check in the last return statement is unnecessary, we can just return the ret variable. But we can simplify the function further by returning 0 immediately if we find the section size and -ENOENT otherwise. Thus we can also remove the ret variable. Signed-off-by: Yuntao Wang --- tools/lib/bpf/libbpf.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 7e978feaf822..776b8e034d62 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -1374,22 +1374,20 @@ static bool bpf_map_type__is_map_in_map(enum bpf_map_type type) static int find_elf_sec_sz(const struct bpf_object *obj, const char *name, __u32 *size) { - int ret = -ENOENT; Elf_Data *data; Elf_Scn *scn; - *size = 0; if (!name) return -EINVAL; scn = elf_sec_by_name(obj, name); data = elf_sec_data(obj, scn); if (data) { - ret = 0; /* found it */ *size = data->d_size; + return 0; /* found it */ } - return *size ? 0 : ret; + return -ENOENT; } static int find_elf_var_offset(const struct bpf_object *obj, const char *name, __u32 *off) -- 2.35.0.rc2