Subject: [PATCH 1/3] powerpc/xive: Don't call cpu_online() on an invalid CPU number

From: Benjamin Herrenschmidt <[email-masked]>
Date: Mon, 10 Apr 2017 16:23:19 +1000

If the interrupt didn't have a selected target yet, we could
call cpu_online() and do other cpumask tests with cpu #-1 which
would result in random outcomes.

Signed-off-by: Benjamin Herrenschmidt <[email-masked]>
---
 arch/powerpc/sysdev/xive/common.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/sysdev/xive/common.c b/arch/powerpc/sysdev/xive/common.c
index 006a53e..dbbe446 100644
--- a/arch/powerpc/sysdev/xive/common.c
+++ b/arch/powerpc/sysdev/xive/common.c
@@ -662,7 +662,8 @@ static int xive_irq_set_affinity(struct irq_data *d,
 	 * If existing target is already in the new mask, and is
 	 * online then do nothing.
 	 */
-	if (cpu_online(xd->target) &&
+	if (xd->target != XIVE_INVALID_TARGET &&
+	    cpu_online(xd->target) &&
 	    cpumask_test_cpu(xd->target, cpumask))
 		return IRQ_SET_MASK_OK;
 
-- 
2.9.3