On Fri, Apr 23, 2021 at 9:31 AM Andrii Nakryiko
[off-list ref] wrote:
quoted
quoted
static int remap_type_id(__u32 *type_id, void *ctx)
{
int *id_map = ctx;
int new_id = id_map[*type_id];
/* Here VOID stays VOID, that's all */
if (*type_id == 0)
return 0;
Does it mean that id_map[0] is a garbage value?
and all other code that might be doing id_map[idx] might be reading
garbage if it doesn't have a check for idx == 0 ?
No, id_map[0] == 0 by construction (id_map is obj->btf_type_map and is
calloc()'ed) and can be used as id_map[idx].
Ok. Then why are you insisting on this micro optimization to return 0
directly?
That's the confusing part for me.
If it was:
"if (new_id == 0 && *type_id != 0) { pr_warn"
Then it would be clear what error condition is about.
But 'return 0' messing things up in my mind,
because it's far from obvious that first check is really a combination
with the 2nd check and by itself it's a micro optimization to avoid
reading id_map[0].