mirror of
https://kernel.googlesource.com/pub/scm/linux/kernel/git/stable/linux-stable.git
synced 2025-09-28 17:40:21 +10:00
bus: fsl-mc: Fix potential double device reference in fsl_mc_get_endpoint()
commitbddbe13d36
upstream. The fsl_mc_get_endpoint() function may call fsl_mc_device_lookup() twice, which would increment the device's reference count twice if both lookups find a device. This could lead to a reference count leak. Found by code review. Cc: stable@vger.kernel.org Fixes:1ac210d128
("bus: fsl-mc: add the fsl_mc_get_endpoint function") Signed-off-by: Ma Ke <make24@iscas.ac.cn> Tested-by: Ioana Ciornei <ioana.ciornei@nxp.com> Reviewed-by: Simon Horman <horms@kernel.org> Fixes:8567494ceb
("bus: fsl-mc: rescan devices if endpoint not found") Link: https://patch.msgid.link/20250717022309.3339976-1-make24@iscas.ac.cn Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
6e7836c836
commit
72584a9178
@ -942,6 +942,7 @@ struct fsl_mc_device *fsl_mc_get_endpoint(struct fsl_mc_device *mc_dev,
|
||||
struct fsl_mc_obj_desc endpoint_desc = {{ 0 }};
|
||||
struct dprc_endpoint endpoint1 = {{ 0 }};
|
||||
struct dprc_endpoint endpoint2 = {{ 0 }};
|
||||
struct fsl_mc_bus *mc_bus;
|
||||
int state, err;
|
||||
|
||||
mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent);
|
||||
@ -965,6 +966,8 @@ struct fsl_mc_device *fsl_mc_get_endpoint(struct fsl_mc_device *mc_dev,
|
||||
strcpy(endpoint_desc.type, endpoint2.type);
|
||||
endpoint_desc.id = endpoint2.id;
|
||||
endpoint = fsl_mc_device_lookup(&endpoint_desc, mc_bus_dev);
|
||||
if (endpoint)
|
||||
return endpoint;
|
||||
|
||||
/*
|
||||
* We know that the device has an endpoint because we verified by
|
||||
@ -972,17 +975,13 @@ struct fsl_mc_device *fsl_mc_get_endpoint(struct fsl_mc_device *mc_dev,
|
||||
* yet discovered by the fsl-mc bus, thus the lookup returned NULL.
|
||||
* Force a rescan of the devices in this container and retry the lookup.
|
||||
*/
|
||||
if (!endpoint) {
|
||||
struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_bus_dev);
|
||||
|
||||
if (mutex_trylock(&mc_bus->scan_mutex)) {
|
||||
err = dprc_scan_objects(mc_bus_dev, true);
|
||||
mutex_unlock(&mc_bus->scan_mutex);
|
||||
}
|
||||
|
||||
if (err < 0)
|
||||
return ERR_PTR(err);
|
||||
mc_bus = to_fsl_mc_bus(mc_bus_dev);
|
||||
if (mutex_trylock(&mc_bus->scan_mutex)) {
|
||||
err = dprc_scan_objects(mc_bus_dev, true);
|
||||
mutex_unlock(&mc_bus->scan_mutex);
|
||||
}
|
||||
if (err < 0)
|
||||
return ERR_PTR(err);
|
||||
|
||||
endpoint = fsl_mc_device_lookup(&endpoint_desc, mc_bus_dev);
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user