Skip to contentSkip to conversation

USB: ohci-nxp: Fix error handling in ohci-hcd-nxp driver

PATCH In review Ma Ke 3 participants 3 messages Nov 16, 2025 – Nov 17, 2025

Subsystems (4)
lore
Share & tools
lore

Ma Ke

author
#0 lore raw

PATCH 1/1 USB: ohci-nxp: Fix error handling in ohci-hcd-nxp driver

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.

Fixes 73108aa90cbf ("USB: ohci-nxp: Use isp1301 driver")
---
 drivers/usb/host/ohci-nxp.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/usb/host/ohci-nxp.c +4 -0
index 24d5a1dc5056..f79558ef0b45 100644
@@ -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;
 }
 
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 1 line · Ma Ke

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.

Quoted 20 lines

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.

Fixes 73108aa90cbf ("USB: ohci-nxp: Use isp1301 driver")
---
 drivers/usb/host/ohci-nxp.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/usb/host/ohci-nxp.c +0 -0
index 24d5a1dc5056..f79558ef0b45 100644

drivers/usb/host/ohci-nxp.c static int ohci_hcd_nxp_probe(struct platform_device *pdev) · line 226

Quoted 4 lines
drivers/usb/host/ohci-nxp.c +1 -0
@@ -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.

drivers/usb/host/ohci-nxp.c static void ohci_hcd_nxp_remove(struct platform_device *pdev) · line 239

Quoted 9 lines
drivers/usb/host/ohci-nxp.c +2 -0
+		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

Quoted 7 lines
drivers/usb/host/ohci-nxp.c +1 -0
+		put_device(&isp1301_i2c_client->dev);
 	isp1301_i2c_client = NULL;
 }
 
Signature · 1 line
2.17.1
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Ma Ke
Quoted 30 lines · Ma Ke

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.

Fixes 73108aa90cbf ("USB: ohci-nxp: Use isp1301 driver")
---
  drivers/usb/host/ohci-nxp.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/usb/host/ohci-nxp.c +2 -0
index 24d5a1dc5056..f79558ef0b45 100644
@@ -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;
  }

drivers/usb/host/ohci-nxp.c static void ohci_hcd_nxp_remove(struct platform_device *pdev) · line 243

Quoted 8 lines
drivers/usb/host/ohci-nxp.c +2 -0
@@ -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

Signature · 2 lines
Best wishes,
Vladimir