Re: [PATCH v2 bpf-next 1/6] bpf: Refactor reg_bounds_sanity_check

Mykyta Yatsenko
2026-03-24T18:16:22Z

Harishankar Vishwanathan <harishankar.vishwanathan@gmail.com> writes:

> On Mon, Mar 23, 2026 at 10:16 AM Mykyta Yatsenko
> <mykyta.yatsenko5@gmail.com> wrote:
>>
>> Paul Chaignon <paul.chaignon@gmail.com> writes:
>>
>> > From: Harishankar Vishwanathan <harishankar.vishwanathan@gmail.com>
>> >
> [...]
>> nit: maybe it's going to look simpler if you rewrite it with early return?
>> static bool const_tnum_out_of_sync_with_range_bounds(struct bpf_reg_state *reg)
>> {
>> u64 uval = reg->var_off.value;
>> s64 sval = (s64)uval;
>>
>> if (!tnum_is_const(reg->var_off))
>> return false;
>>
>> return reg->umin_value != uval || reg->umax_value != uval ||
>> reg->smin_value != sval || reg->smax_value != sval;
>> }
>
> Sounds good, this makes sense!
>
>> same principle can be applied to
>> const_subreg_tnum_out_of_sync_with_range_bounds(), which looks like a
>> very long function name, will something like
>> subreg_tnum_range_mismatch() capture the idea?
>
> It is specifically checking for a *const* tnum and range mismatch, not
> just any tnum,
> so I'd assume we want to capture that when naming.
> Perhaps we call these const_tnum_range_mismatch and
> const_tnum_range_mismatch_32?
Something like that should do, thanks!
>
> [...]
>> Other than those few nits, the change looks good.
>> >
>> > return 0;
>> > out:
>> > --
>> > 2.43.0