Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp369667pxb; Wed, 11 Nov 2020 05:56:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJzBLTkqTMgxVX9OQ9fLuL9tUUXE0ALH9kWX3bXm6Y2vYGQiBeln+r4ilYWmxuCpwxZBoCVs X-Received: by 2002:a50:abe6:: with SMTP id u93mr5006308edc.277.1605102989780; Wed, 11 Nov 2020 05:56:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605102989; cv=none; d=google.com; s=arc-20160816; b=ldejN+4Z8tOseQbFRABe9kA9OdHXggIP+r61qo7AxhaOUtxXYQSb+ft0WpD1ihv94V KL2k154k/HsTDy9LCMw3KkmKkMYbEttU57QOqPk3o+HhxOuLXk5Q+3W9T0SXDPj846VS RRGvmbovq3yTFk3S6ZoyeJfGp8RzR5ocoQXWErXPBmKKTbgJWYzC0T/KuVf3sjFv3z1r G5k7c8IUn3qshQsee5ke01ZOlK2HvcAFyFjLEPLmVfMcfIbvvSZlZ7rW8K5TBZiG2hhD xmodLDqLaQgSaW3goOx7np1D9M+gtEZ9ZpjDe6MyiZVx9ITfVeT0pnOhBClXSogvuZw6 8SEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=xJgH/Zoaa8DIfLtcx/1Gl4iajMCKSaiohnFuvhqNXng=; b=NhYEfIoAW61uJfc5x0mV/t0Wm9RAuEb4ZmI090Xv61mLgKextEzFSwjsWKgqikolRA URTsb/MTSXZ85ihHI/+hSoMK0gRuCMEFmzmONOI+UTu27PVwuGElyH9kFmzmGwJXRHrb s3UgSTiIBs8vq38GmD8NbotFgLGE0T7h1D1NHP/Lipzag2fF+Hmtsn/cmmaKY3nkVCer XeI2doisy5aUZPlpsX5RpMWZf0S+/mwevisg5/Heaxq6UdOVkOlNLl8m17m5amF6dLTN zIV35u0c183f2v2t+3LiiWYZgElwMzfqXMpuTYmJ+2vNhAMB/e1Vzxjw4oWGOKy8vaw0 pY1A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a7si1464445eda.335.2020.11.11.05.56.06; Wed, 11 Nov 2020 05:56:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727014AbgKKNvh (ORCPT + 99 others); Wed, 11 Nov 2020 08:51:37 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:7883 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726985AbgKKNvd (ORCPT ); Wed, 11 Nov 2020 08:51:33 -0500 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4CWR3536z3z75dk; Wed, 11 Nov 2020 21:51:13 +0800 (CST) Received: from huawei.com (10.175.113.133) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.487.0; Wed, 11 Nov 2020 21:51:21 +0800 From: Wang Hai To: , , CC: , , , , , , , , , , , Subject: [PATCH v3 bpf] tools: bpftool: Add missing close before bpftool net attach exit Date: Wed, 11 Nov 2020 21:54:25 +0800 Message-ID: <20201111135425.56533-1-wanghai38@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.113.133] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org progfd is created by prog_parse_fd(), before 'bpftool net attach' exit, it should be closed. Fixes: 04949ccc273e ("tools: bpftool: add net attach command to attach XDP on interface") Signed-off-by: Wang Hai --- v2->v3: add 'err = 0' before successful return v1->v2: use cleanup tag instead of repeated closes tools/bpf/bpftool/net.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tools/bpf/bpftool/net.c b/tools/bpf/bpftool/net.c index 910e7bac6e9e..f927392271cc 100644 --- a/tools/bpf/bpftool/net.c +++ b/tools/bpf/bpftool/net.c @@ -578,8 +578,8 @@ static int do_attach(int argc, char **argv) ifindex = net_parse_dev(&argc, &argv); if (ifindex < 1) { - close(progfd); - return -EINVAL; + err = -EINVAL; + goto cleanup; } if (argc) { @@ -587,8 +587,8 @@ static int do_attach(int argc, char **argv) overwrite = true; } else { p_err("expected 'overwrite', got: '%s'?", *argv); - close(progfd); - return -EINVAL; + err = -EINVAL; + goto cleanup; } } @@ -597,16 +597,20 @@ static int do_attach(int argc, char **argv) err = do_attach_detach_xdp(progfd, attach_type, ifindex, overwrite); - if (err < 0) { + if (err) { p_err("interface %s attach failed: %s", attach_type_strings[attach_type], strerror(-err)); - return err; + goto cleanup; } if (json_output) jsonw_null(json_wtr); - return 0; + err = 0; + +cleanup: + close(progfd); + return err; } static int do_detach(int argc, char **argv) -- 2.17.1