aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/bpf/libbpf.c
diff options
context:
space:
mode:
authorAndrii Nakryiko <andriin@fb.com>2019-05-29 13:36:11 -0400
committerDaniel Borkmann <daniel@iogearbox.net>2019-05-29 19:23:35 -0400
commit399dc65e9ca0c35c8ceea7130b25e7be8f229a52 (patch)
treea7484f753b889ec13a466bc810519ac11bf953e3 /tools/lib/bpf/libbpf.c
parent76e1022b9653b5b5254e2f99ac467354b9c08de6 (diff)
libbpf: reduce unnecessary line wrapping
There are a bunch of lines of code or comments that are unnecessary wrapped into multi-lines. Fix that without violating any code guidelines. Acked-by: Song Liu <songliubraving@fb.com> Signed-off-by: Andrii Nakryiko <andriin@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'tools/lib/bpf/libbpf.c')
-rw-r--r--tools/lib/bpf/libbpf.c52
1 files changed, 16 insertions, 36 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index a889925ecbcb..ba89d9727137 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -497,8 +497,7 @@ static struct bpf_object *bpf_object__new(const char *path,
497 497
498 strcpy(obj->path, path); 498 strcpy(obj->path, path);
499 /* Using basename() GNU version which doesn't modify arg. */ 499 /* Using basename() GNU version which doesn't modify arg. */
500 strncpy(obj->name, basename((void *)path), 500 strncpy(obj->name, basename((void *)path), sizeof(obj->name) - 1);
501 sizeof(obj->name) - 1);
502 end = strchr(obj->name, '.'); 501 end = strchr(obj->name, '.');
503 if (end) 502 if (end)
504 *end = 0; 503 *end = 0;
@@ -578,15 +577,13 @@ static int bpf_object__elf_init(struct bpf_object *obj)
578 } 577 }
579 578
580 if (!obj->efile.elf) { 579 if (!obj->efile.elf) {
581 pr_warning("failed to open %s as ELF file\n", 580 pr_warning("failed to open %s as ELF file\n", obj->path);
582 obj->path);
583 err = -LIBBPF_ERRNO__LIBELF; 581 err = -LIBBPF_ERRNO__LIBELF;
584 goto errout; 582 goto errout;
585 } 583 }
586 584
587 if (!gelf_getehdr(obj->efile.elf, &obj->efile.ehdr)) { 585 if (!gelf_getehdr(obj->efile.elf, &obj->efile.ehdr)) {
588 pr_warning("failed to get EHDR from %s\n", 586 pr_warning("failed to get EHDR from %s\n", obj->path);
589 obj->path);
590 err = -LIBBPF_ERRNO__FORMAT; 587 err = -LIBBPF_ERRNO__FORMAT;
591 goto errout; 588 goto errout;
592 } 589 }
@@ -622,18 +619,15 @@ static int bpf_object__check_endianness(struct bpf_object *obj)
622} 619}
623 620
624static int 621static int
625bpf_object__init_license(struct bpf_object *obj, 622bpf_object__init_license(struct bpf_object *obj, void *data, size_t size)
626 void *data, size_t size)
627{ 623{
628 memcpy(obj->license, data, 624 memcpy(obj->license, data, min(size, sizeof(obj->license) - 1));
629 min(size, sizeof(obj->license) - 1));
630 pr_debug("license of %s is %s\n", obj->path, obj->license); 625 pr_debug("license of %s is %s\n", obj->path, obj->license);
631 return 0; 626 return 0;
632} 627}
633 628
634static int 629static int
635bpf_object__init_kversion(struct bpf_object *obj, 630bpf_object__init_kversion(struct bpf_object *obj, void *data, size_t size)
636 void *data, size_t size)
637{ 631{
638 __u32 kver; 632 __u32 kver;
639 633
@@ -643,8 +637,7 @@ bpf_object__init_kversion(struct bpf_object *obj,
643 } 637 }
644 memcpy(&kver, data, sizeof(kver)); 638 memcpy(&kver, data, sizeof(kver));
645 obj->kern_version = kver; 639 obj->kern_version = kver;
646 pr_debug("kernel version of %s is %x\n", obj->path, 640 pr_debug("kernel version of %s is %x\n", obj->path, obj->kern_version);
647 obj->kern_version);
648 return 0; 641 return 0;
649} 642}
650 643
@@ -800,8 +793,7 @@ bpf_object__init_internal_map(struct bpf_object *obj, struct bpf_map *map,
800 def->key_size = sizeof(int); 793 def->key_size = sizeof(int);
801 def->value_size = data->d_size; 794 def->value_size = data->d_size;
802 def->max_entries = 1; 795 def->max_entries = 1;
803 def->map_flags = type == LIBBPF_MAP_RODATA ? 796 def->map_flags = type == LIBBPF_MAP_RODATA ? BPF_F_RDONLY_PROG : 0;
804 BPF_F_RDONLY_PROG : 0;
805 if (data_buff) { 797 if (data_buff) {
806 *data_buff = malloc(data->d_size); 798 *data_buff = malloc(data->d_size);
807 if (!*data_buff) { 799 if (!*data_buff) {
@@ -816,8 +808,7 @@ bpf_object__init_internal_map(struct bpf_object *obj, struct bpf_map *map,
816 return 0; 808 return 0;
817} 809}
818 810
819static int 811static int bpf_object__init_maps(struct bpf_object *obj, int flags)
820bpf_object__init_maps(struct bpf_object *obj, int flags)
821{ 812{
822 int i, map_idx, map_def_sz = 0, nr_syms, nr_maps = 0, nr_maps_glob = 0; 813 int i, map_idx, map_def_sz = 0, nr_syms, nr_maps = 0, nr_maps_glob = 0;
823 bool strict = !(flags & MAPS_RELAX_COMPAT); 814 bool strict = !(flags & MAPS_RELAX_COMPAT);
@@ -1098,8 +1089,7 @@ static int bpf_object__elf_collect(struct bpf_object *obj, int flags)
1098 1089
1099 /* Elf is corrupted/truncated, avoid calling elf_strptr. */ 1090 /* Elf is corrupted/truncated, avoid calling elf_strptr. */
1100 if (!elf_rawdata(elf_getscn(elf, ep->e_shstrndx), NULL)) { 1091 if (!elf_rawdata(elf_getscn(elf, ep->e_shstrndx), NULL)) {
1101 pr_warning("failed to get e_shstrndx from %s\n", 1092 pr_warning("failed to get e_shstrndx from %s\n", obj->path);
1102 obj->path);
1103 return -LIBBPF_ERRNO__FORMAT; 1093 return -LIBBPF_ERRNO__FORMAT;
1104 } 1094 }
1105 1095
@@ -1340,8 +1330,7 @@ bpf_program__collect_reloc(struct bpf_program *prog, GElf_Shdr *shdr,
1340 size_t nr_maps = obj->nr_maps; 1330 size_t nr_maps = obj->nr_maps;
1341 int i, nrels; 1331 int i, nrels;
1342 1332
1343 pr_debug("collecting relocating info for: '%s'\n", 1333 pr_debug("collecting relocating info for: '%s'\n", prog->section_name);
1344 prog->section_name);
1345 nrels = shdr->sh_size / shdr->sh_entsize; 1334 nrels = shdr->sh_size / shdr->sh_entsize;
1346 1335
1347 prog->reloc_desc = malloc(sizeof(*prog->reloc_desc) * nrels); 1336 prog->reloc_desc = malloc(sizeof(*prog->reloc_desc) * nrels);
@@ -1366,9 +1355,7 @@ bpf_program__collect_reloc(struct bpf_program *prog, GElf_Shdr *shdr,
1366 return -LIBBPF_ERRNO__FORMAT; 1355 return -LIBBPF_ERRNO__FORMAT;
1367 } 1356 }
1368 1357
1369 if (!gelf_getsym(symbols, 1358 if (!gelf_getsym(symbols, GELF_R_SYM(rel.r_info), &sym)) {
1370 GELF_R_SYM(rel.r_info),
1371 &sym)) {
1372 pr_warning("relocation: symbol %"PRIx64" not found\n", 1359 pr_warning("relocation: symbol %"PRIx64" not found\n",
1373 GELF_R_SYM(rel.r_info)); 1360 GELF_R_SYM(rel.r_info));
1374 return -LIBBPF_ERRNO__FORMAT; 1361 return -LIBBPF_ERRNO__FORMAT;
@@ -1817,18 +1804,14 @@ check_btf_ext_reloc_err(struct bpf_program *prog, int err,
1817 if (btf_prog_info) { 1804 if (btf_prog_info) {
1818 /* 1805 /*
1819 * Some info has already been found but has problem 1806 * Some info has already been found but has problem
1820 * in the last btf_ext reloc. Must have to error 1807 * in the last btf_ext reloc. Must have to error out.
1821 * out.
1822 */ 1808 */
1823 pr_warning("Error in relocating %s for sec %s.\n", 1809 pr_warning("Error in relocating %s for sec %s.\n",
1824 info_name, prog->section_name); 1810 info_name, prog->section_name);
1825 return err; 1811 return err;
1826 } 1812 }
1827 1813
1828 /* 1814 /* Have problem loading the very first info. Ignore the rest. */
1829 * Have problem loading the very first info. Ignore
1830 * the rest.
1831 */
1832 pr_warning("Cannot find %s for main program sec %s. Ignore all %s.\n", 1815 pr_warning("Cannot find %s for main program sec %s. Ignore all %s.\n",
1833 info_name, prog->section_name, info_name); 1816 info_name, prog->section_name, info_name);
1834 return 0; 1817 return 0;
@@ -2032,9 +2015,7 @@ static int bpf_object__collect_reloc(struct bpf_object *obj)
2032 return -LIBBPF_ERRNO__RELOC; 2015 return -LIBBPF_ERRNO__RELOC;
2033 } 2016 }
2034 2017
2035 err = bpf_program__collect_reloc(prog, 2018 err = bpf_program__collect_reloc(prog, shdr, data, obj);
2036 shdr, data,
2037 obj);
2038 if (err) 2019 if (err)
2039 return err; 2020 return err;
2040 } 2021 }
@@ -2354,8 +2335,7 @@ struct bpf_object *bpf_object__open_buffer(void *obj_buf,
2354 (unsigned long)obj_buf_sz); 2335 (unsigned long)obj_buf_sz);
2355 name = tmp_name; 2336 name = tmp_name;
2356 } 2337 }
2357 pr_debug("loading object '%s' from buffer\n", 2338 pr_debug("loading object '%s' from buffer\n", name);
2358 name);
2359 2339
2360 return __bpf_object__open(name, obj_buf, obj_buf_sz, true, true); 2340 return __bpf_object__open(name, obj_buf, obj_buf_sz, true, true);
2361} 2341}