ARC: perf: redo the pct irq missing in device-tree handling
authorVineet Gupta <vgupta@synopsys.com>
Thu, 22 Oct 2020 10:16:22 +0000 (03:16 -0700)
committerVineet Gupta <vgupta@synopsys.com>
Thu, 22 Oct 2020 17:57:58 +0000 (10:57 -0700)
commit8c42a5c02bec6c7eccf08957be3c6c8fccf9790b
treebaaec812df674806c3e7e1f6ce5e3e4534a5b997
parent6364d1b41cc382db3b03cf33c57b6007ee8f09cf
ARC: perf: redo the pct irq missing in device-tree handling

commit feb92d7d3813456c11dce21 "(ARC: perf: don't bail setup if pct irq
missing in device-tree)" introduced a silly brown-paper bag bug:
The assignment and comparison in an if statement were not bracketed
correctly leaving the order of evaluation undefined.

|
| if (has_interrupts && (irq = platform_get_irq(pdev, 0) >= 0)) {
|                           ^^^                         ^^^^

And given such a chance, the compiler will bite you hard, fully entitled
to generating this piece of beauty:

|
| # if (has_interrupts && (irq = platform_get_irq(pdev, 0) >= 0)) {
|
| bl.d @platform_get_irq  <-- irq returned in r0
|
| setge r2, r0, 0    <-- r2 is bool 1 or 0 if irq >= 0 true/false
| brlt.d r0, 0, @.L114
|
| st_s r2,[sp]     <-- irq saved is bool 1 or 0, not actual return val
| st 1,[r3,160]    # arc_pmu.18_29->irq <-- drops bool and assumes 1
|
| # return __request_percpu_irq(irq, handler, 0,
|
| bl.d @__request_percpu_irq;
| mov_s r0,1    <-- drops even bool and assumes 1 which fails

With the snafu fixed, everything is as expected.

| bl.d @platform_get_irq <-- returns irq in r0
|
| mov_s r2,r0
| brlt.d r2, 0, @.L112
|
| st_s r0,[sp] <-- irq isaved is actual return value above
| st r0,[r13,160] #arc_pmu.18_27->irq
|
| bl.d @__request_percpu_irq <-- r0 unchanged so actual irq returned
| add r4,r4,r12 #, tmp363, __ptr

Cc: <stable@vger.kernel.org>
Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
arch/arc/kernel/perf_event.c