On Wed, Jun 12, 2019 at 10:09 AM Dan Carpenter <dan.carpenter@xxxxxxxxxx> 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