public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn>
Cc: heikki.krogerus@linux.intel.com, sean.anderson@seco.com,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] usb: ulpi: fix a double free in ulpi_register_interface()
Date: Tue, 23 Dec 2025 15:27:28 +0100	[thread overview]
Message-ID: <2025122313-pebbly-petunia-5f2d@gregkh> (raw)
In-Reply-To: <20251219154859.650819-1-lihaoxiang@isrc.iscas.ac.cn>

On Fri, Dec 19, 2025 at 11:48:59PM +0800, Haoxiang Li wrote:
> If ulpi_register() fails, put_device() is called in ulpi_register(),
> kfree() in ulpi_register_interface() will result in a double free.
> 
> Also, refactor the device registration sequence to use a unified
> put_device() cleanup path, addressing multiple error returns in
> ulpi_register().
> 
> Found by code review and compiled on ubuntu 20.04.

"compiled on" doesn't really provide any information, sorry.  Espeically
for a VERY old distro release :(

How was this tested?

> Fixes: 0a907ee9d95e ("usb: ulpi: Call of_node_put correctly")
> Cc: stable@vger.kernel.org
> Signed-off-by: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn>
> ---
>  drivers/usb/common/ulpi.c | 25 ++++++++++++-------------
>  1 file changed, 12 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c
> index 4a2ee447b213..c81a0cb24067 100644
> --- a/drivers/usb/common/ulpi.c
> +++ b/drivers/usb/common/ulpi.c
> @@ -278,6 +278,7 @@ static int ulpi_register(struct device *dev, struct ulpi *ulpi)
>  	int ret;
>  	struct dentry *root;
>  
> +	device_initialize(&ulpi->dev);
>  	ulpi->dev.parent = dev; /* needed early for ops */
>  	ulpi->dev.bus = &ulpi_bus;
>  	ulpi->dev.type = &ulpi_dev_type;
> @@ -287,19 +288,15 @@ static int ulpi_register(struct device *dev, struct ulpi *ulpi)
>  
>  	ret = ulpi_of_register(ulpi);
>  	if (ret)
> -		return ret;
> +		goto err_register;
>  
>  	ret = ulpi_read_id(ulpi);
> -	if (ret) {
> -		of_node_put(ulpi->dev.of_node);
> -		return ret;
> -	}
> +	if (ret)
> +		goto err_register;
>  
> -	ret = device_register(&ulpi->dev);

Splitting this up into init/add instead of just register is usually only
done if you _HAVE_ to do that.  I really don't see why that is required
here at all, sorry.  Are you sure this is the correct solution?

thanks,

greg k-h

      reply	other threads:[~2025-12-23 14:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-19 15:48 [PATCH] usb: ulpi: fix a double free in ulpi_register_interface() Haoxiang Li
2025-12-23 14:27 ` Greg KH [this message]

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=2025122313-pebbly-petunia-5f2d@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=lihaoxiang@isrc.iscas.ac.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=sean.anderson@seco.com \
    --cc=stable@vger.kernel.org \
    /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