3 ms·
Question, isn't this a bug? static enum hrtimer_restart perf_swevent_hrtimer(struct hrtimer *hrtimer) { - if (event->state != PERF_EVENT_STATE_ACTIVE
by ChuckMcM 10mo ago
Question, isn't this a bug?
static enum hrtimer_restart perf_swevent_hrtimer(struct hrtimer *hrtimer)
{
- if (event->state != PERF_EVENT_STATE_ACTIVE)
+ if (event->state != PERF_EVENT_STATE_ACTIVE ||
+ event->hw.state & PERF_HES_STOPPED)
return HRTIMER_NORESTART;
The bug being that the precedence of || is higher than the precedence of != ?
Consider writing it
if ((event->state != PERF_EVENT_STATE_ACTIVE) ||
(event->hw_state & PERF_HES_STOPPED))
This coming from a person who has too many scars from not parenthesizing my expressions in conditionals to ensure they work the way I meant them to work.
- jerrinot 10mo agoWow, someone is actually reading the article in detail, that's a good feeling! In C, the != operator has higher precedence than the || operator. That said, extra parentheses never hurt readability.
- unsnap_biceps 10mo agoWhich language(s?) have || before !=/==?
- anematode 10mo agoLikely they're confusing it with bitwise OR, since in C, a | b == c parses as a | (b == c), causing widespread pain.