public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH v2] USB: ohci-nxp: Fix error handling in ohci-hcd-nxp driver
@ 2025-11-17  1:34 Ma Ke
  2025-11-17  2:12 ` Alan Stern
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Ma Ke @ 2025-11-17  1:34 UTC (permalink / raw)
  To: stern, vz, piotr.wojtaszczyk, gregkh, arnd, stigge
  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.

Fix this by storing whether the client was obtained via device tree
and only releasing the reference in that case.

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>
---
Changes in v2:
- only released the device reference when the ISP1301 client was obtained through device tree, not in the non-DT case where the global variable is used;
- removed unnecessary NULL checks as suggested by reviewer.
---
 drivers/usb/host/ohci-nxp.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/usb/host/ohci-nxp.c b/drivers/usb/host/ohci-nxp.c
index 24d5a1dc5056..081b8c7f21a0 100644
--- a/drivers/usb/host/ohci-nxp.c
+++ b/drivers/usb/host/ohci-nxp.c
@@ -50,6 +50,7 @@ static const char hcd_name[] = "ohci-nxp";
 static struct hc_driver __read_mostly ohci_nxp_hc_driver;
 
 static struct i2c_client *isp1301_i2c_client;
+static bool isp1301_using_dt;
 
 static void isp1301_configure_lpc32xx(void)
 {
@@ -161,6 +162,7 @@ static int ohci_hcd_nxp_probe(struct platform_device *pdev)
 	} else {
 		isp1301_node = NULL;
 	}
+	isp1301_using_dt = (isp1301_node != NULL);
 
 	isp1301_i2c_client = isp1301_get_client(isp1301_node);
 	of_node_put(isp1301_node);
@@ -223,6 +225,8 @@ static int ohci_hcd_nxp_probe(struct platform_device *pdev)
 fail_resource:
 	usb_put_hcd(hcd);
 fail_disable:
+	if (isp1301_using_dt)
+		put_device(&isp1301_i2c_client->dev);
 	isp1301_i2c_client = NULL;
 	return ret;
 }
@@ -234,6 +238,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_using_dt)
+		put_device(&isp1301_i2c_client->dev);
 	isp1301_i2c_client = NULL;
 }
 
-- 
2.17.1



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

end of thread, other threads:[~2025-11-21 14:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-17  1:34 [PATCH v2] USB: ohci-nxp: Fix error handling in ohci-hcd-nxp driver Ma Ke
2025-11-17  2:12 ` Alan Stern
2025-11-17  8:53 ` Arnd Bergmann
2025-11-17 14:56   ` Alan Stern
2025-11-17 19:44     ` Vladimir Zapolskiy
2025-11-21 14:18 ` Greg KH

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