Skip to contentSkip to conversation

gpio: loongson-64bit: Fix a less than zero check on an unsigned int struct field

PATCH Applied Colin Ian King 4 participants 4 messages Sep 9, 2025 – Sep 10, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: loongson-64bit: Fix a less than zero check on an unsigned int struct field

Currently the error check from the call to platform_get_irq is always false because an unsigned int chip->irq.parents[i] is being used to to perform the less than zero error check. Fix this by using the int variable ret to perform the check.

Fixes 03c146cb6cd1 ("gpio: loongson-64bit: Add support for Loongson-2K0300 SoC")
---
 drivers/gpio/gpio-loongson-64bit.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpio/gpio-loongson-64bit.c +6 -3
index f84f8c537249..24b7219db34a 100644
@@ -267,10 +267,13 @@ static int loongson_gpio_init_irqchip(struct platform_device *pdev,
 		return -ENOMEM;
 
 	for (i = 0; i < data->intr_num; i++) {
-		chip->irq.parents[i] = platform_get_irq(pdev, i);
-		if (chip->irq.parents[i] < 0)
-			return dev_err_probe(&pdev->dev, chip->irq.parents[i],
+		int ret;
+
+		ret = platform_get_irq(pdev, i);
+		if (ret < 0)
+			return dev_err_probe(&pdev->dev, ret,
 					     "failed to get IRQ %d\n", i);
+		chip->irq.parents[i] = ret;
 	}
 
 	for (i = 0; i < data->intr_num; i++) {
Signature · 1 line
2.51.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Colin Ian King

Currently the error check from the call to platform_get_irq is always false because an unsigned int chip->irq.parents[i] is being used to to perform the less than zero error check. Fix this by using the int variable ret to perform the check.

Fixes 03c146cb6cd1 ("gpio: loongson-64bit: Add support for Loongson-2K0300 SoC")
---
 drivers/gpio/gpio-loongson-64bit.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Thanks for catching this,

Quoted 24 lines
drivers/gpio/gpio-loongson-64bit.c +6 -3
index f84f8c537249..24b7219db34a 100644
@@ -267,10 +267,13 @@ static int loongson_gpio_init_irqchip(struct platform_device *pdev,
 		return -ENOMEM;
 
 	for (i = 0; i < data->intr_num; i++) {
-		chip->irq.parents[i] = platform_get_irq(pdev, i);
-		if (chip->irq.parents[i] < 0)
-			return dev_err_probe(&pdev->dev, chip->irq.parents[i],
+		int ret;
+
+		ret = platform_get_irq(pdev, i);
+		if (ret < 0)
+			return dev_err_probe(&pdev->dev, ret,
 					     "failed to get IRQ %d\n", i);
+		chip->irq.parents[i] = ret;
 	}
 
 	for (i = 0; i < data->intr_num; i++) {
Signature · 1 line
2.51.0
Reviewed-by on v1 1/1
#2 lore raw
In reply to Colin Ian King

Hi, Colin,

Quoted 18 lines · Colin Ian King

Currently the error check from the call to platform_get_irq is always false because an unsigned int chip->irq.parents[i] is being used to to perform the less than zero error check. Fix this by using the int variable ret to perform the check.

Fixes 03c146cb6cd1 ("gpio: loongson-64bit: Add support for Loongson-2K0300 SoC")
---
 drivers/gpio/gpio-loongson-64bit.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpio/gpio-loongson-64bit.c +0 -0
index f84f8c537249..24b7219db34a 100644
@@ -267,10 +267,13 @@ static int loongson_gpio_init_irqchip(struct platform_device *pdev,
                return -ENOMEM;

drivers/gpio/gpio-loongson-64bit.c static int loongson_gpio_init_irqchip(struct platform_device *pdev, · line 274

Quoted 10 lines
drivers/gpio/gpio-loongson-64bit.c +5 -3
 
        for (i = 0; i < data->intr_num; i++) {
-               chip->irq.parents[i] = platform_get_irq(pdev, i);
-               if (chip->irq.parents[i] < 0)
-                       return dev_err_probe(&pdev->dev, chip->irq.parents[i],
+               int ret;
+
+               ret = platform_get_irq(pdev, i);
+               if (ret < 0)
+                       return dev_err_probe(&pdev->dev, ret,

Then this line becomes short enough, and the "return ..." can be in one line.

Quoted 8 lines
drivers/gpio/gpio-loongson-64bit.c +1 -1
                                             "failed to get IRQ %d\n", i);
+               chip->irq.parents[i] = ret;
        }
 
        for (i = 0; i < data->intr_num; i++) {
--

2.51.0

#3 lore raw
In reply to Colin Ian King

From: Bartosz Golaszewski <[email protected]>

Quoted 6 lines · Colin Ian King

Currently the error check from the call to platform_get_irq is always false because an unsigned int chip->irq.parents[i] is being used to to perform the less than zero error check. Fix this by using the int variable ret to perform the check.

Applied, thanks!

[1/1] gpio: loongson-64bit: Fix a less than zero check on an unsigned int struct field

      https://git.kernel.org/brgl/linux/c/4c91b0ee35db07ae017dce067c64364c7e95faae

Best regards,

Signature · 1 line
Bartosz Golaszewski <[email protected]>