[PATCH] arch: nds32: Add IRQ check for platform_get_irq()

From: Jiajun Cao
Date: Wed Jun 23 2021 - 01:19:25 EST


The function cpu_pmu_request_irq() neglects to check the return
value of platform_get_irq().

The error code (a negative number) of platform_get_irq(), i.e.,
irq, will be passed to request_irq(), which will cause the function
cpu_pmu_request_irq() to fail with -EINVAL, overriding the original
error code irq.

Fix it by adding a IRQ check before calling request_irq().

Signed-off-by: Jiajun Cao <jjcao20@xxxxxxxxxxxx>
Signed-off-by: Xin Tan <tanxin.ctf@xxxxxxxxx>
---
arch/nds32/kernel/perf_event_cpu.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/arch/nds32/kernel/perf_event_cpu.c b/arch/nds32/kernel/perf_event_cpu.c
index 0ce6f9f307e6..6a6cbebaf5aa 100644
--- a/arch/nds32/kernel/perf_event_cpu.c
+++ b/arch/nds32/kernel/perf_event_cpu.c
@@ -1083,6 +1083,9 @@ static int cpu_pmu_request_irq(struct nds32_pmu *cpu_pmu, irq_handler_t handler)
}

irq = platform_get_irq(pmu_device, 0);
+ if (irq < 0)
+ return irq;
+
err = request_irq(irq, handler, IRQF_NOBALANCING, "nds32-pfm",
cpu_pmu);
if (err) {
--
2.17.1

Please check whether it's meaningful to propagate the error code of platform_get_irq() or stop calling request_irq() early when irq is invalid. Thanks!