Takashi Iwai 9fc19b
From 18d83fc611a8eb4a5ef157108cb0fd06a4d21678 Mon Sep 17 00:00:00 2001
Takashi Iwai 9fc19b
From: Jackie Liu <liuyun01@kylinos.cn>
Takashi Iwai 9fc19b
Date: Wed, 1 Sep 2021 20:35:57 +0800
Takashi Iwai 9fc19b
Subject: [PATCH] ARM: s3c: irq-s3c24xx: Fix return value check for s3c24xx_init_intc()
Takashi Iwai 9fc19b
Git-commit: 2aa717473ce96c93ae43a5dc8c23cedc8ce7dd9f
Takashi Iwai 9fc19b
Patch-mainline: v5.16-rc1
Takashi Iwai 9fc19b
References: stable-5.14.19
Takashi Iwai 9fc19b
Takashi Iwai 9fc19b
[ Upstream commit 2aa717473ce96c93ae43a5dc8c23cedc8ce7dd9f ]
Takashi Iwai 9fc19b
Takashi Iwai 9fc19b
The s3c24xx_init_intc() returns an error pointer upon failure, not NULL.
Takashi Iwai 9fc19b
let's add an error pointer check in s3c24xx_handle_irq.
Takashi Iwai 9fc19b
Takashi Iwai 9fc19b
s3c_intc[0] is not NULL or ERR, we can simplify the code.
Takashi Iwai 9fc19b
Takashi Iwai 9fc19b
Fixes: 1f629b7a3ced ("ARM: S3C24XX: transform irq handling into a declarative form")
Takashi Iwai 9fc19b
Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
Takashi Iwai 9fc19b
Link: https://lore.kernel.org/r/20210901123557.1043953-1-liu.yun@linux.dev
Takashi Iwai 9fc19b
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Takashi Iwai 9fc19b
Signed-off-by: Sasha Levin <sashal@kernel.org>
Takashi Iwai 9fc19b
Acked-by: Takashi Iwai <tiwai@suse.de>
Takashi Iwai 9fc19b
Takashi Iwai 9fc19b
---
Takashi Iwai 9fc19b
 arch/arm/mach-s3c/irq-s3c24xx.c | 22 ++++++++++++++++++----
Takashi Iwai 9fc19b
 1 file changed, 18 insertions(+), 4 deletions(-)
Takashi Iwai 9fc19b
Takashi Iwai 9fc19b
diff --git a/arch/arm/mach-s3c/irq-s3c24xx.c b/arch/arm/mach-s3c/irq-s3c24xx.c
Takashi Iwai 9fc19b
index 0c631c14a817..53081505e397 100644
Takashi Iwai 9fc19b
--- a/arch/arm/mach-s3c/irq-s3c24xx.c
Takashi Iwai 9fc19b
+++ b/arch/arm/mach-s3c/irq-s3c24xx.c
Takashi Iwai 9fc19b
@@ -362,11 +362,25 @@ static inline int s3c24xx_handle_intc(struct s3c_irq_intc *intc,
Takashi Iwai 9fc19b
 static asmlinkage void __exception_irq_entry s3c24xx_handle_irq(struct pt_regs *regs)
Takashi Iwai 9fc19b
 {
Takashi Iwai 9fc19b
 	do {
Takashi Iwai 9fc19b
-		if (likely(s3c_intc[0]))
Takashi Iwai 9fc19b
-			if (s3c24xx_handle_intc(s3c_intc[0], regs, 0))
Takashi Iwai 9fc19b
-				continue;
Takashi Iwai 9fc19b
+		/*
Takashi Iwai 9fc19b
+		 * For platform based machines, neither ERR nor NULL can happen here.
Takashi Iwai 9fc19b
+		 * The s3c24xx_handle_irq() will be set as IRQ handler iff this succeeds:
Takashi Iwai 9fc19b
+		 *
Takashi Iwai 9fc19b
+		 *    s3c_intc[0] = s3c24xx_init_intc()
Takashi Iwai 9fc19b
+		 *
Takashi Iwai 9fc19b
+		 * If this fails, the next calls to s3c24xx_init_intc() won't be executed.
Takashi Iwai 9fc19b
+		 *
Takashi Iwai 9fc19b
+		 * For DT machine, s3c_init_intc_of() could set the IRQ handler without
Takashi Iwai 9fc19b
+		 * setting s3c_intc[0] only if it was called with num_ctrl=0. There is no
Takashi Iwai 9fc19b
+		 * such code path, so again the s3c_intc[0] will have a valid pointer if
Takashi Iwai 9fc19b
+		 * set_handle_irq() is called.
Takashi Iwai 9fc19b
+		 *
Takashi Iwai 9fc19b
+		 * Therefore in s3c24xx_handle_irq(), the s3c_intc[0] is always something.
Takashi Iwai 9fc19b
+		 */
Takashi Iwai 9fc19b
+		if (s3c24xx_handle_intc(s3c_intc[0], regs, 0))
Takashi Iwai 9fc19b
+			continue;
Takashi Iwai 9fc19b
 
Takashi Iwai 9fc19b
-		if (s3c_intc[2])
Takashi Iwai 9fc19b
+		if (!IS_ERR_OR_NULL(s3c_intc[2]))
Takashi Iwai 9fc19b
 			if (s3c24xx_handle_intc(s3c_intc[2], regs, 64))
Takashi Iwai 9fc19b
 				continue;
Takashi Iwai 9fc19b
 
Takashi Iwai 9fc19b
-- 
Takashi Iwai 9fc19b
2.26.2
Takashi Iwai 9fc19b