From 7ec5a7211cda47308f4eb0c6eda4ee240f17a801 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 17 Oct 2026 18:10:53 +1100 Subject: [PATCH] usb: typec: tipd: cd321x: Don't race the resume read in the IRQ test cd321x_ack_retry_across_sleep_test() asserted that the resume read was pending right after tipd_complete(). The driver queues that read with no delay, so on an SMP test machine a worker can already be running it, with the pending bit clear, and the test fails although the driver behaved correctly. With two CPUs it failed in 1 of 20 runs. Wait for the resume read with flush_work() instead. Unlike flush_delayed_work(), it does not run early the retry that the read schedules, so the loop that follows still sees exactly one retry pending after each read. Check that the resume read tried to read the events. The other pending and timer checks in the test look either at work that nothing can queue at that point, or at a retry scheduled at least 500 ms ahead. Not queueing the resume read, or giving up the retry after the cable-state budget, still makes the test fail, and now so does queueing the resume read late. Fixes: 7e97f2f5ee45 ("usb: typec: tipd: cd321x: Never leave interrupt events unacknowledged") Assisted-by: LLM Signed-off-by: Ryan Murray --- drivers/usb/typec/tipd/cd321x-irq-test.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/tipd/cd321x-irq-test.c b/drivers/usb/typec/tipd/cd321x-irq-test.c index 17ef778f96826..0c5067e9ab024 100644 --- a/drivers/usb/typec/tipd/cd321x-irq-test.c +++ b/drivers/usb/typec/tipd/cd321x-irq-test.c @@ -314,7 +314,7 @@ static void cd321x_ack_retry_across_sleep_test(struct kunit *test) { struct cd321x_test *t = cd321x_test_port(test); struct device *dev = t->cd.tps.dev; - unsigned int i; + unsigned int i, left; cd321x_test_raise(&t->ctrl, APPLE_CD_REG_INT_PLUG_EVENT); t->ctrl.failing_event_reads = UINT_MAX; @@ -324,7 +324,15 @@ static void cd321x_ack_retry_across_sleep_test(struct kunit *test) /* Sleep cancels the retry, and the resume read takes it over. */ KUNIT_ASSERT_EQ(test, tipd_prepare(dev), 0); KUNIT_EXPECT_FALSE(test, delayed_work_pending(&t->cd.resume_work)); + left = t->ctrl.failing_event_reads; tipd_complete(dev); + /* + * The resume read is queued without delay, so on SMP a worker may be + * running it already. Wait for it, without running the retry it + * schedules early, and check that it tried to read the events. + */ + flush_work(&t->cd.resume_work.work); + KUNIT_EXPECT_EQ(test, t->ctrl.failing_event_reads, left - 1); for (i = 0; i < 2 * CD321X_RESUME_ATTEMPTS; i++) { KUNIT_ASSERT_TRUE(test, delayed_work_pending(&t->cd.resume_work)); flush_delayed_work(&t->cd.resume_work);