Skip to contentSkip to conversation

power: supply: axp288_charger: Fix unchecked return value

PATCH In review Gustavo A. R. Silva 3 participants 3 messages Mar 18, 2019 – Apr 5, 2019

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

PATCH 1/1 power: supply: axp288_charger: Fix unchecked return value

Currently there is no check on platform_get_irq() return value in case it fails, hence never actually reporting any errors and causing unexpected behavior when using such value as argument for function regmap_irq_get_virq().

Fix this by adding a proper check, a message reporting any errors and returning *pirq*

Addresses-Coverity-ID: 1443940 ("Improper use of negative value")

Fixes 843735b788a4 ("power: axp288_charger: axp288 charger driver")
---
 drivers/power/supply/axp288_charger.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/power/supply/axp288_charger.c +4 -0
index f8c6da9277b3..00b961890a38 100644
@@ -833,6 +833,10 @@ static int axp288_charger_probe(struct platform_device *pdev)
 	/* Register charger interrupts */
 	for (i = 0; i < CHRG_INTR_END; i++) {
 		pirq = platform_get_irq(info->pdev, i);
+		if (pirq < 0) {
+			dev_err(&pdev->dev, "Failed to get IRQ: %d\n", pirq);
+			return pirq;
+		}
 		info->irq[i] = regmap_irq_get_virq(info->regmap_irqc, pirq);
 		if (info->irq[i] < 0) {
 			dev_warn(&info->pdev->dev,
Signature · 1 line
2.21.0
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 22 lines · Gustavo A. R. Silva

Currently there is no check on platform_get_irq() return value in case it fails, hence never actually reporting any errors and causing unexpected behavior when using such value as argument for function regmap_irq_get_virq().

Fix this by adding a proper check, a message reporting any errors and returning *pirq*

Addresses-Coverity-ID: 1443940 ("Improper use of negative value")

Fixes 843735b788a4 ("power: axp288_charger: axp288 charger driver")
---
  drivers/power/supply/axp288_charger.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/power/supply/axp288_charger.c +0 -0
index f8c6da9277b3..00b961890a38 100644

drivers/power/supply/axp288_charger.c static int axp288_charger_probe(struct platform_device *pdev) · line 842

Quoted 10 lines
drivers/power/supply/axp288_charger.c +4 -0
@@ -833,6 +833,10 @@ static int axp288_charger_probe(struct platform_device *pdev)
  	/* Register charger interrupts */
  	for (i = 0; i < CHRG_INTR_END; i++) {
  		pirq = platform_get_irq(info->pdev, i);
+		if (pirq < 0) {
+			dev_err(&pdev->dev, "Failed to get IRQ: %d\n", pirq);
+			return pirq;
+		}
  		info->irq[i] = regmap_irq_get_virq(info->regmap_irqc, pirq);
  		if (info->irq[i] < 0) {
  			dev_warn(&info->pdev->dev,

Patch looks good to me:

Regards,

Hans

#2 lore raw

Hi,

Quoted 38 lines · Hans de Goede

Hi,

Quoted 22 lines · Gustavo A. R. Silva

Currently there is no check on platform_get_irq() return value in case it fails, hence never actually reporting any errors and causing unexpected behavior when using such value as argument for function regmap_irq_get_virq().

Fix this by adding a proper check, a message reporting any errors and returning *pirq*

Addresses-Coverity-ID: 1443940 ("Improper use of negative value")

Fixes 843735b788a4 ("power: axp288_charger: axp288 charger driver")
---
  drivers/power/supply/axp288_charger.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/power/supply/axp288_charger.c +0 -0
index f8c6da9277b3..00b961890a38 100644

drivers/power/supply/axp288_charger.c static int axp288_charger_probe(struct platform_device *pdev) · line 842

Quoted 10 lines
drivers/power/supply/axp288_charger.c +4 -0
@@ -833,6 +833,10 @@ static int axp288_charger_probe(struct platform_device *pdev)
  	/* Register charger interrupts */
  	for (i = 0; i < CHRG_INTR_END; i++) {
  		pirq = platform_get_irq(info->pdev, i);
+		if (pirq < 0) {
+			dev_err(&pdev->dev, "Failed to get IRQ: %d\n", pirq);
+			return pirq;
+		}
  		info->irq[i] = regmap_irq_get_virq(info->regmap_irqc, pirq);
  		if (info->irq[i] < 0) {
  			dev_warn(&info->pdev->dev,

Patch looks good to me:

Quoted 1 line

Thanks, queued.

-- Sebastian