return &env->explored_states[(idx ^ state->callsite) % state_htab_size(env)];
 }
 
+static bool same_callsites(struct bpf_verifier_state *a, struct bpf_verifier_state *b)
+{
+       int fr;
+
+       if (a->curframe != b->curframe)
+               return false;
+
+       for (fr = a->curframe; fr >= 0; fr--)
+               if (a->frame[fr]->callsite != b->frame[fr]->callsite)
+                       return false;
+
+       return true;
+}
+
 static void update_branch_counts(struct bpf_verifier_env *env, struct bpf_verifier_state *st)
 {
        while (st) {
                              struct bpf_verifier_state *cur)
 {
        struct bpf_verifier_state_list *sl;
-       int i;
 
        sl = *explored_state(env, insn);
        while (sl) {
                if (sl->state.branches)
                        goto next;
                if (sl->state.insn_idx != insn ||
-                   sl->state.curframe != cur->curframe)
+                   !same_callsites(&sl->state, cur))
                        goto next;
-               for (i = 0; i <= cur->curframe; i++)
-                       if (sl->state.frame[i]->callsite != cur->frame[i]->callsite)
-                               goto next;
                clean_verifier_state(env, &sl->state);
 next:
                sl = sl->next;