From patchwork Mon Nov 14 03:28:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tiezhu Yang X-Patchwork-Id: 19534 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1942190wru; Sun, 13 Nov 2022 19:32:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf44j0QbCuWP/ehsd/vVKBy8ehLICctgjbykYOl2LTdw36SIfsoEFLrkUE3+6EbTfQVvtJS4 X-Received: by 2002:aa7:d4d3:0:b0:45f:b80f:1fe8 with SMTP id t19-20020aa7d4d3000000b0045fb80f1fe8mr9359479edr.118.1668396779340; Sun, 13 Nov 2022 19:32:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668396779; cv=none; d=google.com; s=arc-20160816; b=amrloIzVaAwYL7J4qyUW2fIuqNpMK41nsNob56yiHkOc8dQ/2U4b95XKdBzjuA6UZO TBf/8Um2S+NXN2ZPEPT0b29ibF6cevcAdsW+mHbafGmlntIVOfxsillRZg8h731tT5uJ 0PI9r5Ytg4FYGNp+HrmkZExx0PsiamCCN6iz5e1FSCes9XeIYhLIhUPdhUHrJAT92WSu TDGnLPcMuAqw6x/6lMqkyjqVixBV3/uLJwGDAlUNxDmdN/EPqT+1uU3cyYJAz2otUMd/ v5qIzlrYFvAZKHDukGKS1J3HO93uvD/uHX4wXlvA7D4DgiC/L7W5gxAc0/gcGrmDzfq6 ms2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=UMfVfqISYes1ncxJZwZDAPgvvqwpLd9XY/sYs6t9MSc=; b=YDnGSu0bTDLH6JhVBaFwVE7wSGCsSUvU4NDnisEwe0MK7/B7d8v5GzbIKlUGrzUgfx h1jelNXF6x+uMgN+zDRKIn/yObUcPkeD2Ja2W3biqUgokeEaI+E713bYMjEjAeLrCdRp GFkC37tgHtKt8JnZzvJnefuaZjwtEsVUh5w48bugVGIwbMFOnibmg/2f1m8ooKyOHVop vijfMHayDIgq/j+UcLI5sQF6SFZJE9EcJlOztzRHqny+UWk1ET826orYIbRfZKb3QNuG WJvV2ZHrIY6jld3Ap1fodxwE4LfhBPEC1yK1yzue8Qw/VgiKBdK+64pwO+5jAUFLZwLj jIlA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cs14-20020a170906dc8e00b007adf388f2dasi9093642ejc.497.2022.11.13.19.32.36; Sun, 13 Nov 2022 19:32:59 -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; 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 S235669AbiKND2Q (ORCPT + 99 others); Sun, 13 Nov 2022 22:28:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235376AbiKND2J (ORCPT ); Sun, 13 Nov 2022 22:28:09 -0500 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D4751DF5A; Sun, 13 Nov 2022 19:28:07 -0800 (PST) Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8Dx_7fGtXFj1skGAA--.18954S3; Mon, 14 Nov 2022 11:28:06 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cxn+DFtXFj3j0SAA--.49444S4; Mon, 14 Nov 2022 11:28:06 +0800 (CST) From: Tiezhu Yang To: Quentin Monnet , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next 2/2] bpftool: Check argc first before "file" in do_batch() Date: Mon, 14 Nov 2022 11:28:04 +0800 Message-Id: <1668396484-4596-3-git-send-email-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1668396484-4596-1-git-send-email-yangtiezhu@loongson.cn> References: <1668396484-4596-1-git-send-email-yangtiezhu@loongson.cn> X-CM-TRANSID: AQAAf8Cxn+DFtXFj3j0SAA--.49444S4 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBjvdXoW7Xr4xAF4xur1Utr4rKw4DJwb_yoWDGrg_Wa y3ZF1avFn5JryakF4UG398uryxKa18ZwsYqr4akr18JrW8Xw17AF48C395Xw45uFWqkw12 yFZ3uryfGF129jkaLaAFLSUrUUUU1b8apTn2vfkv8UJUUUU8wcxFpf9Il3svdxBIdaVrn0 xqx4xG64xvF2IEw4CE5I8CrVC2j2Jv73VFW2AGmfu7bjvjm3AaLaJ3UjIYCTnIWjp_UUUY y7kC6x804xWl14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0rVWrJVCq3w AFIxvE14AKwVWUXVWUAwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK021l84ACjcxK 6xIIjxv20xvE14v26ryj6F1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4j6F4UM28EF7 xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJwAa w2AFwI0_Jrv_JF1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44 I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jw0_WrylYx0Ex4A2 jsIE14v26r4j6F4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20x vY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwCFI7km07C267AKxVWUXVWUAwC20s02 6c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF 0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvE c7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14 v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x 07jz2NtUUUUU= X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749440821367812437?= X-GMAIL-MSGID: =?utf-8?q?1749440821367812437?= If the parameters for batch are more than 2, check argc first can return immediately, no need to use strcmp() to check "file" with a little overhead and then check argc, it is better to check "file" only when the parameters for batch are 2. Signed-off-by: Tiezhu Yang --- tools/bpf/bpftool/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c index 4ef87c2..27d6dbf 100644 --- a/tools/bpf/bpftool/main.c +++ b/tools/bpf/bpftool/main.c @@ -337,12 +337,12 @@ static int do_batch(int argc, char **argv) if (argc < 2) { p_err("too few parameters for batch"); return -1; - } else if (strcmp(*argv, "file")) { - p_err("expected 'file', got: %s", *argv); - return -1; } else if (argc > 2) { p_err("too many parameters for batch"); return -1; + } else if (strcmp(*argv, "file")) { + p_err("expected 'file', got: %s", *argv); + return -1; } NEXT_ARG();