On Tue, 2024-03-05 at 11:46 -0800, Andrii Nakryiko wrote: [...] > bit masks just for this to save a few bytes?... > > but generally, how about we keep all this much dumber: > > for (each program) { > int use_cnt = 0; > int should_load = false; > > if (!is_struct_ops_program) > continue; > for (each map) { > if (!is_struct_ops_map) > continue; > for (each prog entry in map->st_ops->progs[]) { > if (prog != slot_prog) > continue; > use_cnt++; > if (map->autocreate) > should_load = true; > } > } > if (use_cnt) > prog->autocreate = should_load; > } > > > Sure it does a few more iterations, but we avoid unnecessary > allocation/cleanup and keep things literally working how you describe > in your comment. > > WDYT? I like the version in the patch more but ok, will switch to suggested scheme as it is a bit simpler. [...] > > + prog = map->st_ops->progs[j]; > > + if (!prog) > > + continue; > > + > > + k = prog - obj->programs; > > + if (k < 0 || k > obj->nr_programs) > > >= ? But a clever trick, I like it! Yeah, should have been >=, my bad.