From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9AE641C28 for ; Thu, 22 Sep 2022 01:50:58 +0000 (UTC) Received: from canpemm500010.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4MXynM6xDyz14QPC; Thu, 22 Sep 2022 09:46:47 +0800 (CST) Received: from [10.174.179.191] (10.174.179.191) by canpemm500010.china.huawei.com (7.192.105.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 22 Sep 2022 09:50:54 +0800 Message-ID: Date: Thu, 22 Sep 2022 09:50:54 +0800 Precedence: bulk X-Mailing-List: llvm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.2.0 Subject: Re: [bpf-next v3 1/2] libbpf: Add pathname_concat() helper To: Andrii Nakryiko CC: , , , , , , , , , , , , , , , , , , , , , , , References: <1663555725-17016-1-git-send-email-wangyufen@huawei.com> From: wangyufen In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.179.191] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To canpemm500010.china.huawei.com (7.192.105.118) X-CFilter-Loop: Reflected 在 2022/9/22 8:41, Andrii Nakryiko 写道: > On Sun, Sep 18, 2022 at 7:28 PM Wang Yufen wrote: >> Move snprintf and len check to common helper pathname_concat() to make the >> code simpler. >> >> Signed-off-by: Wang Yufen >> --- >> tools/lib/bpf/libbpf.c | 76 +++++++++++++++++++------------------------------- >> 1 file changed, 29 insertions(+), 47 deletions(-) >> > [...] > >> @@ -8009,14 +8012,9 @@ int bpf_object__unpin_maps(struct bpf_object *obj, const char *path) >> char buf[PATH_MAX]; >> >> if (path) { >> - int len; >> - >> - len = snprintf(buf, PATH_MAX, "%s/%s", path, >> - bpf_map__name(map)); >> - if (len < 0) >> - return libbpf_err(-EINVAL); >> - else if (len >= PATH_MAX) >> - return libbpf_err(-ENAMETOOLONG); >> + err = pathname_concat(path, bpf_map__name(map), buf, PATH_MAX); >> + if (err) >> + return err; > also keep libbpf_err() as well, it sets errno properly > >> sanitize_pin_path(buf); >> pin_path = buf; >> } else if (!map->pin_path) { >> @@ -8034,6 +8032,7 @@ int bpf_object__unpin_maps(struct bpf_object *obj, const char *path) >> int bpf_object__pin_programs(struct bpf_object *obj, const char *path) >> { >> struct bpf_program *prog; >> + char buf[PATH_MAX]; >> int err; >> >> if (!obj) > [...] Thanks for your comments, will send v4.