All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] extcon: max14577: cancel cable detection work on detach
@ 2026-07-19 14:43 Hongyan Xu
  0 siblings, 0 replies; only message in thread
From: Hongyan Xu @ 2026-07-19 14:43 UTC (permalink / raw)
  To: cw00.choi, krzysztof.kozlowski, myungjoo.ham
  Cc: linux-kernel, jianhao.xu, getshell

Probe queues wq_detcable, but the delayed work is not cancelled when
the platform device is detached. Devres can therefore release info
while the work is still pending.

Manage both work items with devres and request the nested IRQs only
after the extcon device and work items are ready. Reverse-order release
then stops the IRQ producers before cancelling the work and releasing
info.

Signed-off-by: Hongyan Xu <getshell@seu.edu.cn>
---
 drivers/extcon/extcon-max14577.c | 58 +++++++++++++++++---------------
 1 file changed, 30 insertions(+), 28 deletions(-)

diff --git a/drivers/extcon/extcon-max14577.c b/drivers/extcon/extcon-max14577.c
index 5476f48..9fad5c9 100644
--- a/drivers/extcon/extcon-max14577.c
+++ b/drivers/extcon/extcon-max14577.c
@@ -674,11 +674,6 @@ static int max14577_muic_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, info);
 	mutex_init(&info->mutex);
 
-	ret = devm_work_autocancel(&pdev->dev, &info->irq_work,
-				   max14577_muic_irq_work);
-	if (ret)
-		return ret;
-
 	switch (max14577->dev_type) {
 	case MAXIM_DEVICE_TYPE_MAX77836:
 		info->muic_irqs = max77836_muic_irqs;
@@ -690,28 +685,6 @@ static int max14577_muic_probe(struct platform_device *pdev)
 		info->muic_irqs_num = ARRAY_SIZE(max14577_muic_irqs);
 	}
 
-	/* Support irq domain for max14577 MUIC device */
-	for (i = 0; i < info->muic_irqs_num; i++) {
-		struct max14577_muic_irq *muic_irq = &info->muic_irqs[i];
-		int virq = 0;
-
-		virq = regmap_irq_get_virq(max14577->irq_data, muic_irq->irq);
-		if (virq <= 0)
-			return -EINVAL;
-		muic_irq->virq = virq;
-
-		ret = devm_request_threaded_irq(&pdev->dev, virq, NULL,
-				max14577_muic_irq_handler,
-				IRQF_NO_SUSPEND,
-				muic_irq->name, info);
-		if (ret) {
-			dev_err(&pdev->dev,
-				"failed: irq request (IRQ: %d, error :%d)\n",
-				muic_irq->irq, ret);
-			return ret;
-		}
-	}
-
 	/* Initialize extcon device */
 	info->edev = devm_extcon_dev_allocate(&pdev->dev,
 					      max14577_extcon_cable);
@@ -725,6 +698,14 @@ static int max14577_muic_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "failed to register extcon device\n");
 		return ret;
 	}
+	ret = devm_work_autocancel(&pdev->dev, &info->irq_work,
+				   max14577_muic_irq_work);
+	if (ret)
+		return ret;
+	ret = devm_delayed_work_autocancel(&pdev->dev, &info->wq_detcable,
+					   max14577_muic_detect_cable_wq);
+	if (ret)
+		return ret;
 
 	/* Default h/w line path */
 	info->path_usb = CTRL1_SW_USB;
@@ -755,6 +736,28 @@ static int max14577_muic_probe(struct platform_device *pdev)
 	/* Set ADC debounce time */
 	max14577_muic_set_debounce_time(info, ADC_DEBOUNCE_TIME_25MS);
 
+	/* Support irq domain for max14577 MUIC device */
+	for (i = 0; i < info->muic_irqs_num; i++) {
+		struct max14577_muic_irq *muic_irq = &info->muic_irqs[i];
+		int virq = 0;
+
+		virq = regmap_irq_get_virq(max14577->irq_data, muic_irq->irq);
+		if (virq <= 0)
+			return -EINVAL;
+		muic_irq->virq = virq;
+
+		ret = devm_request_threaded_irq(&pdev->dev, virq, NULL,
+						max14577_muic_irq_handler,
+						IRQF_NO_SUSPEND,
+						muic_irq->name, info);
+		if (ret) {
+			dev_err(&pdev->dev,
+				"failed: irq request (IRQ: %d, error :%d)\n",
+				muic_irq->irq, ret);
+			return ret;
+		}
+	}
+
 	/*
 	 * Detect accessory after completing the initialization of platform
 	 *
@@ -763,7 +766,6 @@ static int max14577_muic_probe(struct platform_device *pdev)
 	 * After completing the booting of platform, the extcon provider
 	 * driver should notify cable state to upper layer.
 	 */
-	INIT_DELAYED_WORK(&info->wq_detcable, max14577_muic_detect_cable_wq);
 	queue_delayed_work(system_power_efficient_wq, &info->wq_detcable,
 			delay_jiffies);
 
-- 
2.50.1.windows.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-07-19 14:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-19 14:43 [PATCH] extcon: max14577: cancel cable detection work on detach Hongyan Xu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.