usb: phy: isp1301: fix non-OF device reference imbalance

commit b4b64fda4d upstream.

A recent change fixing a device reference leak in a UDC driver
introduced a potential use-after-free in the non-OF case as the
isp1301_get_client() helper only increases the reference count for the
returned I2C device in the OF case.

Increment the reference count also for non-OF so that the caller can
decrement it unconditionally.

Note that this is inherently racy just as using the returned I2C device
is since nothing is preventing the PHY driver from being unbound while
in use.

Fixes: c84117912b ("USB: lpc32xx_udc: Fix error handling in probe")
Cc: stable@vger.kernel.org
Cc: Ma Ke <make24@iscas.ac.cn>
Signed-off-by: Johan Hovold <johan@kernel.org>
Reviewed-by: Vladimir Zapolskiy <vz@mleia.com>
Link: https://patch.msgid.link/20251218153519.19453-3-johan@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Johan Hovold
2026-01-02 12:57:13 +01:00
committed by Greg Kroah-Hartman
parent 2e7c47e2eb
commit 7501ecfe3e
+6 -1
View File
@@ -149,7 +149,12 @@ struct i2c_client *isp1301_get_client(struct device_node *node)
return client;
/* non-DT: only one ISP1301 chip supported */
return isp1301_i2c_client;
if (isp1301_i2c_client) {
get_device(&isp1301_i2c_client->dev);
return isp1301_i2c_client;
}
return NULL;
}
EXPORT_SYMBOL_GPL(isp1301_get_client);