mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] USB: ohci-nxp: Fix error handling in ohci-hcd-nxp driver
@ 2025-11-16  1:06 Ma Ke
  2025-11-16  2:02 ` Alan Stern
  2025-11-17 19:37 ` Vladimir Zapolskiy
  0 siblings, 2 replies; 3+ messages in thread
From: Ma Ke @ 2025-11-16  1:06 UTC (permalink / raw)
  To: stern, vz, piotr.wojtaszczyk, gregkh, stigge, arnd
  Cc: linux-usb, linux-arm-kernel, linux-kernel, akpm, Ma Ke, stable

When obtaining the ISP1301 I2C client through the device tree, the
driver does not release the device reference in the probe failure path
or in the remove function. This could cause a reference count leak,
which may prevent the device from being properly unbound or freed,
leading to resource leakage. Add put_device() to release the reference
in the probe failure path and in the remove function.

Found by code review.

Cc: stable@vger.kernel.org
Fixes: 73108aa90cbf ("USB: ohci-nxp: Use isp1301 driver")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
 drivers/usb/host/ohci-nxp.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/usb/host/ohci-nxp.c b/drivers/usb/host/ohci-nxp.c
index 24d5a1dc5056..f79558ef0b45 100644
--- a/drivers/usb/host/ohci-nxp.c
+++ b/drivers/usb/host/ohci-nxp.c
@@ -223,6 +223,8 @@ static int ohci_hcd_nxp_probe(struct platform_device *pdev)
 fail_resource:
 	usb_put_hcd(hcd);
 fail_disable:
+	if (isp1301_i2c_client)
+		put_device(&isp1301_i2c_client->dev);
 	isp1301_i2c_client = NULL;
 	return ret;
 }
@@ -234,6 +236,8 @@ static void ohci_hcd_nxp_remove(struct platform_device *pdev)
 	usb_remove_hcd(hcd);
 	ohci_nxp_stop_hc();
 	usb_put_hcd(hcd);
+	if (isp1301_i2c_client)
+		put_device(&isp1301_i2c_client->dev);
 	isp1301_i2c_client = NULL;
 }
 
-- 
2.17.1


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

* Re: [PATCH] USB: ohci-nxp: Fix error handling in ohci-hcd-nxp driver
  2025-11-16  1:06 [PATCH] USB: ohci-nxp: Fix error handling in ohci-hcd-nxp driver Ma Ke
@ 2025-11-16  2:02 ` Alan Stern
  2025-11-17 19:37 ` Vladimir Zapolskiy
  1 sibling, 0 replies; 3+ messages in thread
From: Alan Stern @ 2025-11-16  2:02 UTC (permalink / raw)
  To: Ma Ke
  Cc: vz, piotr.wojtaszczyk, gregkh, stigge, arnd, linux-usb,
	linux-arm-kernel, linux-kernel, akpm, stable

On Sun, Nov 16, 2025 at 09:06:13AM +0800, Ma Ke wrote:
> When obtaining the ISP1301 I2C client through the device tree, the

What if the client is obtained not through the device tree but through 
normal I2C probing?  See the isp1301_get_client() routine in 
drivers/usb/phy/phy-isp1301.c.

> driver does not release the device reference in the probe failure path
> or in the remove function. This could cause a reference count leak,
> which may prevent the device from being properly unbound or freed,
> leading to resource leakage. Add put_device() to release the reference
> in the probe failure path and in the remove function.
> 
> Found by code review.
> 
> Cc: stable@vger.kernel.org
> Fixes: 73108aa90cbf ("USB: ohci-nxp: Use isp1301 driver")
> Signed-off-by: Ma Ke <make24@iscas.ac.cn>
> ---
>  drivers/usb/host/ohci-nxp.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/usb/host/ohci-nxp.c b/drivers/usb/host/ohci-nxp.c
> index 24d5a1dc5056..f79558ef0b45 100644
> --- a/drivers/usb/host/ohci-nxp.c
> +++ b/drivers/usb/host/ohci-nxp.c
> @@ -223,6 +223,8 @@ static int ohci_hcd_nxp_probe(struct platform_device *pdev)
>  fail_resource:
>  	usb_put_hcd(hcd);
>  fail_disable:
> +	if (isp1301_i2c_client)

This test is not needed; there is no way to get here if 
isp1301_i2c_client is NULL.

> +		put_device(&isp1301_i2c_client->dev);
>  	isp1301_i2c_client = NULL;
>  	return ret;
>  }
> @@ -234,6 +236,8 @@ static void ohci_hcd_nxp_remove(struct platform_device *pdev)
>  	usb_remove_hcd(hcd);
>  	ohci_nxp_stop_hc();
>  	usb_put_hcd(hcd);
> +	if (isp1301_i2c_client)

The same is true for this test.

Alan Stern

> +		put_device(&isp1301_i2c_client->dev);
>  	isp1301_i2c_client = NULL;
>  }
>  
> -- 
> 2.17.1
> 

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

* Re: [PATCH] USB: ohci-nxp: Fix error handling in ohci-hcd-nxp driver
  2025-11-16  1:06 [PATCH] USB: ohci-nxp: Fix error handling in ohci-hcd-nxp driver Ma Ke
  2025-11-16  2:02 ` Alan Stern
@ 2025-11-17 19:37 ` Vladimir Zapolskiy
  1 sibling, 0 replies; 3+ messages in thread
From: Vladimir Zapolskiy @ 2025-11-17 19:37 UTC (permalink / raw)
  To: Ma Ke, stern, piotr.wojtaszczyk, gregkh, stigge, arnd
  Cc: linux-usb, linux-arm-kernel, linux-kernel, akpm, stable

On 11/16/25 03:06, Ma Ke wrote:
> When obtaining the ISP1301 I2C client through the device tree, the
> driver does not release the device reference in the probe failure path
> or in the remove function. This could cause a reference count leak,
> which may prevent the device from being properly unbound or freed,
> leading to resource leakage. Add put_device() to release the reference
> in the probe failure path and in the remove function.
> 
> Found by code review.
> 
> Cc: stable@vger.kernel.org
> Fixes: 73108aa90cbf ("USB: ohci-nxp: Use isp1301 driver")
> Signed-off-by: Ma Ke <make24@iscas.ac.cn>
> ---
>   drivers/usb/host/ohci-nxp.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/usb/host/ohci-nxp.c b/drivers/usb/host/ohci-nxp.c
> index 24d5a1dc5056..f79558ef0b45 100644
> --- a/drivers/usb/host/ohci-nxp.c
> +++ b/drivers/usb/host/ohci-nxp.c
> @@ -223,6 +223,8 @@ static int ohci_hcd_nxp_probe(struct platform_device *pdev)
>   fail_resource:
>   	usb_put_hcd(hcd);
>   fail_disable:
> +	if (isp1301_i2c_client)
> +		put_device(&isp1301_i2c_client->dev);
>   	isp1301_i2c_client = NULL;
>   	return ret;
>   }
> @@ -234,6 +236,8 @@ static void ohci_hcd_nxp_remove(struct platform_device *pdev)
>   	usb_remove_hcd(hcd);
>   	ohci_nxp_stop_hc();
>   	usb_put_hcd(hcd);
> +	if (isp1301_i2c_client)
> +		put_device(&isp1301_i2c_client->dev);
>   	isp1301_i2c_client = NULL;
>   }
>   

For v2 please remove checks for !isp1301_i2c_client as pointed out by Alan Stern,
and then feel free to add

Reviewed-by: Vladimir Zapolskiy <vz@mleia.com>

-- 
Best wishes,
Vladimir

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

end of thread, other threads:[~2025-11-17 19:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-16  1:06 [PATCH] USB: ohci-nxp: Fix error handling in ohci-hcd-nxp driver Ma Ke
2025-11-16  2:02 ` Alan Stern
2025-11-17 19:37 ` Vladimir Zapolskiy

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®