* [PATCH v2 0/4] usb: typec: tcpm/tcpci_maxim: lockdep, wakeup and vbus regulator fixes
@ 2026-11-25 12:16 André Draszik
2026-11-25 12:16 ` [PATCH v2 1/4] usb: typec: tcpm/tcpci_maxim: fix invalid wait context André Draszik
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: André Draszik @ 2026-11-25 12:16 UTC (permalink / raw)
To: Heikki Krogerus, Greg Kroah-Hartman, Badhri Jagan Sridharan
Cc: Sebastian Andrzej Siewior, Clark Williams, Steven Rostedt,
Peter Griffin, Tudor Ambarus, Juan Yescas, Amit Sunil Dhamne,
kernel-team, linux-usb, linux-rt-devel, André Draszik,
stable
Hi,
These four patches fix a lockdep invalid wait context splat, a
probe/unbind wakeup-event race, and two vbus regulator lifetime and
logging bugs in the Maxim 77759 TCPCI driver:
- Call pm_wakeup_event() from the threaded IRQ handler instead of the
hard IRQ handler (the driver uses IRQF_ONESHOT, so the primary handler
runs in hard IRQ context even on PREEMPT_RT).
- Initialise device wakeup before requesting the IRQ, so a pending alert
or an interrupt during unbind cannot miss recording a wakeup event.
- Fix a vbus regulator use-after-free on driver unbind.
- Drop an irrelevant error message when VBUS sourcing is not requested.
Tested on Pixel 6 (Oriole) with CONFIG_PROVE_RAW_LOCK_NESTING=y enabled,
including tcpci_maxim module unload and reload cycles.
Cheers
Andre'
Signed-off-by: André Draszik <andre.draszik@linaro.org>
---
Changes in v2:
- add patches for two more issues, a UAF and a spurious irrelevant
warning
- collect Heikki's Acked-by on patches 1 and 2.
- rebase onto next-20261123.
- Link to v1: https://lore.kernel.org/r/20261123-max77759-wait-v1-0-6fa54a751bb7@linaro.org
---
André Draszik (4):
usb: typec: tcpm/tcpci_maxim: fix invalid wait context
usb: typec: tcpm/tcpci_maxim: init wakeup before irq
usb: typec: tcpm/tcpci_maxim: fix vbus regulator UAF on unbind
usb: typec: tcpm/tcpci_maxim: only complain about vbus when sourcing
drivers/usb/typec/tcpm/tcpci_maxim_core.c | 62 +++++++++++++++++--------------
1 file changed, 35 insertions(+), 27 deletions(-)
---
base-commit: 3191063649dbf7c0d0b768e1f3655e4c5fc6edb5
change-id: 20261123-max77759-wait-10974f4c312d
Best regards,
--
André Draszik <andre.draszik@linaro.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/4] usb: typec: tcpm/tcpci_maxim: fix invalid wait context
2026-11-25 12:16 [PATCH v2 0/4] usb: typec: tcpm/tcpci_maxim: lockdep, wakeup and vbus regulator fixes André Draszik
@ 2026-11-25 12:16 ` André Draszik
2026-11-25 12:16 ` [PATCH v2 2/4] usb: typec: tcpm/tcpci_maxim: init wakeup before irq André Draszik
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: André Draszik @ 2026-11-25 12:16 UTC (permalink / raw)
To: Heikki Krogerus, Greg Kroah-Hartman, Badhri Jagan Sridharan
Cc: Sebastian Andrzej Siewior, Clark Williams, Steven Rostedt,
Peter Griffin, Tudor Ambarus, Juan Yescas, Amit Sunil Dhamne,
kernel-team, linux-usb, linux-rt-devel, André Draszik,
stable
Lockdep reports the following with CONFIG_PROVE_RAW_LOCK_NESTING=y:
[ BUG: Invalid wait context ]
swapper/0/0 is trying to lock:
(&dev->power.lock){-...}-{3:3}, at: pm_wakeup_dev_event+0x38/0x80
other info that might help us debug this:
context-{2:2}
locks held by swapper/0/0: 0, on CPU#0
Call trace:
_raw_spin_lock_irqsave+0x60/0x98
pm_wakeup_dev_event+0x38/0x80
max_tcpci_isr+0x2c/0x58 [tcpci_maxim]
__handle_irq_event_percpu+0xc4/0x4d8
handle_irq_event+0x4c/0x100
handle_level_irq+0xe8/0x188
max_tcpci_isr() calls pm_wakeup_event(), which acquires two spinlocks
(spinlock_t): dev->power.lock and the lock of the device's wakeup
source. On PREEMPT_RT, spinlock_t turns into a sleeping lock. Since the
interrupt is requested with IRQF_ONESHOT, max_tcpci_isr() is never
force-threaded and runs in hard irq context even on PREEMPT_RT. Taking
a sleeping lock in hard irq context is invalid, triggering the lockdep
report above.
Move pm_wakeup_event() to the interrupt thread max_tcpci_irq() instead.
Drop max_tcpci_isr() altogether, since its chip->port check is already
duplicated in max_tcpci_irq(), and request the interrupt without a
primary handler.
Note: Moving pm_wakeup_event() to the interrupt thread doesn't allow
the system to suspend before the event is reported:
suspend_device_irqs() uses synchronize_irq() to wait for the interrupt
thread to finish, and pm_wakeup_pending() is checked after
suspend_device_irqs() returns. Once suspend_device_irqs() has armed the
wake interrupt, the interrupt core reports the wakeup itself and
doesn't call the driver's handlers.
Fixes: 6f413b559f86 ("usb: typec: tcpci_maxim: Chip level TCPC driver")
Cc: stable@vger.kernel.org
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: André Draszik <andre.draszik@linaro.org>
---
drivers/usb/typec/tcpm/tcpci_maxim_core.c | 16 +++-------------
1 file changed, 3 insertions(+), 13 deletions(-)
diff --git a/drivers/usb/typec/tcpm/tcpci_maxim_core.c b/drivers/usb/typec/tcpm/tcpci_maxim_core.c
index a19f52515429..6e202171f57a 100644
--- a/drivers/usb/typec/tcpm/tcpci_maxim_core.c
+++ b/drivers/usb/typec/tcpm/tcpci_maxim_core.c
@@ -411,6 +411,8 @@ static irqreturn_t max_tcpci_irq(int irq, void *dev_id)
irqreturn_t irq_return = IRQ_HANDLED;
int ret;
+ pm_wakeup_event(chip->dev, PD_ACTIVITY_TIMEOUT_MS);
+
if (!chip->port)
return IRQ_HANDLED;
@@ -430,18 +432,6 @@ static irqreturn_t max_tcpci_irq(int irq, void *dev_id)
return irq_return;
}
-static irqreturn_t max_tcpci_isr(int irq, void *dev_id)
-{
- struct max_tcpci_chip *chip = dev_id;
-
- pm_wakeup_event(chip->dev, PD_ACTIVITY_TIMEOUT_MS);
-
- if (!chip->port)
- return IRQ_HANDLED;
-
- return IRQ_WAKE_THREAD;
-}
-
static int max_tcpci_start_toggling(struct tcpci *tcpci, struct tcpci_data *tdata,
enum typec_cc_status cc)
{
@@ -538,7 +528,7 @@ static int max_tcpci_probe(struct i2c_client *client)
chip->port = tcpci_get_tcpm_port(chip->tcpci);
- ret = devm_request_threaded_irq(&client->dev, client->irq, max_tcpci_isr, max_tcpci_irq,
+ ret = devm_request_threaded_irq(&client->dev, client->irq, NULL, max_tcpci_irq,
(IRQF_TRIGGER_LOW | IRQF_ONESHOT), dev_name(chip->dev),
chip);
if (ret < 0)
--
2.56.1.831.g720f3f5937-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/4] usb: typec: tcpm/tcpci_maxim: init wakeup before irq
2026-11-25 12:16 [PATCH v2 0/4] usb: typec: tcpm/tcpci_maxim: lockdep, wakeup and vbus regulator fixes André Draszik
2026-11-25 12:16 ` [PATCH v2 1/4] usb: typec: tcpm/tcpci_maxim: fix invalid wait context André Draszik
@ 2026-11-25 12:16 ` André Draszik
2026-11-25 12:16 ` [PATCH v2 3/4] usb: typec: tcpm/tcpci_maxim: fix vbus regulator UAF on unbind André Draszik
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: André Draszik @ 2026-11-25 12:16 UTC (permalink / raw)
To: Heikki Krogerus, Greg Kroah-Hartman, Badhri Jagan Sridharan
Cc: Sebastian Andrzej Siewior, Clark Williams, Steven Rostedt,
Peter Griffin, Tudor Ambarus, Juan Yescas, Amit Sunil Dhamne,
kernel-team, linux-usb, linux-rt-devel, André Draszik,
stable
max_tcpci_probe() requests the TCPC interrupt before it initialises
the wakeup source of the device. Since the interrupt is level
triggered, an already asserted alert can trigger the interrupt handler
before devm_device_init_wakeup() is called. Its pm_wakeup_event() does
nothing while the device has no wakeup source, so the wakeup event of
such an early interrupt is not recorded, meaning the system is then not
prevented from suspending for PD_ACTIVITY_TIMEOUT_MS while handling
that alert.
When the driver unbinds, devres works in reverse order and in this case
removes the wakeup source before it frees the interrupt, which leaves a
similar window.
Call devm_device_init_wakeup() before devm_request_threaded_irq(), so
that the wakeup source exists for as long as the interrupt handler can
run.
Fixes: 6f413b559f86 ("usb: typec: tcpci_maxim: Chip level TCPC driver")
Cc: stable@vger.kernel.org
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: André Draszik <andre.draszik@linaro.org>
---
drivers/usb/typec/tcpm/tcpci_maxim_core.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/usb/typec/tcpm/tcpci_maxim_core.c b/drivers/usb/typec/tcpm/tcpci_maxim_core.c
index 6e202171f57a..2bb306b6b1f9 100644
--- a/drivers/usb/typec/tcpm/tcpci_maxim_core.c
+++ b/drivers/usb/typec/tcpm/tcpci_maxim_core.c
@@ -528,16 +528,16 @@ static int max_tcpci_probe(struct i2c_client *client)
chip->port = tcpci_get_tcpm_port(chip->tcpci);
+ ret = devm_device_init_wakeup(chip->dev);
+ if (ret)
+ return dev_err_probe(chip->dev, ret, "Failed to init wakeup\n");
+
ret = devm_request_threaded_irq(&client->dev, client->irq, NULL, max_tcpci_irq,
(IRQF_TRIGGER_LOW | IRQF_ONESHOT), dev_name(chip->dev),
chip);
if (ret < 0)
return ret;
- ret = devm_device_init_wakeup(chip->dev);
- if (ret)
- return dev_err_probe(chip->dev, ret, "Failed to init wakeup\n");
-
return 0;
}
--
2.56.1.831.g720f3f5937-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 3/4] usb: typec: tcpm/tcpci_maxim: fix vbus regulator UAF on unbind
2026-11-25 12:16 [PATCH v2 0/4] usb: typec: tcpm/tcpci_maxim: lockdep, wakeup and vbus regulator fixes André Draszik
2026-11-25 12:16 ` [PATCH v2 1/4] usb: typec: tcpm/tcpci_maxim: fix invalid wait context André Draszik
2026-11-25 12:16 ` [PATCH v2 2/4] usb: typec: tcpm/tcpci_maxim: init wakeup before irq André Draszik
@ 2026-11-25 12:16 ` André Draszik
2026-11-25 12:16 ` [PATCH v2 4/4] usb: typec: tcpm/tcpci_maxim: only complain about vbus when sourcing André Draszik
2026-11-25 12:21 ` [PATCH v2 0/4] usb: typec: tcpm/tcpci_maxim: lockdep, wakeup and vbus regulator fixes sashiko-bot
4 siblings, 0 replies; 6+ messages in thread
From: André Draszik @ 2026-11-25 12:16 UTC (permalink / raw)
To: Heikki Krogerus, Greg Kroah-Hartman, Badhri Jagan Sridharan
Cc: Sebastian Andrzej Siewior, Clark Williams, Steven Rostedt,
Peter Griffin, Tudor Ambarus, Juan Yescas, Amit Sunil Dhamne,
kernel-team, linux-usb, linux-rt-devel, André Draszik,
stable
Unbinding the tcpci_maxim driver triggers a use-after-free in
regulator_disable() if the driver has acquired the vbus regulator:
Unable to handle kernel paging request at virtual address
006b6b6b6b6b6bb7
pc : regulator_lock_recursive+0x20/0x218
lr : regulator_lock_dependent+0x198/0x2c0
Call trace:
regulator_lock_recursive+0x20/0x218 (P)
regulator_lock_dependent+0x198/0x2c0
regulator_disable+0x4c/0x100
max_tcpci_set_vbus+0x70/0x108 [tcpci_maxim]
tcpci_set_vbus+0x44/0x100 [tcpci]
tcpm_reset_port+0x13c/0x288 [tcpm]
tcpm_unregister_port+0x70/0x120 [tcpm]
tcpci_unregister_port+0x24/0x68 [tcpci]
max_tcpci_unregister_tcpci_port+0x18/0x30 [tcpci_maxim]
devm_action_release+0x1c/0x30
max_tcpci_set_vbus() obtains chip->vbus_reg lazily via
devm_regulator_get_exclusive(). When the regulator is acquired after
max_tcpci_probe() has queued max_tcpci_unregister_tcpci_port() with
devm_add_action_or_reset(), devres releases resources in reverse order
and frees the regulator handle before max_tcpci_unregister_tcpci_port()
unregisters the port and max_tcpci_set_vbus() accesses chip->vbus_reg.
Switch to regulator_get_exclusive() and register a devres cleanup action
for regulator_put() before tcpci_register_port(), so the port is
unregistered and tcpm_reset_port() disables VBUS before the regulator
handle is released.
Fixes: 0c8935642cb0 ("usb: typec: tcpm/tcpci_maxim: deprecate WAR for setting charger mode")
Cc: stable@vger.kernel.org
Signed-off-by: André Draszik <andre.draszik@linaro.org>
---
drivers/usb/typec/tcpm/tcpci_maxim_core.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/typec/tcpm/tcpci_maxim_core.c b/drivers/usb/typec/tcpm/tcpci_maxim_core.c
index 2bb306b6b1f9..2e6a8906fb32 100644
--- a/drivers/usb/typec/tcpm/tcpci_maxim_core.c
+++ b/drivers/usb/typec/tcpm/tcpci_maxim_core.c
@@ -209,8 +209,7 @@ static void process_rx(struct max_tcpci_chip *chip, u16 status)
static int get_vbus_regulator_handle(struct max_tcpci_chip *chip)
{
if (IS_ERR_OR_NULL(chip->vbus_reg)) {
- chip->vbus_reg = devm_regulator_get_exclusive(chip->dev,
- "vbus");
+ chip->vbus_reg = regulator_get_exclusive(chip->dev, "vbus");
if (IS_ERR_OR_NULL(chip->vbus_reg)) {
dev_err(chip->dev,
"Failed to get vbus regulator handle\n");
@@ -221,6 +220,14 @@ static int get_vbus_regulator_handle(struct max_tcpci_chip *chip)
return 0;
}
+static void max_tcpci_put_vbus_regulator(void *data)
+{
+ struct max_tcpci_chip *chip = data;
+
+ if (!IS_ERR_OR_NULL(chip->vbus_reg))
+ regulator_put(chip->vbus_reg);
+}
+
static int max_tcpci_set_vbus(struct tcpci *tcpci, struct tcpci_data *tdata, bool source, bool sink)
{
struct max_tcpci_chip *chip = tdata_to_max_tcpci(tdata);
@@ -514,6 +521,11 @@ static int max_tcpci_probe(struct i2c_client *client)
chip->data.cable_comm_capable = true;
chip->data.attempt_vconn_swap_discovery = max_tcpci_attempt_vconn_swap_discovery;
+ ret = devm_add_action_or_reset(&client->dev,
+ max_tcpci_put_vbus_regulator, chip);
+ if (ret)
+ return ret;
+
max_tcpci_init_regs(chip);
chip->tcpci = tcpci_register_port(chip->dev, &chip->data);
if (IS_ERR(chip->tcpci))
--
2.56.1.831.g720f3f5937-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 4/4] usb: typec: tcpm/tcpci_maxim: only complain about vbus when sourcing
2026-11-25 12:16 [PATCH v2 0/4] usb: typec: tcpm/tcpci_maxim: lockdep, wakeup and vbus regulator fixes André Draszik
` (2 preceding siblings ...)
2026-11-25 12:16 ` [PATCH v2 3/4] usb: typec: tcpm/tcpci_maxim: fix vbus regulator UAF on unbind André Draszik
@ 2026-11-25 12:16 ` André Draszik
2026-11-25 12:21 ` [PATCH v2 0/4] usb: typec: tcpm/tcpci_maxim: lockdep, wakeup and vbus regulator fixes sashiko-bot
4 siblings, 0 replies; 6+ messages in thread
From: André Draszik @ 2026-11-25 12:16 UTC (permalink / raw)
To: Heikki Krogerus, Greg Kroah-Hartman, Badhri Jagan Sridharan
Cc: Sebastian Andrzej Siewior, Clark Williams, Steven Rostedt,
Peter Griffin, Tudor Ambarus, Juan Yescas, Amit Sunil Dhamne,
kernel-team, linux-usb, linux-rt-devel, André Draszik
get_vbus_regulator_handle() logs a spurious "Failed to get vbus
regulator handle" error during probe and stores the ERR_PTR in
chip->vbus_reg even when sourcing VBUS is not requested.
During tcpci_register_port(), tcpm_init_vbus() calls set_vbus(false,
false) before the PMIC charger providing the vbus regulator has probed
(the charger's power supply waits for the TCPM power supply), or on
sink-only boards without a vbus regulator. Sink-only operation does not
need the vbus regulator, and max_tcpci_set_vbus() already ignores
regulator lookup failures when source is false.
Leave chip->vbus_reg untouched when regulator_get_exclusive() fails,
return the error from get_vbus_regulator_handle() silently, and log an
error in max_tcpci_set_vbus() only when sourcing is requested.
Fixes: 0c8935642cb0 ("usb: typec: tcpm/tcpci_maxim: deprecate WAR for setting charger mode")
Signed-off-by: André Draszik <andre.draszik@linaro.org>
---
drivers/usb/typec/tcpm/tcpci_maxim_core.c | 26 ++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/drivers/usb/typec/tcpm/tcpci_maxim_core.c b/drivers/usb/typec/tcpm/tcpci_maxim_core.c
index 2e6a8906fb32..736d01694745 100644
--- a/drivers/usb/typec/tcpm/tcpci_maxim_core.c
+++ b/drivers/usb/typec/tcpm/tcpci_maxim_core.c
@@ -208,15 +208,16 @@ static void process_rx(struct max_tcpci_chip *chip, u16 status)
static int get_vbus_regulator_handle(struct max_tcpci_chip *chip)
{
- if (IS_ERR_OR_NULL(chip->vbus_reg)) {
- chip->vbus_reg = regulator_get_exclusive(chip->dev, "vbus");
- if (IS_ERR_OR_NULL(chip->vbus_reg)) {
- dev_err(chip->dev,
- "Failed to get vbus regulator handle\n");
- return -ENODEV;
- }
- }
+ struct regulator *reg;
+
+ if (chip->vbus_reg)
+ return 0;
+ reg = regulator_get_exclusive(chip->dev, "vbus");
+ if (IS_ERR(reg))
+ return PTR_ERR(reg);
+
+ chip->vbus_reg = reg;
return 0;
}
@@ -224,7 +225,7 @@ static void max_tcpci_put_vbus_regulator(void *data)
{
struct max_tcpci_chip *chip = data;
- if (!IS_ERR_OR_NULL(chip->vbus_reg))
+ if (chip->vbus_reg)
regulator_put(chip->vbus_reg);
}
@@ -244,7 +245,12 @@ static int max_tcpci_set_vbus(struct tcpci *tcpci, struct tcpci_data *tdata, boo
* Regulator is not necessary for sink only applications. Return
* success in cases where sink mode is being modified.
*/
- return source ? ret : 1;
+ if (!source)
+ return 1;
+
+ dev_err(chip->dev, "Failed to get vbus regulator: %pe\n",
+ ERR_PTR(ret));
+ return ret;
}
if (source) {
--
2.56.1.831.g720f3f5937-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/4] usb: typec: tcpm/tcpci_maxim: lockdep, wakeup and vbus regulator fixes
2026-11-25 12:16 [PATCH v2 0/4] usb: typec: tcpm/tcpci_maxim: lockdep, wakeup and vbus regulator fixes André Draszik
` (3 preceding siblings ...)
2026-11-25 12:16 ` [PATCH v2 4/4] usb: typec: tcpm/tcpci_maxim: only complain about vbus when sourcing André Draszik
@ 2026-11-25 12:21 ` sashiko-bot
4 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-25 12:21 UTC (permalink / raw)
To: André Draszik; +Cc: linux-usb
Sashiko has reviewed this 4-patch series and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-max77759-wait-v2-0-9914b985c00b@linaro.org
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-25 12:21 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 12:16 [PATCH v2 0/4] usb: typec: tcpm/tcpci_maxim: lockdep, wakeup and vbus regulator fixes André Draszik
2026-11-25 12:16 ` [PATCH v2 1/4] usb: typec: tcpm/tcpci_maxim: fix invalid wait context André Draszik
2026-11-25 12:16 ` [PATCH v2 2/4] usb: typec: tcpm/tcpci_maxim: init wakeup before irq André Draszik
2026-11-25 12:16 ` [PATCH v2 3/4] usb: typec: tcpm/tcpci_maxim: fix vbus regulator UAF on unbind André Draszik
2026-11-25 12:16 ` [PATCH v2 4/4] usb: typec: tcpm/tcpci_maxim: only complain about vbus when sourcing André Draszik
2026-11-25 12:21 ` [PATCH v2 0/4] usb: typec: tcpm/tcpci_maxim: lockdep, wakeup and vbus regulator fixes sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox