Commit 70c78fc1 authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller

nfp: bpf: refactor nfp_bpf_check_ptr()

nfp_bpf_check_ptr() mostly looks at the pointer register.
Add a temporary variable to shorten the code.

While at it make sure we print error messages if translation
fails to help users identify the problem (to be carried in
ext_ack in due course).
Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: default avatarQuentin Monnet <quentin.monnet@netronome.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ff42bb9f
...@@ -113,17 +113,23 @@ nfp_bpf_check_exit(struct nfp_prog *nfp_prog, ...@@ -113,17 +113,23 @@ nfp_bpf_check_exit(struct nfp_prog *nfp_prog,
static int static int
nfp_bpf_check_ptr(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta, nfp_bpf_check_ptr(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta,
const struct bpf_verifier_env *env, u8 reg) const struct bpf_verifier_env *env, u8 reg_no)
{ {
if (env->cur_state.regs[reg].type != PTR_TO_CTX && const struct bpf_reg_state *reg = &env->cur_state.regs[reg_no];
env->cur_state.regs[reg].type != PTR_TO_PACKET)
if (reg->type != PTR_TO_CTX &&
reg->type != PTR_TO_PACKET) {
pr_info("unsupported ptr type: %d\n", reg->type);
return -EINVAL; return -EINVAL;
}
if (meta->ptr.type != NOT_INIT && if (meta->ptr.type != NOT_INIT && meta->ptr.type != reg->type) {
meta->ptr.type != env->cur_state.regs[reg].type) pr_info("ptr type changed for instruction %d -> %d\n",
meta->ptr.type, reg->type);
return -EINVAL; return -EINVAL;
}
meta->ptr = env->cur_state.regs[reg]; meta->ptr = *reg;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment