* [bug report] libbpf: use negative fd to specify missing BTF
@ 2019-06-12 11:51 Dan Carpenter
2019-06-13 4:51 ` Andrii Nakryiko
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2019-06-12 11:51 UTC (permalink / raw)
To: andriin; +Cc: bpf
Hello Andrii Nakryiko,
The patch fba01a0689a9: "libbpf: use negative fd to specify missing
BTF" from May 29, 2019, leads to the following static checker warning:
./tools/lib/bpf/libbpf.c:1757 bpf_object__create_maps()
warn: always true condition '(create_attr.btf_fd >= 0) => (0-u32max >= 0)'
./tools/lib/bpf/libbpf.c
1735 if (obj->caps.name)
1736 create_attr.name = map->name;
1737 create_attr.map_ifindex = map->map_ifindex;
1738 create_attr.map_type = def->type;
1739 create_attr.map_flags = def->map_flags;
1740 create_attr.key_size = def->key_size;
1741 create_attr.value_size = def->value_size;
1742 create_attr.max_entries = def->max_entries;
1743 create_attr.btf_fd = -1;
^^^^^^^^^^^^^^^^^^^^^^^
.btf_fd is a __u32
1744 create_attr.btf_key_type_id = 0;
1745 create_attr.btf_value_type_id = 0;
1746 if (bpf_map_type__is_map_in_map(def->type) &&
1747 map->inner_map_fd >= 0)
1748 create_attr.inner_map_fd = map->inner_map_fd;
1749
1750 if (obj->btf && !bpf_map_find_btf_info(map, obj->btf)) {
1751 create_attr.btf_fd = btf__fd(obj->btf);
1752 create_attr.btf_key_type_id = map->btf_key_type_id;
1753 create_attr.btf_value_type_id = map->btf_value_type_id;
1754 }
1755
1756 *pfd = bpf_create_map_xattr(&create_attr);
1757 if (*pfd < 0 && create_attr.btf_fd >= 0) {
^^^^^^^^^^^^^^^^^^^^^^^
Always true condition.
1758 cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg));
1759 pr_warning("Error in bpf_create_map_xattr(%s):%s(%d). Retrying without BTF.\n",
1760 map->name, cp, errno);
1761 create_attr.btf_fd = -1;
1762 create_attr.btf_key_type_id = 0;
1763 create_attr.btf_value_type_id = 0;
1764 map->btf_key_type_id = 0;
1765 map->btf_value_type_id = 0;
1766 *pfd = bpf_create_map_xattr(&create_attr);
1767 }
regards,
dan carpenter
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [bug report] libbpf: use negative fd to specify missing BTF
2019-06-12 11:51 [bug report] libbpf: use negative fd to specify missing BTF Dan Carpenter
@ 2019-06-13 4:51 ` Andrii Nakryiko
0 siblings, 0 replies; 2+ messages in thread
From: Andrii Nakryiko @ 2019-06-13 4:51 UTC (permalink / raw)
To: Dan Carpenter; +Cc: Andrii Nakryiko, bpf
On Wed, Jun 12, 2019 at 10:09 AM Dan Carpenter <dan.carpenter@oracle.com> wrote:
>
> Hello Andrii Nakryiko,
>
> The patch fba01a0689a9: "libbpf: use negative fd to specify missing
> BTF" from May 29, 2019, leads to the following static checker warning:
>
> ./tools/lib/bpf/libbpf.c:1757 bpf_object__create_maps()
> warn: always true condition '(create_attr.btf_fd >= 0) => (0-u32max >= 0)'
>
Thanks for reporting this! I'll post a fix shortly.
> ./tools/lib/bpf/libbpf.c
> 1735 if (obj->caps.name)
> 1736 create_attr.name = map->name;
> 1737 create_attr.map_ifindex = map->map_ifindex;
> 1738 create_attr.map_type = def->type;
> 1739 create_attr.map_flags = def->map_flags;
> 1740 create_attr.key_size = def->key_size;
> 1741 create_attr.value_size = def->value_size;
> 1742 create_attr.max_entries = def->max_entries;
> 1743 create_attr.btf_fd = -1;
> ^^^^^^^^^^^^^^^^^^^^^^^
> .btf_fd is a __u32
>
> 1744 create_attr.btf_key_type_id = 0;
> 1745 create_attr.btf_value_type_id = 0;
> 1746 if (bpf_map_type__is_map_in_map(def->type) &&
> 1747 map->inner_map_fd >= 0)
> 1748 create_attr.inner_map_fd = map->inner_map_fd;
> 1749
> 1750 if (obj->btf && !bpf_map_find_btf_info(map, obj->btf)) {
> 1751 create_attr.btf_fd = btf__fd(obj->btf);
> 1752 create_attr.btf_key_type_id = map->btf_key_type_id;
> 1753 create_attr.btf_value_type_id = map->btf_value_type_id;
> 1754 }
> 1755
> 1756 *pfd = bpf_create_map_xattr(&create_attr);
> 1757 if (*pfd < 0 && create_attr.btf_fd >= 0) {
> ^^^^^^^^^^^^^^^^^^^^^^^
> Always true condition.
>
> 1758 cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg));
> 1759 pr_warning("Error in bpf_create_map_xattr(%s):%s(%d). Retrying without BTF.\n",
> 1760 map->name, cp, errno);
> 1761 create_attr.btf_fd = -1;
> 1762 create_attr.btf_key_type_id = 0;
> 1763 create_attr.btf_value_type_id = 0;
> 1764 map->btf_key_type_id = 0;
> 1765 map->btf_value_type_id = 0;
> 1766 *pfd = bpf_create_map_xattr(&create_attr);
> 1767 }
>
> regards,
> dan carpenter
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-06-13 16:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-12 11:51 [bug report] libbpf: use negative fd to specify missing BTF Dan Carpenter
2019-06-13 4:51 ` Andrii Nakryiko
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.