Skip to contentSkip to conversation

extcon: max77693: Fix max77693_muic_probe error handling

PATCH In review Axel Lin 2 participants 2 messages Oct 3, 2012 – Oct 4, 2012

Subsystems (2)
lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 extcon: max77693: Fix max77693_muic_probe error handling

Fix below issues:
1. If request_threaded_irq() fails, current code does not free all requested irqs.
2. Add missing extcon_dev_unregister() in error path if failed to read revision number.

---
 drivers/extcon/extcon-max77693.c |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/extcon/extcon-max77693.c +6 -6
index e0ed622..9928c63 100644
@@ -696,12 +696,8 @@ static int __devinit max77693_muic_probe(struct platform_device *pdev)
 				IRQF_ONESHOT, muic_irq->name, info);
 		if (ret) {
 			dev_err(&pdev->dev,
-				"failed: irq request (IRQ: %d,"
-				" error :%d)\n",
+				"failed: irq request (IRQ: %d, error :%d)\n",
 				muic_irq->irq, ret);
-
-			for (i = i - 1; i >= 0; i--)
-				free_irq(muic_irq->virq, info);
 			goto err_irq;
 		}
 	}
@@ -726,7 +722,7 @@ static int __devinit max77693_muic_probe(struct platform_device *pdev)
 			MAX77693_MUIC_REG_ID, &id);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "failed to read revision number\n");
-		goto err_extcon;
+		goto err_read_reg;
 	}
 	dev_info(info->dev, "device ID : 0x%x\n", id);
 
@@ -738,9 +734,13 @@ static int __devinit max77693_muic_probe(struct platform_device *pdev)
 
 	return ret;
 
+err_read_reg:
+	extcon_dev_unregister(info->edev);
 err_extcon:
 	kfree(info->edev);
 err_irq:
+	while (--i >= 0)
+		free_irq(muic_irqs[i].virq, info);
 err_regmap:
 	kfree(info);
 err_kfree:
Signature · 1 line
1.7.9.5
maintainer
#1 lore raw
Quoted 39 lines · Axel Lin

Fix below issues:
1. If request_threaded_irq() fails, current code does not free all requested irqs.
2. Add missing extcon_dev_unregister() in error path if failed to read revision number.

---
 drivers/extcon/extcon-max77693.c |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/extcon/extcon-max77693.c +2 -6
index e0ed622..9928c63 100644
@@ -696,12 +696,8 @@ static int __devinit max77693_muic_probe(struct platform_device *pdev)
 				IRQF_ONESHOT, muic_irq->name, info);
 		if (ret) {
 			dev_err(&pdev->dev,
-				"failed: irq request (IRQ: %d,"
-				" error :%d)\n",
+				"failed: irq request (IRQ: %d, error :%d)\n",
 				muic_irq->irq, ret);
-
-			for (i = i - 1; i >= 0; i--)
-				free_irq(muic_irq->virq, info);
 			goto err_irq;
 		}
 	}
@@ -726,7 +722,7 @@ static int __devinit max77693_muic_probe(struct platform_device *pdev)
 			MAX77693_MUIC_REG_ID, &id);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "failed to read revision number\n");
-		goto err_extcon;
+		goto err_read_reg;
 	}
 	dev_info(info->dev, "device ID : 0x%x\n", id);
 

drivers/extcon/extcon-max77693.c static int __devinit max77693_muic_probe(struct platform_device *pdev) · line 743

Quoted 10 lines
drivers/extcon/extcon-max77693.c +4 -0
@@ -738,9 +734,13 @@ static int __devinit max77693_muic_probe(struct platform_device *pdev)
 
 	return ret;
 
+err_read_reg:
+	extcon_dev_unregister(info->edev);
 err_extcon:
 	kfree(info->edev);
 err_irq:
+	while (--i >= 0)
+		free_irq(muic_irqs[i].virq, info);

This include possible error when 'i' variable may be used after completed request_thread_irq() operation. I think the below patch is appropriate because free_irq() function return NULL if first parameter is unrequested irq.

err_irq:
+ for (i = 0; i < ARRAY_SIZE(muic_irqs); i++)
+ free_irq(muic_irqs[i].virq, info);

Thank you,
Chanwoo Choi