Re: [PATCH v2 1/2] usb: phy: twl6030: initialize lock and work before registering comparator

From: Greg KH

Date: Thu Dec 03 2026 - 22:25:34 EST


On Fri, Nov 27, 2026 at 09:39:22PM +0800, Bin Luo (University of Electronic Science and Technology of China) wrote:
> 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@xxxxxxxxx>
> ---
> 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
>
>

Please test on the real hardware first.