Linux USB
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: "Bin Luo (University of Electronic Science and Technology of
	China)" <luob87709@gmail.com>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] usb: phy: twl6030: clear comparator on probe failure and remove
Date: Thu, 3 Dec 2026 20:09:56 +0100	[thread overview]
Message-ID: <2026120350-freeing-marine-3e31@gregkh> (raw)
In-Reply-To: <20261127133923.1452-3-luob87709@gmail.com>

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

Please test on the real hardware.

  reply	other threads:[~2026-12-04  3:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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-12-03 19:09   ` Greg KH
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)
2026-12-03 19:09   ` Greg KH [this message]
2026-11-27 13:50 ` [PATCH v2 0/2] usb: phy: twl6030: fix comparator init order and teardown cleanup sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2026120350-freeing-marine-3e31@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=luob87709@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox