From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754149AbbERSGJ (ORCPT ); Mon, 18 May 2015 14:06:09 -0400 Received: from mail-ie0-f177.google.com ([209.85.223.177]:34452 "EHLO mail-ie0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751177AbbERSGF (ORCPT ); Mon, 18 May 2015 14:06:05 -0400 Message-ID: <555A2A09.6090504@plumgrid.com> Date: Mon, 18 May 2015 11:06:01 -0700 From: Alexei Starovoitov User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Wang Nan , paulus@samba.org, a.p.zijlstra@chello.nl, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, jolsa@kernel.org, dsahern@gmail.com, daniel@iogearbox.net, brendan.d.gregg@gmail.com, masami.hiramatsu.pt@hitachi.com CC: lizefan@huawei.com, linux-kernel@vger.kernel.org, pi3orama@163.com Subject: Re: [RFC PATCH v3 09/37] bpf tools: Open eBPF object file and do basic validation References: <1431860222-61636-1-git-send-email-wangnan0@huawei.com> <1431860222-61636-10-git-send-email-wangnan0@huawei.com> In-Reply-To: <1431860222-61636-10-git-send-email-wangnan0@huawei.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- ... > +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 ?