Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp678252pxb; Wed, 11 Nov 2020 13:26:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJw5seH+L87Buu0hT8VUNS5mqDALOYys6JqyOLhJEKFwTcPhQNXLCo/qdBHDVdbcLP+9U8LN X-Received: by 2002:a05:6402:16d6:: with SMTP id r22mr1734848edx.246.1605129978916; Wed, 11 Nov 2020 13:26:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605129978; cv=none; d=google.com; s=arc-20160816; b=BnL/uzg6XVtPwPWAMY3wbJLnPjOP6Y9Tr0CGFgBhQvoDkd5LbBlMnS5OPd+6HWBrW0 rt1OeeI7okEv3vyuxB/aFCt4KyjYi80GOOBs5+d4yQDOZn6hut91IzzN12pX+2ELFDnj OvFFvwmLkmK61WhDY7YzJPfRQeH+fwa8ix+RqPC5LCPPpcP4nyrkHlazFOV6tVH30BOW U1vyyCo0lvV51sRugjbqHfBM6Ofq63u1+YEjIUwNnBb/waZqJaCF5LmfvVOeCKjBTsEk 1zpIvNMdMPyNiSxvbKMro/PlnD1pdWrTU2mAwB9JxXEKm0Ok9Xt1sSuS63LeCpg7/q8S BDjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=0W/nXNNVOMLa+TTuA886EhvP9HKBS0Ui1RY7foQboi8=; b=DrtNSiy6AYVbRZgdVbJE16xmLA8msIqAhyCPt5GMfO4zvZCEA+fcdTgKlmxUd0fLga +6/Xi/h1oE2uokNRaYb9sKH8Bjt9vwzIMqy4injHhsRzF+rv5NyWT1MtZlJtE8PlEE1d HQ405t/hcx756zSa4/13dcy7CLLQoCcIBNGzy3PCRMVhXdvIU6HVWBzJkA0CZqm8qdpt f+vEAVN3fM498YpllFybnVjwLT9q1z8uUUgIY7XO6hBW/TIR39HfTUYS9YFX+/+VNEvJ YE3BgSfyjJWZS22UnXCbfYhsqwlTQh+i+Bto4u4HEIhs6Au/09hyIiYHUkex0jf4LYWl eNkA== 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 t8si2453561edy.496.2020.11.11.13.25.54; Wed, 11 Nov 2020 13:26:18 -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 S1726584AbgKKVY0 (ORCPT + 99 others); Wed, 11 Nov 2020 16:24:26 -0500 Received: from www62.your-server.de ([213.133.104.62]:39124 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725933AbgKKVYY (ORCPT ); Wed, 11 Nov 2020 16:24:24 -0500 Received: from sslproxy05.your-server.de ([78.46.172.2]) by www62.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from ) id 1kcxbB-0006uo-5g; Wed, 11 Nov 2020 22:24:13 +0100 Received: from [85.7.101.30] (helo=pc-9.home) by sslproxy05.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kcxbA-000Xzz-S4; Wed, 11 Nov 2020 22:24:12 +0100 Subject: Re: [PATCH v3 bpf] tools: bpftool: Add missing close before bpftool net attach exit To: Wang Hai , john.fastabend@gmail.com, quentin@isovalent.com, mrostecki@opensuse.org Cc: ast@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, andrii@kernel.org, kpsingh@chromium.org, toke@redhat.com, danieltimlee@gmail.com, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org References: <20201111135425.56533-1-wanghai38@huawei.com> From: Daniel Borkmann Message-ID: <6a589c0b-e2fb-5766-542b-62f40b16253a@iogearbox.net> Date: Wed, 11 Nov 2020 22:24:12 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <20201111135425.56533-1-wanghai38@huawei.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.102.4/25985/Wed Nov 11 14:18:01 2020) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/11/20 2:54 PM, Wang Hai wrote: > 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; Why is the 'err = 0' still needed here given we test for err != 0 earlier? Would just remove it, otherwise looks good. > +cleanup: > + close(progfd); > + return err; > } > > static int do_detach(int argc, char **argv) >