Skip to contentSkip to conversation

mfd: arizona: Correctly clean up after IRQs

PATCH Superseded Charles Keepax 2 participants 8 messages Nov 14, 2016 – Nov 22, 2016

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 mfd: arizona: Correctly clean up after IRQs

Currently we leak a lot of things when tearing down the IRQs this patch fixes this cleaning up both the IRQ mappings and the IRQ domain itself.

---

Changes since v1:
- Correct handling of ret and error messages from irq_create_mapping

Thanks,
Charles

 drivers/mfd/arizona-irq.c | 54 +++++++++++++++++++++++++++++++++++------------
 1 file changed, 40 insertions(+), 14 deletions(-)
drivers/mfd/arizona-irq.c +40 -14
index 2e01975..bc3b342 100644
@@ -207,6 +207,7 @@ int arizona_irq_init(struct arizona *arizona)
 	int ret, i;
 	const struct regmap_irq_chip *aod, *irq;
 	struct irq_data *irq_data;
+	unsigned int virq;
 
 	arizona->ctrlif_error = true;
 
@@ -318,24 +319,34 @@ int arizona_irq_init(struct arizona *arizona)
 	}
 
 	if (aod) {
-		ret = regmap_add_irq_chip(arizona->regmap,
-					  irq_create_mapping(arizona->virq, 0),
-					  IRQF_ONESHOT, 0, aod,
-					  &arizona->aod_irq_chip);
+		virq = irq_create_mapping(arizona->virq, 0);
+		if (!virq) {
+			dev_err(arizona->dev, "Failed to map AOD IRQs\n");
+			ret = -EINVAL;
+			goto err_domain;
+		}
+
+		ret = regmap_add_irq_chip(arizona->regmap, virq, IRQF_ONESHOT,
+					  0, aod, &arizona->aod_irq_chip);
 		if (ret != 0) {
 			dev_err(arizona->dev,
 				"Failed to add AOD IRQs: %d\n", ret);
-			goto err;
+			goto err_map_aod;
 		}
 	}
 
-	ret = regmap_add_irq_chip(arizona->regmap,
-				  irq_create_mapping(arizona->virq, 1),
-				  IRQF_ONESHOT, 0, irq,
-				  &arizona->irq_chip);
+	virq = irq_create_mapping(arizona->virq, 1);
+	if (!virq) {
+		dev_err(arizona->dev, "Failed to map main IRQs\n");
+		ret = -EINVAL;
+		goto err_aod;
+	}
+
+	ret = regmap_add_irq_chip(arizona->regmap, virq, IRQF_ONESHOT,
+				  0, irq, &arizona->irq_chip);
 	if (ret != 0) {
 		dev_err(arizona->dev, "Failed to add main IRQs: %d\n", ret);
-		goto err_aod;
+		goto err_map_main_irq;
 	}
 
 	/* Used to emulate edge trigger and to work around broken pinmux */
@@ -400,23 +411,38 @@ int arizona_irq_init(struct arizona *arizona)
 err_main_irq:
 	regmap_del_irq_chip(irq_find_mapping(arizona->virq, 1),
 			    arizona->irq_chip);
+err_map_main_irq:
+	irq_dispose_mapping(irq_find_mapping(arizona->virq, 1));
 err_aod:
 	regmap_del_irq_chip(irq_find_mapping(arizona->virq, 0),
 			    arizona->aod_irq_chip);
+err_map_aod:
+	irq_dispose_mapping(irq_find_mapping(arizona->virq, 0));
+err_domain:
+	irq_domain_remove(arizona->virq);
 err:
 	return ret;
 }
 
 int arizona_irq_exit(struct arizona *arizona)
 {
+	unsigned int virq;
+
 	if (arizona->ctrlif_error)
 		free_irq(arizona_map_irq(arizona, ARIZONA_IRQ_CTRLIF_ERR),
 			 arizona);
 	free_irq(arizona_map_irq(arizona, ARIZONA_IRQ_BOOT_DONE), arizona);
-	regmap_del_irq_chip(irq_find_mapping(arizona->virq, 1),
-			    arizona->irq_chip);
-	regmap_del_irq_chip(irq_find_mapping(arizona->virq, 0),
-			    arizona->aod_irq_chip);
+
+	virq = irq_find_mapping(arizona->virq, 1);
+	regmap_del_irq_chip(virq, arizona->irq_chip);
+	irq_dispose_mapping(virq);
+
+	virq = irq_find_mapping(arizona->virq, 0);
+	regmap_del_irq_chip(virq, arizona->aod_irq_chip);
+	irq_dispose_mapping(virq);
+
+	irq_domain_remove(arizona->virq);
+
 	free_irq(arizona->irq, arizona);
 
 	return 0;
Signature · 1 line
2.1.4
#1 lore raw

PATCH 2/3 mfd: arizona: Disable IRQs during driver remove

As DCVDD will often be supplied by a child node of the MFD, we can't call mfd_remove_devices as the first step in arizona_dev_exit as might be expected (tidy up the children before we tidy up the MFD). We need to disable and put the DCVDD regulator before we call mfd_remove_devices, to prevent PM runtime from turning this back on we also need to disable the PM runtime before we do this. Finally we can not clean up the IRQs until all the MFD children have been removed, as they may have registered IRQs themselves.

This creates a window of time where the interrupts are enabled but the PM runtime, on which the IRQ handler depends, is not available, any interrupts in this window will go unhandled and fill the log with failed to resume device messages. To avoid this we simply disable the main IRQ at the start of arizona_dev_exit, we don't need to actually handle any IRQs in this window as we are removing the driver.

---
 drivers/mfd/arizona-core.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mfd/arizona-core.c +1 -0
index 41767f7..b6d4bc6 100644
@@ -1553,6 +1553,7 @@ EXPORT_SYMBOL_GPL(arizona_dev_init);
 
 int arizona_dev_exit(struct arizona *arizona)
 {
+	disable_irq(arizona->irq);
 	pm_runtime_disable(arizona->dev);
 
 	regulator_disable(arizona->dcvdd);
Signature · 1 line
2.1.4
Applied
#2 lore raw

Re: [PATCH 2/3] mfd: arizona: Disable IRQs during driver remove

Quoted 16 lines · Charles Keepax

As DCVDD will often be supplied by a child node of the MFD, we can't call mfd_remove_devices as the first step in arizona_dev_exit as might be expected (tidy up the children before we tidy up the MFD). We need to disable and put the DCVDD regulator before we call mfd_remove_devices, to prevent PM runtime from turning this back on we also need to disable the PM runtime before we do this. Finally we can not clean up the IRQs until all the MFD children have been removed, as they may have registered IRQs themselves.

This creates a window of time where the interrupts are enabled but the PM runtime, on which the IRQ handler depends, is not available, any interrupts in this window will go unhandled and fill the log with failed to resume device messages. To avoid this we simply disable the main IRQ at the start of arizona_dev_exit, we don't need to actually handle any IRQs in this window as we are removing the driver.

Quoted 4 lines
---
 drivers/mfd/arizona-core.c | 1 +
 1 file changed, 1 insertion(+)

I'm convinced.

Applied, thanks.

Quoted 12 lines
drivers/mfd/arizona-core.c +1 -0
index 41767f7..b6d4bc6 100644
@@ -1553,6 +1553,7 @@ EXPORT_SYMBOL_GPL(arizona_dev_init);
 
 int arizona_dev_exit(struct arizona *arizona)
 {
+	disable_irq(arizona->irq);
 	pm_runtime_disable(arizona->dev);
 
 	regulator_disable(arizona->dcvdd);
Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#3 lore raw

PATCH 3/3 mfd: arizona: Use arizona_map_irq instead of hard coding it

In reply to Charles Keepax

We have arizona_map_irq we might as well use it rather than hard coding it in several places.

---
 drivers/mfd/arizona-irq.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)
drivers/mfd/arizona-irq.c +9 -12
index bc3b342..22f96c9 100644
@@ -204,7 +204,7 @@ static const struct irq_domain_ops arizona_domain_ops = {
 int arizona_irq_init(struct arizona *arizona)
 {
 	int flags = IRQF_ONESHOT;
-	int ret, i;
+	int ret;
 	const struct regmap_irq_chip *aod, *irq;
 	struct irq_data *irq_data;
 	unsigned int virq;
@@ -379,9 +379,8 @@ int arizona_irq_init(struct arizona *arizona)
 	}
 
 	/* Make sure the boot done IRQ is unmasked for resumes */
-	i = arizona_map_irq(arizona, ARIZONA_IRQ_BOOT_DONE);
-	ret = request_threaded_irq(i, NULL, arizona_boot_done, IRQF_ONESHOT,
-				   "Boot done", arizona);
+	ret = arizona_request_irq(arizona, ARIZONA_IRQ_BOOT_DONE, "Boot done",
+				  arizona_boot_done, arizona);
 	if (ret != 0) {
 		dev_err(arizona->dev, "Failed to request boot done %d: %d\n",
 			arizona->irq, ret);
@@ -390,10 +389,9 @@ int arizona_irq_init(struct arizona *arizona)
 
 	/* Handle control interface errors in the core */
 	if (arizona->ctrlif_error) {
-		i = arizona_map_irq(arizona, ARIZONA_IRQ_CTRLIF_ERR);
-		ret = request_threaded_irq(i, NULL, arizona_ctrlif_err,
-					   IRQF_ONESHOT,
-					   "Control interface error", arizona);
+		ret = arizona_request_irq(arizona, ARIZONA_IRQ_CTRLIF_ERR,
+					  "Control interface error",
+					  arizona_ctrlif_err, arizona);
 		if (ret != 0) {
 			dev_err(arizona->dev,
 				"Failed to request CTRLIF_ERR %d: %d\n",
@@ -405,7 +403,7 @@ int arizona_irq_init(struct arizona *arizona)
 	return 0;
 
 err_ctrlif:
-	free_irq(arizona_map_irq(arizona, ARIZONA_IRQ_BOOT_DONE), arizona);
+	arizona_free_irq(arizona, ARIZONA_IRQ_BOOT_DONE, arizona);
 err_boot_done:
 	free_irq(arizona->irq, arizona);
 err_main_irq:
@@ -429,9 +427,8 @@ int arizona_irq_exit(struct arizona *arizona)
 	unsigned int virq;
 
 	if (arizona->ctrlif_error)
-		free_irq(arizona_map_irq(arizona, ARIZONA_IRQ_CTRLIF_ERR),
-			 arizona);
-	free_irq(arizona_map_irq(arizona, ARIZONA_IRQ_BOOT_DONE), arizona);
+		arizona_free_irq(arizona, ARIZONA_IRQ_CTRLIF_ERR, arizona);
+	arizona_free_irq(arizona, ARIZONA_IRQ_BOOT_DONE, arizona);
 
 	virq = irq_find_mapping(arizona->virq, 1);
 	regmap_del_irq_chip(virq, arizona->irq_chip);
Signature · 1 line
2.1.4
Applied
#4 lore raw

Re: [PATCH 3/3] mfd: arizona: Use arizona_map_irq instead of hard coding it

Quoted 7 lines · Charles Keepax

We have arizona_map_irq we might as well use it rather than hard coding it in several places.

---
 drivers/mfd/arizona-irq.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

Applied, thanks.

Quoted 60 lines
drivers/mfd/arizona-irq.c +9 -12
index bc3b342..22f96c9 100644
@@ -204,7 +204,7 @@ static const struct irq_domain_ops arizona_domain_ops = {
 int arizona_irq_init(struct arizona *arizona)
 {
 	int flags = IRQF_ONESHOT;
-	int ret, i;
+	int ret;
 	const struct regmap_irq_chip *aod, *irq;
 	struct irq_data *irq_data;
 	unsigned int virq;
@@ -379,9 +379,8 @@ int arizona_irq_init(struct arizona *arizona)
 	}
 
 	/* Make sure the boot done IRQ is unmasked for resumes */
-	i = arizona_map_irq(arizona, ARIZONA_IRQ_BOOT_DONE);
-	ret = request_threaded_irq(i, NULL, arizona_boot_done, IRQF_ONESHOT,
-				   "Boot done", arizona);
+	ret = arizona_request_irq(arizona, ARIZONA_IRQ_BOOT_DONE, "Boot done",
+				  arizona_boot_done, arizona);
 	if (ret != 0) {
 		dev_err(arizona->dev, "Failed to request boot done %d: %d\n",
 			arizona->irq, ret);
@@ -390,10 +389,9 @@ int arizona_irq_init(struct arizona *arizona)
 
 	/* Handle control interface errors in the core */
 	if (arizona->ctrlif_error) {
-		i = arizona_map_irq(arizona, ARIZONA_IRQ_CTRLIF_ERR);
-		ret = request_threaded_irq(i, NULL, arizona_ctrlif_err,
-					   IRQF_ONESHOT,
-					   "Control interface error", arizona);
+		ret = arizona_request_irq(arizona, ARIZONA_IRQ_CTRLIF_ERR,
+					  "Control interface error",
+					  arizona_ctrlif_err, arizona);
 		if (ret != 0) {
 			dev_err(arizona->dev,
 				"Failed to request CTRLIF_ERR %d: %d\n",
@@ -405,7 +403,7 @@ int arizona_irq_init(struct arizona *arizona)
 	return 0;
 
 err_ctrlif:
-	free_irq(arizona_map_irq(arizona, ARIZONA_IRQ_BOOT_DONE), arizona);
+	arizona_free_irq(arizona, ARIZONA_IRQ_BOOT_DONE, arizona);
 err_boot_done:
 	free_irq(arizona->irq, arizona);
 err_main_irq:
@@ -429,9 +427,8 @@ int arizona_irq_exit(struct arizona *arizona)
 	unsigned int virq;
 
 	if (arizona->ctrlif_error)
-		free_irq(arizona_map_irq(arizona, ARIZONA_IRQ_CTRLIF_ERR),
-			 arizona);
-	free_irq(arizona_map_irq(arizona, ARIZONA_IRQ_BOOT_DONE), arizona);
+		arizona_free_irq(arizona, ARIZONA_IRQ_CTRLIF_ERR, arizona);
+	arizona_free_irq(arizona, ARIZONA_IRQ_BOOT_DONE, arizona);
 
 	virq = irq_find_mapping(arizona->virq, 1);
 	regmap_del_irq_chip(virq, arizona->irq_chip);
Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#5 lore raw

Re: [PATCH 3/3] mfd: arizona: Use arizona_map_irq instead of hard coding it

Quoted 11 lines · Lee Jones
Quoted 7 lines · Charles Keepax

We have arizona_map_irq we might as well use it rather than hard coding it in several places.

---
 drivers/mfd/arizona-irq.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

Applied, thanks.

Slight change of plan.

Patch doesn't seem to apply.

Please rebase it on top of my MFD tree and resubmit.

Quoted 61 lines
Quoted 60 lines
drivers/mfd/arizona-irq.c +9 -12
index bc3b342..22f96c9 100644
@@ -204,7 +204,7 @@ static const struct irq_domain_ops arizona_domain_ops = {
 int arizona_irq_init(struct arizona *arizona)
 {
 	int flags = IRQF_ONESHOT;
-	int ret, i;
+	int ret;
 	const struct regmap_irq_chip *aod, *irq;
 	struct irq_data *irq_data;
 	unsigned int virq;
@@ -379,9 +379,8 @@ int arizona_irq_init(struct arizona *arizona)
 	}
 
 	/* Make sure the boot done IRQ is unmasked for resumes */
-	i = arizona_map_irq(arizona, ARIZONA_IRQ_BOOT_DONE);
-	ret = request_threaded_irq(i, NULL, arizona_boot_done, IRQF_ONESHOT,
-				   "Boot done", arizona);
+	ret = arizona_request_irq(arizona, ARIZONA_IRQ_BOOT_DONE, "Boot done",
+				  arizona_boot_done, arizona);
 	if (ret != 0) {
 		dev_err(arizona->dev, "Failed to request boot done %d: %d\n",
 			arizona->irq, ret);
@@ -390,10 +389,9 @@ int arizona_irq_init(struct arizona *arizona)
 
 	/* Handle control interface errors in the core */
 	if (arizona->ctrlif_error) {
-		i = arizona_map_irq(arizona, ARIZONA_IRQ_CTRLIF_ERR);
-		ret = request_threaded_irq(i, NULL, arizona_ctrlif_err,
-					   IRQF_ONESHOT,
-					   "Control interface error", arizona);
+		ret = arizona_request_irq(arizona, ARIZONA_IRQ_CTRLIF_ERR,
+					  "Control interface error",
+					  arizona_ctrlif_err, arizona);
 		if (ret != 0) {
 			dev_err(arizona->dev,
 				"Failed to request CTRLIF_ERR %d: %d\n",
@@ -405,7 +403,7 @@ int arizona_irq_init(struct arizona *arizona)
 	return 0;
 
 err_ctrlif:
-	free_irq(arizona_map_irq(arizona, ARIZONA_IRQ_BOOT_DONE), arizona);
+	arizona_free_irq(arizona, ARIZONA_IRQ_BOOT_DONE, arizona);
 err_boot_done:
 	free_irq(arizona->irq, arizona);
 err_main_irq:
@@ -429,9 +427,8 @@ int arizona_irq_exit(struct arizona *arizona)
 	unsigned int virq;
 
 	if (arizona->ctrlif_error)
-		free_irq(arizona_map_irq(arizona, ARIZONA_IRQ_CTRLIF_ERR),
-			 arizona);
-	free_irq(arizona_map_irq(arizona, ARIZONA_IRQ_BOOT_DONE), arizona);
+		arizona_free_irq(arizona, ARIZONA_IRQ_CTRLIF_ERR, arizona);
+	arizona_free_irq(arizona, ARIZONA_IRQ_BOOT_DONE, arizona);
 
 	virq = irq_find_mapping(arizona->virq, 1);
 	regmap_del_irq_chip(virq, arizona->irq_chip);
Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#6 lore raw

Re: [PATCH 3/3] mfd: arizona: Use arizona_map_irq instead of hard coding it

Quoted 12 lines · Lee Jones
Quoted 10 lines · Lee Jones
Quoted 7 lines · Charles Keepax

We have arizona_map_irq we might as well use it rather than hard coding it in several places.

---
 drivers/mfd/arizona-irq.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)
Quoted 8 lines
Quoted 1 line

Applied, thanks.

Slight change of plan.

Patch doesn't seem to apply.

Please rebase it on top of my MFD tree and resubmit.

Yeah depends on the first patch, ignore the ones I just sent (since I had assumed you fixed that up manually) and I will resend the whole series.

Thanks,
Charles

#7 lore raw
In reply to Charles Keepax
Quoted 28 lines · Charles Keepax

Currently we leak a lot of things when tearing down the IRQs this patch fixes this cleaning up both the IRQ mappings and the IRQ domain itself.

---

Changes since v1:
- Correct handling of ret and error messages from irq_create_mapping

Thanks,
Charles

 drivers/mfd/arizona-irq.c | 54 +++++++++++++++++++++++++++++++++++------------
 1 file changed, 40 insertions(+), 14 deletions(-)
drivers/mfd/arizona-irq.c +1 -0
index 2e01975..bc3b342 100644
@@ -207,6 +207,7 @@ int arizona_irq_init(struct arizona *arizona)
 	int ret, i;
 	const struct regmap_irq_chip *aod, *irq;
 	struct irq_data *irq_data;
+	unsigned int virq;
 
 	arizona->ctrlif_error = true;
 

drivers/mfd/arizona-irq.c int arizona_irq_init(struct arizona *arizona) · line 322

Quoted 8 lines
drivers/mfd/arizona-irq.c +1 -4
@@ -318,24 +319,34 @@ int arizona_irq_init(struct arizona *arizona)
 	}
 
 	if (aod) {
-		ret = regmap_add_irq_chip(arizona->regmap,
-					  irq_create_mapping(arizona->virq, 0),
-					  IRQF_ONESHOT, 0, aod,
-					  &arizona->aod_irq_chip);
+		virq = irq_create_mapping(arizona->virq, 0);

I would like to see all of the '0's and '1's defined please.

Quoted 79 lines
drivers/mfd/arizona-irq.c +38 -10
+		if (!virq) {
+			dev_err(arizona->dev, "Failed to map AOD IRQs\n");
+			ret = -EINVAL;
+			goto err_domain;
+		}
+
+		ret = regmap_add_irq_chip(arizona->regmap, virq, IRQF_ONESHOT,
+					  0, aod, &arizona->aod_irq_chip);
 		if (ret != 0) {
 			dev_err(arizona->dev,
 				"Failed to add AOD IRQs: %d\n", ret);
-			goto err;
+			goto err_map_aod;
 		}
 	}
 
-	ret = regmap_add_irq_chip(arizona->regmap,
-				  irq_create_mapping(arizona->virq, 1),
-				  IRQF_ONESHOT, 0, irq,
-				  &arizona->irq_chip);
+	virq = irq_create_mapping(arizona->virq, 1);
+	if (!virq) {
+		dev_err(arizona->dev, "Failed to map main IRQs\n");
+		ret = -EINVAL;
+		goto err_aod;
+	}
+
+	ret = regmap_add_irq_chip(arizona->regmap, virq, IRQF_ONESHOT,
+				  0, irq, &arizona->irq_chip);
 	if (ret != 0) {
 		dev_err(arizona->dev, "Failed to add main IRQs: %d\n", ret);
-		goto err_aod;
+		goto err_map_main_irq;
 	}
 
 	/* Used to emulate edge trigger and to work around broken pinmux */
@@ -400,23 +411,38 @@ int arizona_irq_init(struct arizona *arizona)
 err_main_irq:
 	regmap_del_irq_chip(irq_find_mapping(arizona->virq, 1),
 			    arizona->irq_chip);
+err_map_main_irq:
+	irq_dispose_mapping(irq_find_mapping(arizona->virq, 1));
 err_aod:
 	regmap_del_irq_chip(irq_find_mapping(arizona->virq, 0),
 			    arizona->aod_irq_chip);
+err_map_aod:
+	irq_dispose_mapping(irq_find_mapping(arizona->virq, 0));
+err_domain:
+	irq_domain_remove(arizona->virq);
 err:
 	return ret;
 }
 
 int arizona_irq_exit(struct arizona *arizona)
 {
+	unsigned int virq;
+
 	if (arizona->ctrlif_error)
 		free_irq(arizona_map_irq(arizona, ARIZONA_IRQ_CTRLIF_ERR),
 			 arizona);
 	free_irq(arizona_map_irq(arizona, ARIZONA_IRQ_BOOT_DONE), arizona);
-	regmap_del_irq_chip(irq_find_mapping(arizona->virq, 1),
-			    arizona->irq_chip);
-	regmap_del_irq_chip(irq_find_mapping(arizona->virq, 0),
-			    arizona->aod_irq_chip);
+
+	virq = irq_find_mapping(arizona->virq, 1);
+	regmap_del_irq_chip(virq, arizona->irq_chip);
+	irq_dispose_mapping(virq);
+
+	virq = irq_find_mapping(arizona->virq, 0);
+	regmap_del_irq_chip(virq, arizona->aod_irq_chip);
+	irq_dispose_mapping(virq);
+
+	irq_domain_remove(arizona->virq);
+
 	free_irq(arizona->irq, arizona);
 
 	return 0;
Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog