bus: fsl-mc: fix device reference leak in fsl_mc_device_lookup()
Subsystems (2)
PATCH 1/1 bus: fsl-mc: fix device reference leak in fsl_mc_device_lookup()
The device_find_child() function calls the get_device() and returns a device reference that must be properly released when no longer needed. The fsl_mc_device_lookup() directly returns without releasing the reference via put_device().
Add the missing put_device() call to prevent reference leaks.
--- drivers/bus/fsl-mc/dprc-driver.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/bus/fsl-mc/dprc-driver.c +7 -1
@@ -124,11 +124,17 @@ struct fsl_mc_device *fsl_mc_device_lookup(struct fsl_mc_obj_desc *obj_desc, struct fsl_mc_device *mc_bus_dev) {struct device *dev; +struct fsl_mc_device *mc_dev; dev =device_find_child (&mc_bus_dev->dev, obj_desc, __fsl_mc_device_match); +if (!dev) +return NULL ; + + mc_dev =to_fsl_mc_device (dev); +put_device (dev); -return dev ?to_fsl_mc_device (dev) :NULL ; +return mc_dev; }/**
Signature · 1 line
2.42.0.windows.2
Ioana Ciornei
maintainerQuoted 2 lines · Wentao Liang
The
device_find_child()function calls theget_device()and returns a device reference that must be properly released when no longer needed.
The release should be done when no longer needed, not even before returning the device to the caller.
Quoted 5 lines
The
fsl_mc_device_lookup()directly returns without releasing the reference viaput_device().Add the missing
put_device()call to prevent reference leaks.
No, the call to put_device should not be done from fsl_mc_device_lookup() but instead from its callers when indeed the device is no longer in use. For example, fsl_mc_obj_device_add() does call put_device().
Ioana