Re: [PATCH v5 1/4]: perf/core: use rb trees for pinned/flexible groups
From: Alexander Shishkin
Date: Wed Jul 19 2017 - 02:37:03 EST
Alexey Budankov <alexey.budankov@xxxxxxxxxxxxxxx> writes:
>>> +static void
>>> +perf_event_groups_insert(struct perf_event_groups *groups,
>>> + struct perf_event *event)
>>> +{
>>> + struct rb_node **node;
>>> + struct rb_node *parent;
>>> + struct perf_event *node_event;
>>> +
>>> + WARN_ON_ONCE(!groups || !event);
>>
>> I'm pretty sure neither of these is plausible.
>
> Used that for debugging.
It's a bad practice to keep leftovers of debugging code in the
patches. In this particular case, as with most WARN*s that I've seen in
this patchset, it is completely useless, because the code goes ahead and
dereferences the pointers right after the assert, so there'd be an oops
and we'd see it anyway.
Normally, you'd use these assertions if you're actually handling the
undesired scenario, like
/* Can't happen because XXX */
if (WARN_ON_ONCE(!groups))
return -EINVAL;
Also a comment justifying the WARN* is a good thing to have.
> Does it affect performance somehow?
It doesn't matter. Generally, we don't need an reason to remove code, we
need a reason to add code.
Regards,
--
Alex