mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-20 05:31:15 +00:00
bpf: refactor "check_reg_arg" to eliminate code redundancy
There are a few "regs[regno]" here are there across "check_reg_arg", this patch factor it out into a simple "reg" pointer. The intention is to simplify code indentation and make the later patches in this set look cleaner. Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com> Signed-off-by: Jiong Wang <jiong.wang@netronome.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
55e7f3b5ac
commit
c342dc109a
1 changed files with 8 additions and 6 deletions
|
@ -1177,30 +1177,32 @@ static int check_reg_arg(struct bpf_verifier_env *env, u32 regno,
|
||||||
{
|
{
|
||||||
struct bpf_verifier_state *vstate = env->cur_state;
|
struct bpf_verifier_state *vstate = env->cur_state;
|
||||||
struct bpf_func_state *state = vstate->frame[vstate->curframe];
|
struct bpf_func_state *state = vstate->frame[vstate->curframe];
|
||||||
struct bpf_reg_state *regs = state->regs;
|
struct bpf_reg_state *reg, *regs = state->regs;
|
||||||
|
|
||||||
if (regno >= MAX_BPF_REG) {
|
if (regno >= MAX_BPF_REG) {
|
||||||
verbose(env, "R%d is invalid\n", regno);
|
verbose(env, "R%d is invalid\n", regno);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reg = ®s[regno];
|
||||||
if (t == SRC_OP) {
|
if (t == SRC_OP) {
|
||||||
/* check whether register used as source operand can be read */
|
/* check whether register used as source operand can be read */
|
||||||
if (regs[regno].type == NOT_INIT) {
|
if (reg->type == NOT_INIT) {
|
||||||
verbose(env, "R%d !read_ok\n", regno);
|
verbose(env, "R%d !read_ok\n", regno);
|
||||||
return -EACCES;
|
return -EACCES;
|
||||||
}
|
}
|
||||||
/* We don't need to worry about FP liveness because it's read-only */
|
/* We don't need to worry about FP liveness because it's read-only */
|
||||||
if (regno != BPF_REG_FP)
|
if (regno == BPF_REG_FP)
|
||||||
return mark_reg_read(env, ®s[regno],
|
return 0;
|
||||||
regs[regno].parent);
|
|
||||||
|
return mark_reg_read(env, reg, reg->parent);
|
||||||
} else {
|
} else {
|
||||||
/* check whether register used as dest operand can be written to */
|
/* check whether register used as dest operand can be written to */
|
||||||
if (regno == BPF_REG_FP) {
|
if (regno == BPF_REG_FP) {
|
||||||
verbose(env, "frame pointer is read only\n");
|
verbose(env, "frame pointer is read only\n");
|
||||||
return -EACCES;
|
return -EACCES;
|
||||||
}
|
}
|
||||||
regs[regno].live |= REG_LIVE_WRITTEN;
|
reg->live |= REG_LIVE_WRITTEN;
|
||||||
if (t == DST_OP)
|
if (t == DST_OP)
|
||||||
mark_reg_unknown(env, regs, regno);
|
mark_reg_unknown(env, regs, regno);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue