lkml.org 
[lkml]   [2022]   [Sep]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [bpf-next v3 1/2] libbpf: Add pathname_concat() helper
From

在 2022/9/22 8:41, Andrii Nakryiko 写道:
> On Sun, Sep 18, 2022 at 7:28 PM Wang Yufen <wangyufen@huawei.com> wrote:
>> Move snprintf and len check to common helper pathname_concat() to make the
>> code simpler.
>>
>> Signed-off-by: Wang Yufen <wangyufen@huawei.com>
>> ---
>> 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.


\
 
 \ /
  Last update: 2022-09-22 03:51    [W:0.053 / U:1.172 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site