Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1090428pxb; Fri, 13 Nov 2020 04:06:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJy1+hWvfQ/qJMpOYaEGaxYcPdilk2br71NP7B3b0WVgn5CXY5yL8YZgI8d3+epkNKNiLU6W X-Received: by 2002:a05:6402:236e:: with SMTP id a14mr2103998eda.103.1605269163568; Fri, 13 Nov 2020 04:06:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605269163; cv=none; d=google.com; s=arc-20160816; b=Fs9djT/8ZpMXom83lrsK7dqjuA+grEc9pKsYXPHI2us50qZdnJ1euiufeii0miyLz7 VNsiSeK8bxnCfbCOuLT1OlCjRpW3Sn2kyBTrIbzFSdfx/NXOoApRzrZiMJ74Bvij1vWX OcZe4sRkkziFTSqy/MiKC/ShhJdKezxL2uvu1+KTEWaAInfOprNJinkq4puSSICDr25I V5G3OaPFGHTHPUt9Jg+mML9NoBUtymgmPs+kvAGce6hzm1/KCQ55/Mq9mUfo0YteBP1s rrVpOJRx0jccOBnQkwBLgi3+WMuC4Cs/Xd3fDAhHasj6WVolDBoaREeRNfsTv5VIT9nW uCIA== 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=MpNnw9g5R1KehQBr6aJaufDQ20rns09tqziy8zimeKw=; b=TgFDIU5RcG7CH+d98c0kKiLUOcAm9xRZ2b+IHeFmlcIk8YWijqwv2esgw9WIaOCgKO 3m5XBpYEU5ABJwFxbKrk8N3X+xR/uCSv1CaoHlD9pvdjTvaoiCjLLwHyw3H3XyM9KgD2 H47iTlEnd6ZwVLR+ODlDsV5kVBf2NNja91gDOnb+2fQnbcMPW/BfiBnbiCmdfjy68qF+ 94VuxrNA2L1uRNzs/DXb7hu8hoDnxq5Cnw+iBl5z671zECW9OeXdwEtcioxFlX9zTsgo eb+8UKtFcvVtyyvvGi08yP1RbfJX80bTDAI71B/Q68XJnvCxsjgeqvEkNVOB85jOpdFG yJ0g== 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 u20si5492578eje.628.2020.11.13.04.05.40; Fri, 13 Nov 2020 04:06:03 -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 S1726752AbgKMMC7 (ORCPT + 99 others); Fri, 13 Nov 2020 07:02:59 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:7497 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726858AbgKMLte (ORCPT ); Fri, 13 Nov 2020 06:49:34 -0500 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4CXcDv0HKVzhlBS; Fri, 13 Nov 2020 19:48:47 +0800 (CST) Received: from huawei.com (10.175.113.133) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.487.0; Fri, 13 Nov 2020 19:48:50 +0800 From: Wang Hai To: , , , CC: , , Subject: [PATCH v4 bpf] tools: bpftool: Add missing close before bpftool net attach exit Date: Fri, 13 Nov 2020 19:51:52 +0800 Message-ID: <20201113115152.53178-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 --- v3->v4: delete 'err = 0' v2->v3: add 'err = 0' before successful return v1->v2: use cleanup tag instead of repeated closes tools/bpf/bpftool/net.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tools/bpf/bpftool/net.c b/tools/bpf/bpftool/net.c index 910e7bac6e9e..b27b3ee9f2aa 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,18 @@ 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; +cleanup: + close(progfd); + return err; } static int do_detach(int argc, char **argv) -- 2.17.1