Skip to content

Commit

Permalink
bpf: btf: implement btf_name_valid_identifier()
Browse files Browse the repository at this point in the history
Function btf_name_valid_identifier() have been implemented in
bpf-next commit 2667a26 ("bpf: btf: Add BTF_KIND_FUNC and
BTF_KIND_FUNC_PROTO"). Backport this function so later patch
can use it.

Fixes: 69b693f ("bpf: btf: Introduce BPF Type Format (BTF)")
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
  • Loading branch information
Yonghong Song authored and Alexei Starovoitov committed Nov 29, 2018
1 parent d78a5eb commit cdbb096
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions kernel/bpf/btf.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <uapi/linux/types.h>
#include <linux/seq_file.h>
#include <linux/compiler.h>
#include <linux/ctype.h>
#include <linux/errno.h>
#include <linux/slab.h>
#include <linux/anon_inodes.h>
Expand Down Expand Up @@ -426,6 +427,30 @@ static bool btf_name_offset_valid(const struct btf *btf, u32 offset)
offset < btf->hdr.str_len;
}

/* Only C-style identifier is permitted. This can be relaxed if
* necessary.
*/
static bool btf_name_valid_identifier(const struct btf *btf, u32 offset)
{
/* offset must be valid */
const char *src = &btf->strings[offset];
const char *src_limit;

if (!isalpha(*src) && *src != '_')
return false;

/* set a limit on identifier length */
src_limit = src + KSYM_NAME_LEN;
src++;
while (*src && src < src_limit) {
if (!isalnum(*src) && *src != '_')
return false;
src++;
}

return !*src;
}

static const char *btf_name_by_offset(const struct btf *btf, u32 offset)
{
if (!offset)
Expand Down

0 comments on commit cdbb096

Please sign in to comment.