Skip to content

Commit 8983b73

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
libbpf: Fix various errors and warning reported by checkpatch.pl
Fix a bunch of warnings and errors reported by checkpatch.pl, to make it easier to spot new problems. Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 1f8e2bc commit 8983b73

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void libbpf_print(enum libbpf_print_level level, const char *format, ...)
105105
err = action; \
106106
if (err) \
107107
goto out; \
108-
} while(0)
108+
} while (0)
109109

110110

111111
/* Copied from tools/perf/util/util.h */
@@ -965,8 +965,7 @@ static int bpf_object__init_user_maps(struct bpf_object *obj, bool strict)
965965
obj->path, nr_maps, data->d_size);
966966

967967
if (!data->d_size || nr_maps == 0 || (data->d_size % nr_maps) != 0) {
968-
pr_warn("unable to determine map definition size "
969-
"section %s, %d maps in %zd bytes\n",
968+
pr_warn("unable to determine map definition size section %s, %d maps in %zd bytes\n",
970969
obj->path, nr_maps, data->d_size);
971970
return -EINVAL;
972971
}
@@ -1030,12 +1029,11 @@ static int bpf_object__init_user_maps(struct bpf_object *obj, bool strict)
10301029
* incompatible.
10311030
*/
10321031
char *b;
1032+
10331033
for (b = ((char *)def) + sizeof(struct bpf_map_def);
10341034
b < ((char *)def) + map_def_sz; b++) {
10351035
if (*b != 0) {
1036-
pr_warn("maps section in %s: \"%s\" "
1037-
"has unrecognized, non-zero "
1038-
"options\n",
1036+
pr_warn("maps section in %s: \"%s\" has unrecognized, non-zero options\n",
10391037
obj->path, map_name);
10401038
if (strict)
10411039
return -EINVAL;
@@ -1073,7 +1071,8 @@ skip_mods_and_typedefs(const struct btf *btf, __u32 id, __u32 *res_id)
10731071
*/
10741072
static bool get_map_field_int(const char *map_name, const struct btf *btf,
10751073
const struct btf_type *def,
1076-
const struct btf_member *m, __u32 *res) {
1074+
const struct btf_member *m, __u32 *res)
1075+
{
10771076
const struct btf_type *t = skip_mods_and_typedefs(btf, m->type, NULL);
10781077
const char *name = btf__name_by_offset(btf, m->name_off);
10791078
const struct btf_array *arr_info;
@@ -1387,7 +1386,8 @@ static int bpf_object__init_user_btf_maps(struct bpf_object *obj, bool strict,
13871386
for (i = 0; i < vlen; i++) {
13881387
err = bpf_object__init_user_btf_map(obj, sec, i,
13891388
obj->efile.btf_maps_shndx,
1390-
data, strict, pin_root_path);
1389+
data, strict,
1390+
pin_root_path);
13911391
if (err)
13921392
return err;
13931393
}
@@ -1673,12 +1673,14 @@ static int bpf_object__elf_collect(struct bpf_object *obj, bool relaxed_maps,
16731673
if (strcmp(name, ".text") == 0)
16741674
obj->efile.text_shndx = idx;
16751675
err = bpf_object__add_program(obj, data->d_buf,
1676-
data->d_size, name, idx);
1676+
data->d_size,
1677+
name, idx);
16771678
if (err) {
16781679
char errmsg[STRERR_BUFSIZE];
1679-
char *cp = libbpf_strerror_r(-err, errmsg,
1680-
sizeof(errmsg));
1680+
char *cp;
16811681

1682+
cp = libbpf_strerror_r(-err, errmsg,
1683+
sizeof(errmsg));
16821684
pr_warn("failed to alloc program %s (%s): %s",
16831685
name, obj->path, cp);
16841686
return err;
@@ -1828,7 +1830,7 @@ static int bpf_program__record_reloc(struct bpf_program *prog,
18281830
}
18291831

18301832
if (insn->code != (BPF_LD | BPF_IMM | BPF_DW)) {
1831-
pr_warn("bpf: relocation: invalid relo for insns[%d].code 0x%x\n",
1833+
pr_warn("invalid relo for insns[%d].code 0x%x\n",
18321834
insn_idx, insn->code);
18331835
return -LIBBPF_ERRNO__RELOC;
18341836
}
@@ -2145,7 +2147,7 @@ bpf_object__probe_global_data(struct bpf_object *obj)
21452147

21462148
static int bpf_object__probe_btf_func(struct bpf_object *obj)
21472149
{
2148-
const char strs[] = "\0int\0x\0a";
2150+
static const char strs[] = "\0int\0x\0a";
21492151
/* void x(int a) {} */
21502152
__u32 types[] = {
21512153
/* int */
@@ -2171,7 +2173,7 @@ static int bpf_object__probe_btf_func(struct bpf_object *obj)
21712173

21722174
static int bpf_object__probe_btf_datasec(struct bpf_object *obj)
21732175
{
2174-
const char strs[] = "\0x\0.data";
2176+
static const char strs[] = "\0x\0.data";
21752177
/* static int a; */
21762178
__u32 types[] = {
21772179
/* int */
@@ -5112,7 +5114,7 @@ int libbpf_prog_type_by_name(const char *name, enum bpf_prog_type *prog_type,
51125114
*expected_attach_type = section_names[i].expected_attach_type;
51135115
return 0;
51145116
}
5115-
pr_warn("failed to guess program type based on ELF section name '%s'\n", name);
5117+
pr_warn("failed to guess program type from ELF section '%s'\n", name);
51165118
type_names = libbpf_get_type_names(false);
51175119
if (type_names != NULL) {
51185120
pr_info("supported section(type) names are:%s\n", type_names);
@@ -6338,7 +6340,8 @@ static struct bpf_prog_info_array_desc bpf_prog_info_array_desc[] = {
63386340

63396341
};
63406342

6341-
static __u32 bpf_prog_info_read_offset_u32(struct bpf_prog_info *info, int offset)
6343+
static __u32 bpf_prog_info_read_offset_u32(struct bpf_prog_info *info,
6344+
int offset)
63426345
{
63436346
__u32 *array = (__u32 *)info;
63446347

@@ -6347,7 +6350,8 @@ static __u32 bpf_prog_info_read_offset_u32(struct bpf_prog_info *info, int offse
63476350
return -(int)offset;
63486351
}
63496352

6350-
static __u64 bpf_prog_info_read_offset_u64(struct bpf_prog_info *info, int offset)
6353+
static __u64 bpf_prog_info_read_offset_u64(struct bpf_prog_info *info,
6354+
int offset)
63516355
{
63526356
__u64 *array = (__u64 *)info;
63536357

0 commit comments

Comments
 (0)