Re: [RFC PATCH v3 09/37] bpf tools: Open eBPF object file and do basic validation

From: Alexei Starovoitov
Date: Mon May 18 2015 - 14:06:12 EST


On 5/17/15 3:56 AM, Wang Nan wrote:
This patch adds basic 'struct bpf_object' which will be used for eBPF
object file loading. eBPF object files are compiled by LLVM as ELF
format. In this patch, libelf is used to open those files, read EHDR
and do basic validation according to e_type and e_machine.

All elf related staffs are grouped together and reside in elf field of
'struct bpf_object'. bpf_obj_clear_elf() is introduced to clear it.

Signed-off-by: Wang Nan <wangnan0@xxxxxxxxxx>
---
...
+static void bpf_obj_clear_elf(struct bpf_object *obj)
+{
+ if (!obj_elf_valid(obj))
+ return;
+
+ if (obj->elf.elf) {
+ elf_end(obj->elf.elf);
+ obj->elf.elf = NULL;

the name of the function is odd.
'..clear_elf' ? Only because the field was named 'elf' ?
Also obj->elf.elf looks unbalanced.

may be bpf_obj_elf_finish() to match bpf_obj_elf_init()
and obj->efile.elf ?

+ }
+ if (obj->elf.fd >= 0) {
+ close(obj->elf.fd);

and the above will change to obj->efile.fd ?

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/