mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/2] usb: phy: twl6030: fix comparator init order and teardown cleanup
@ 2026-11-27 13:39 Bin Luo (University of Electronic Science and Technology of China)
  2026-11-27 13:39 ` [PATCH v2 1/2] usb: phy: twl6030: initialize lock and work before registering comparator Bin Luo (University of Electronic Science and Technology of China)
  2026-11-27 13:39 ` [PATCH v2 2/2] usb: phy: twl6030: clear comparator on probe failure and remove Bin Luo (University of Electronic Science and Technology of China)
  0 siblings, 2 replies; 3+ messages in thread
From: Bin Luo (University of Electronic Science and Technology of China) @ 2026-11-27 13:39 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, linux-kernel

Hi Greg,

This v2 series addresses your review feedback on v1:
- Drop the unnecessary comment in twl6030_usb_probe().
- Split the v1 patch into two single-purpose patches:
  1/2 initializes twl->lock and work items before registering the
      comparator with omap_usb2_set_comparator().
  2/2 clears the comparator via omap_usb2_set_comparator(NULL) and
      cancels set_vbus_work on probe failure paths and in
      twl6030_usb_remove().

Note on drivers/phy/ti/phy-omap-usb2.c:
Automated review pointed out that omap_usb2_set_comparator() and its
comparator readers in drivers/phy/ti/phy-omap-usb2.c do not currently
synchronize concurrent updates to phy->comparator. Fixing that requires
adding synchronization in the TI PHY driver (a separate subsystem);
this series focuses on fixing the initialization ordering and missing
unregistration bugs in phy-twl6030-usb.c.

Bin Luo (University of Electronic Science and Technology of China) (2):
  usb: phy: twl6030: initialize lock and work before registering
    comparator
  usb: phy: twl6030: clear comparator on probe failure and remove

 drivers/usb/phy/phy-twl6030-usb.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

-- 
2.43.0

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2 1/2] usb: phy: twl6030: initialize lock and work before registering comparator
  2026-11-27 13:39 [PATCH v2 0/2] usb: phy: twl6030: fix comparator init order and teardown cleanup Bin Luo (University of Electronic Science and Technology of China)
@ 2026-11-27 13:39 ` Bin Luo (University of Electronic Science and Technology of China)
  2026-11-27 13:39 ` [PATCH v2 2/2] usb: phy: twl6030: clear comparator on probe failure and remove Bin Luo (University of Electronic Science and Technology of China)
  1 sibling, 0 replies; 3+ messages in thread
From: Bin Luo (University of Electronic Science and Technology of China) @ 2026-11-27 13:39 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, linux-kernel

twl6030_usb_probe() publishes &twl->comparator via
omap_usb2_set_comparator() before initializing twl->lock,
twl->set_vbus_work, and twl->get_status_work. If the OMAP USB2 PHY
invokes twl6030_set_vbus() in that window, schedule_work() operates on
an uninitialized work_struct.

Initialize twl->lock and the work items before calling
omap_usb2_set_comparator().

Found by static code audit.

Fixes: 0e98de67bacb ("usb: otg: make twl6030_usb as a comparator driver to omap_usb2")
Signed-off-by: Bin Luo (University of Electronic Science and Technology of China) <luob87709@gmail.com>
---
 drivers/usb/phy/phy-twl6030-usb.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/phy/phy-twl6030-usb.c b/drivers/usb/phy/phy-twl6030-usb.c
index 9bfcb2c..b28a94b 100644
--- a/drivers/usb/phy/phy-twl6030-usb.c
+++ b/drivers/usb/phy/phy-twl6030-usb.c
@@ -355,15 +355,16 @@ static int twl6030_usb_probe(struct platform_device *pdev)
 	twl->comparator.set_vbus	= twl6030_set_vbus;
 	twl->comparator.start_srp	= twl6030_start_srp;
 
+	spin_lock_init(&twl->lock);
+	INIT_WORK(&twl->set_vbus_work, otg_set_vbus_work);
+	INIT_DELAYED_WORK(&twl->get_status_work, twl6030_status_work);
+
 	ret = omap_usb2_set_comparator(&twl->comparator);
 	if (ret == -ENODEV) {
 		dev_info(&pdev->dev, "phy not ready, deferring probe");
 		return -EPROBE_DEFER;
 	}
 
-	/* init spinlock for workqueue */
-	spin_lock_init(&twl->lock);
-
 	err = twl6030_usb_ldo_init(twl);
 	if (err) {
 		dev_err(&pdev->dev, "ldo init failed\n");
@@ -372,9 +373,6 @@ static int twl6030_usb_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, twl);
 
-	INIT_WORK(&twl->set_vbus_work, otg_set_vbus_work);
-	INIT_DELAYED_WORK(&twl->get_status_work, twl6030_status_work);
-
 	status = request_threaded_irq(twl->irq1, NULL, twl6030_usbotg_irq,
 			IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | IRQF_ONESHOT,
 			"twl6030_usb", twl);
-- 
2.51.0.windows.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2 2/2] usb: phy: twl6030: clear comparator on probe failure and remove
  2026-11-27 13:39 [PATCH v2 0/2] usb: phy: twl6030: fix comparator init order and teardown cleanup Bin Luo (University of Electronic Science and Technology of China)
  2026-11-27 13:39 ` [PATCH v2 1/2] usb: phy: twl6030: initialize lock and work before registering comparator Bin Luo (University of Electronic Science and Technology of China)
@ 2026-11-27 13:39 ` Bin Luo (University of Electronic Science and Technology of China)
  1 sibling, 0 replies; 3+ messages in thread
From: Bin Luo (University of Electronic Science and Technology of China) @ 2026-11-27 13:39 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, linux-kernel

Neither the probe error paths after omap_usb2_set_comparator() nor
twl6030_usb_remove() clears the registered comparator pointer. Because
twl is devm-allocated, a subsequent VBUS or SRP callback from the OMAP
USB2 PHY dereferences freed twl memory and may schedule set_vbus_work
after teardown.

Clear the comparator with omap_usb2_set_comparator(NULL) and cancel
set_vbus_work on probe failure paths, and clear the comparator at the
start of twl6030_usb_remove().

Found by static code audit.

Fixes: 0e98de67bacb ("usb: otg: make twl6030_usb as a comparator driver to omap_usb2")
Signed-off-by: Bin Luo (University of Electronic Science and Technology of China) <luob87709@gmail.com>
---
 drivers/usb/phy/phy-twl6030-usb.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/phy/phy-twl6030-usb.c b/drivers/usb/phy/phy-twl6030-usb.c
index b28a94b..5ea0bfc 100644
--- a/drivers/usb/phy/phy-twl6030-usb.c
+++ b/drivers/usb/phy/phy-twl6030-usb.c
@@ -368,7 +368,8 @@ static int twl6030_usb_probe(struct platform_device *pdev)
 	err = twl6030_usb_ldo_init(twl);
 	if (err) {
 		dev_err(&pdev->dev, "ldo init failed\n");
-		return err;
+		status = err;
+		goto err_clear_comparator;
 	}
 
 	platform_set_drvdata(pdev, twl);
@@ -402,6 +403,9 @@ err_free_irq1:
 	free_irq(twl->irq1, twl);
 err_put_regulator:
 	regulator_put(twl->usb3v3);
+err_clear_comparator:
+	omap_usb2_set_comparator(NULL);
+	cancel_work_sync(&twl->set_vbus_work);
 
 	return status;
 }
@@ -410,6 +414,7 @@ static void twl6030_usb_remove(struct platform_device *pdev)
 {
 	struct twl6030_usb *twl = platform_get_drvdata(pdev);
 
+	omap_usb2_set_comparator(NULL);
 	cancel_delayed_work_sync(&twl->get_status_work);
 	twl6030_interrupt_mask(TWL6030_USBOTG_INT_MASK,
 		REG_INT_MSK_LINE_C);
-- 
2.51.0.windows.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-27 13:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-27 13:39 [PATCH v2 0/2] usb: phy: twl6030: fix comparator init order and teardown cleanup Bin Luo (University of Electronic Science and Technology of China)
2026-11-27 13:39 ` [PATCH v2 1/2] usb: phy: twl6030: initialize lock and work before registering comparator Bin Luo (University of Electronic Science and Technology of China)
2026-11-27 13:39 ` [PATCH v2 2/2] usb: phy: twl6030: clear comparator on probe failure and remove Bin Luo (University of Electronic Science and Technology of China)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®