Skip to contentSkip to conversation

FAILED: patch "[PATCH] usb: typec: qcom-pmic-typec: disable cc_debounce_dwork on" failed to apply to 6.6-stable tree

PATCH Applied [email protected] 4 participants 7 messages Sep 8 – Nov 29

Subsystems (5)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x 263f7d61a4201cde16849b2d016251806e7418be
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026090807-unbalance-starlet-1c55@gregkh' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'

Possible dependencies:

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 263f7d61a4201cde16849b2d016251806e7418be Mon Sep 17 00:00:00 2001
From: Fan Wu <[email protected]>
Date: Thu, 20 Aug 2026 13:53:06 +0000
Subject: [PATCH] usb: typec: qcom-pmic-typec: disable cc_debounce_dwork on
stop

cc_debounce_dwork is queued from the set_cc() and start_toggling() callbacks, which run from TCPM's kthread worker. port_stop() returns before tcpm_unregister_port() destroys that worker. Flushing the worker during unregister may therefore run a callback which queues the delayed work after port_stop() has returned.

The delayed work can then run after devres has freed pmic_typec_port.

Use disable_delayed_work_sync() in port_stop() to cancel a pending instance and prevent the TCPM callbacks from queueing another one.

This issue was found by an in-house static analysis tool.

Fixes a4422ff22142 ("usb: typec: qcom: Add Qualcomm PMIC Type-C driver")
Cc stable <[email protected]> # v6.10+
Assisted-by Codex:gpt-5.6
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c +2 -0
index bf985efe1cd6..d43799f43184 100644
@@ -693,6 +693,8 @@ static void qcom_pmic_typec_port_stop(struct pmic_typec *tcpm)
 
 	for (i = 0; i < pmic_typec_port->nr_irqs; i++)
 		disable_irq(pmic_typec_port->irq_data[i].irq);
+
+	disable_delayed_work_sync(&pmic_typec_port->cc_debounce_dwork);
 }
 
 int qcom_pmic_typec_port_probe(struct platform_device *pdev,
#1 lore raw

cover usb: typec: qcom-pmic-typec: fix late probe and debounce teardown

Patch 1 unwinds port startup and TCPM registration on late probe errors. Patch 2 blocks new CC debounce work and drains pending work on port stop. Patch 3 does the same if port startup fails before the IRQs are enabled. The two debounce fixes failed to apply to 6.6 in <2026090807-unbalance-starlet-1c55@gregkh> and <2026090836-sublet-submersed-cfc4@gregkh>.

The late-probe patch uses a newer driver layout. On 6.6 the unwind calls the port helpers directly and keeps fwnode_handle_put(). This branch lacks disable_delayed_work_sync(), so port stop and port-start failure block new debounce work under the port lock and cancel pending work synchronously.

Tested on v6.6.163:
- The three patches applied cleanly with git am.
- Base and patched x86_64 allmodconfig W=1 builds passed for qcom_pmic_typec.o and qcom_pmic_typec_port.o with identical diagnostics.
- The patched x86_64 kernel booted under QEMU/KVM with CONFIG_TYPEC_QCOM_PMIC=y and powered down normally.
The guest has no Qualcomm PMIC, so the error and teardown paths were checked in source only.

The backport and the test runs were prepared with AI coding tools (OpenAI Codex agents, with review by Claude). I went over the result before signing off.

---
Fan Wu (2):
usb: typec: qcom-pmic-typec: disable cc_debounce_dwork on stop
usb: typec: qcom-pmic-typec: drain cc_debounce_dwork if port_start() fails

Johan Hovold (1):
usb: typec: qcom-pmic: fix use-after-free on late probe errors

 drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c      |  8 ++++++--
 drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c | 20 ++++++++++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)

---
base-commit: e2bb30811e063ce0db964484357973b855b06572
change-id: 20261127-typec-66b-370b700f7dce

Best regards,

Signature · 1 line
Dickson Wu <[email protected]>
#4 lore raw

PATCH 1/3 usb: typec: qcom-pmic: fix use-after-free on late probe errors

In reply to [email protected]

From: Johan Hovold <[email protected]>

commit d80eee97cb4e90768a81c856ac71d721996d86b7 upstream.

Make sure to stop and deregister the port in case of late probe errors to avoid use-after-free issues when the underlying memory is released by devres.

Fixes a4422ff22142 ("usb: typec: qcom: Add Qualcomm PMIC Type-C driver")
Cc Bryan O'Donoghue <[email protected]>
[ adapted to 6.6.y: use direct port helpers and fwnode_handle_put() ]

---
On 6.6 the unwind calls the port helpers directly and keeps fwnode_handle_put(); the tcpm ops layout upstream uses came later.

The backport and the test runs were prepared with AI coding tools (OpenAI Codex agents, with review by Claude). I went over the result before signing off.

 drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c +6 -2
index 5f67925a19d3..a8fc86099f32 100644
@@ -258,15 +258,19 @@ static int qcom_pmic_typec_probe(struct platform_device *pdev)
 	ret = qcom_pmic_typec_port_start(tcpm->pmic_typec_port,
 					 tcpm->tcpm_port);
 	if (ret)
-		goto fwnode_remove;
+		goto port_unregister;
 
 	ret = qcom_pmic_typec_pdphy_start(tcpm->pmic_typec_pdphy,
 					  tcpm->tcpm_port);
 	if (ret)
-		goto fwnode_remove;
+		goto port_stop;
 
 	return 0;
 
+port_stop:
+	qcom_pmic_typec_port_stop(tcpm->pmic_typec_port);
+port_unregister:
+	tcpm_unregister_port(tcpm->tcpm_port);
 fwnode_remove:
 	fwnode_handle_put(tcpm->tcpc.fwnode);
 
Signature · 1 line
2.43.0
#5 lore raw

PATCH 2/3 usb: typec: qcom-pmic-typec: disable cc_debounce_dwork on stop

In reply to [email protected]

From: Fan Wu <[email protected]>

commit 263f7d61a4201cde16849b2d016251806e7418be upstream.

cc_debounce_dwork is queued from the set_cc() and start_toggling() callbacks, which run from TCPM's kthread worker. port_stop() returns before tcpm_unregister_port() destroys that worker. Flushing the worker during unregister may therefore run a callback which queues the delayed work after port_stop() has returned.

The delayed work can then run after devres has freed pmic_typec_port.

Use disable_delayed_work_sync() in port_stop() to cancel a pending instance and prevent the TCPM callbacks from queueing another one.

This issue was found by an in-house static analysis tool.

Fixes a4422ff22142 ("usb: typec: qcom: Add Qualcomm PMIC Type-C driver")
Cc stable <[email protected]> # v6.10+
Assisted-by Codex:gpt-5.6
[ adapted to 6.6.y: gate enqueues under the port lock before cancel ]

---
6.6 has no disable_delayed_work_sync(). Port stop instead sets a flag under the port lock, which both enqueue sites already hold, and then cancels pending work synchronously. The flag is never cleared because port stop only runs from remove and the probe error path.

The backport and the test runs were prepared with AI coding tools (OpenAI Codex agents, with review by Claude). I went over the result before signing off.

 drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c +17 -0
index d6607491fcef..f0e5e8ab06c0 100644
@@ -36,6 +36,7 @@ struct pmic_typec_port {
 
 	int				cc;
 	bool				debouncing_cc;
+	bool				cc_debounce_disabled;
 	struct delayed_work		cc_debounce_dwork;
 
 	spinlock_t			lock;	/* Register atomicity */
@@ -269,6 +270,9 @@ int qcom_pmic_typec_port_get_cc(struct pmic_typec_port *pmic_typec_port,
 
 static void qcom_pmic_set_cc_debounce(struct pmic_typec_port *pmic_typec_port)
 {
+	if (pmic_typec_port->cc_debounce_disabled)
+		return;
+
 	pmic_typec_port->debouncing_cc = true;
 	schedule_delayed_work(&pmic_typec_port->cc_debounce_dwork,
 			      msecs_to_jiffies(2));
@@ -440,6 +444,17 @@ int qcom_pmic_typec_port_start_toggling(struct pmic_typec_port *pmic_typec_port,
 	(TYPEC_STATE_MACHINE_CHANGE_INT_EN | TYPEC_VBUS_ERROR_INT_EN | \
 	 TYPEC_DEBOUNCE_DONE_INT_EN)
 
+static void qcom_pmic_typec_port_disable_debounce(struct pmic_typec_port *pmic_typec_port)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&pmic_typec_port->lock, flags);
+	pmic_typec_port->cc_debounce_disabled = true;
+	spin_unlock_irqrestore(&pmic_typec_port->lock, flags);
+
+	cancel_delayed_work_sync(&pmic_typec_port->cc_debounce_dwork);
+}
+
 int qcom_pmic_typec_port_start(struct pmic_typec_port *pmic_typec_port,
 			       struct tcpm_port *tcpm_port)
 {
@@ -496,6 +511,8 @@ void qcom_pmic_typec_port_stop(struct pmic_typec_port *pmic_typec_port)
 
 	for (i = 0; i < pmic_typec_port->nr_irqs; i++)
 		disable_irq(pmic_typec_port->irq_data[i].irq);
+
+	qcom_pmic_typec_port_disable_debounce(pmic_typec_port);
 }
 
 struct pmic_typec_port *qcom_pmic_typec_port_alloc(struct device *dev)
Signature · 1 line
2.43.0
#6 lore raw

PATCH 3/3 usb: typec: qcom-pmic-typec: drain cc_debounce_dwork if port_start() fails

In reply to [email protected]

From: Fan Wu <[email protected]>

commit c9273c83885835dbd1e8835d5665dfb8503d65e0 upstream.

cc_debounce_dwork can be queued before port_start() fails:
tcpm_register_port() runs first, and its state machine may invoke set_cc() or start_toggling() from the TCPM worker. The error path then calls tcpm_unregister_port(), whose worker flush may queue the delayed work before devres frees pmic_typec_port.

Disable and drain the delayed work directly at port_start()'s error exit. Do not use port_stop() for this path: its IRQs use IRQF_NO_AUTOEN and are enabled only after a successful port_start().

This issue was found by an in-house static analysis tool.

Fixes a4422ff22142 ("usb: typec: qcom: Add Qualcomm PMIC Type-C driver")
Cc stable <[email protected]> # v6.10+
Assisted-by Codex:gpt-5.6
[ adapted to 6.6.y: call the port's debounce shutdown helper ]

---
This reuses the helper from patch 2 at port_start()'s error exit.

The backport and the test runs were prepared with AI coding tools (OpenAI Codex agents, with review by Claude). I went over the result before signing off.

 drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c +3 -0
index f0e5e8ab06c0..8e6507ce895f 100644
@@ -502,6 +502,9 @@ int qcom_pmic_typec_port_start(struct pmic_typec_port *pmic_typec_port,
 		enable_irq(pmic_typec_port->irq_data[i].irq);
 
 done:
+	if (ret)
+		qcom_pmic_typec_port_disable_debounce(pmic_typec_port);
+
 	return ret;
 }
 
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH 6.6.y 0/3] usb: typec: qcom-pmic-typec: fix late probe and debounce teardown

In reply to Dickson Wu
Sashiko has reviewed this 3-patch series and found no issues.

Sashiko has reviewed this 3-patch series and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]
maintainer Applied
#3 lore raw

Re: [PATCH 6.6.y 0/3] usb: typec: qcom-pmic-typec: fix late probe and debounce teardown

In reply to Dickson Wu
Quoted 3 lines

Patch 1 unwinds port startup and TCPM registration on late probe errors. Patch 2 blocks new CC debounce work and drains pending work on port stop. Patch 3 does the same if port startup fails before the IRQs are enabled.

Queued the series for 6.6, thanks.

Signature · 2 lines
Thanks,
Sasha