public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: ulpi: fix double free in ulpi_register_interface() error path
@ 2026-04-01  2:51 Guangshuo Li
  2026-04-01 12:19 ` Heikki Krogerus
  0 siblings, 1 reply; 2+ messages in thread
From: Guangshuo Li @ 2026-04-01  2:51 UTC (permalink / raw)
  To: Heikki Krogerus, Greg Kroah-Hartman, David Cohen, Felipe Balbi,
	linux-usb, linux-kernel
  Cc: Guangshuo Li, stable

When device_register() fails, ulpi_register() calls put_device() on
ulpi->dev.

The device release callback ulpi_dev_release() drops the OF node
reference and frees ulpi, but the current error path in
ulpi_register_interface() then calls kfree(ulpi) again, causing a
double free.

Let put_device() handle the cleanup through ulpi_dev_release() and
avoid freeing ulpi again in ulpi_register_interface().

Fixes: 289fcff4bcdb1 ("usb: add bus type for USB ULPI")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
 drivers/usb/common/ulpi.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c
index 4a2ee447b213..d895cf6532a2 100644
--- a/drivers/usb/common/ulpi.c
+++ b/drivers/usb/common/ulpi.c
@@ -331,10 +331,9 @@ struct ulpi *ulpi_register_interface(struct device *dev,
 	ulpi->ops = ops;
 
 	ret = ulpi_register(dev, ulpi);
-	if (ret) {
-		kfree(ulpi);
+	if (ret)
 		return ERR_PTR(ret);
-	}
+
 
 	return ulpi;
 }
-- 
2.43.0


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

* Re: [PATCH] usb: ulpi: fix double free in ulpi_register_interface() error path
  2026-04-01  2:51 [PATCH] usb: ulpi: fix double free in ulpi_register_interface() error path Guangshuo Li
@ 2026-04-01 12:19 ` Heikki Krogerus
  0 siblings, 0 replies; 2+ messages in thread
From: Heikki Krogerus @ 2026-04-01 12:19 UTC (permalink / raw)
  To: Guangshuo Li
  Cc: Greg Kroah-Hartman, David Cohen, Felipe Balbi, linux-usb,
	linux-kernel, stable

On Wed, Apr 01, 2026 at 10:51:42AM +0800, Guangshuo Li wrote:
> When device_register() fails, ulpi_register() calls put_device() on
> ulpi->dev.
> 
> The device release callback ulpi_dev_release() drops the OF node
> reference and frees ulpi, but the current error path in
> ulpi_register_interface() then calls kfree(ulpi) again, causing a
> double free.
> 
> Let put_device() handle the cleanup through ulpi_dev_release() and
> avoid freeing ulpi again in ulpi_register_interface().
> 
> Fixes: 289fcff4bcdb1 ("usb: add bus type for USB ULPI")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/usb/common/ulpi.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c
> index 4a2ee447b213..d895cf6532a2 100644
> --- a/drivers/usb/common/ulpi.c
> +++ b/drivers/usb/common/ulpi.c
> @@ -331,10 +331,9 @@ struct ulpi *ulpi_register_interface(struct device *dev,
>  	ulpi->ops = ops;
>  
>  	ret = ulpi_register(dev, ulpi);
> -	if (ret) {
> -		kfree(ulpi);
> +	if (ret)
>  		return ERR_PTR(ret);
> -	}
> +
>  
>  	return ulpi;
>  }

-- 
heikki

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

end of thread, other threads:[~2026-04-01 12:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-01  2:51 [PATCH] usb: ulpi: fix double free in ulpi_register_interface() error path Guangshuo Li
2026-04-01 12:19 ` Heikki Krogerus

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