bus: fsl-mc: Fix two double free problems in fsl_mc_device_add()
Subsystems (2)
v2 cover bus: fsl-mc: Fix two double free problems in fsl_mc_device_add()
This patchset fixes two double free problems in fsl_mc_device_add(). One is reported by clang static checker, another is reported by Dan when reviewing the code.
ps: There is only patch 1 in v1 patch, patch 2 has no v1 version.
v1: https://lore.kernel.org/all/[email protected]/
Su Hui (2):
bus: fsl-mc: Fix the double free in fsl_mc_device_add()
bus: fsl-mc: using put_device() when add_device() failed in
fsl_mc_device_add()
drivers/bus/fsl-mc/fsl-mc-bus.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
Signature · 1 line
2.30.2
PATCH v2 1/2 bus: fsl-mc: Fix the double free in fsl_mc_device_add()
Clang static checker(scan-build) warning: drivers/bus/fsl-mc/fsl-mc-bus.c: line 909, column 2 Attempt to free released memory.
When 'obj_desc->type' == "dprc" and begin to free 'mc_bus' and 'mc_dev', there is a double free problem because of 'mc_dev = &mc_bus->mc_dev'. Add a judgment to fix this problem.
---
v2:
- using is_fsl_mc_bus_dprc().
https://lore.kernel.org/all/[email protected]/
drivers/bus/fsl-mc/fsl-mc-bus.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/bus/fsl-mc/fsl-mc-bus.c +4 -2
@@ -905,8 +905,10 @@ int fsl_mc_device_add(struct fsl_mc_obj_desc *obj_desc, error_cleanup_dev:kfree (mc_dev->regions); -kfree (mc_bus); -kfree (mc_dev); +if (is_fsl_mc_bus_dprc (mc_dev)) +kfree (mc_bus); +else +kfree (mc_dev);return error; }
Signature · 1 line
2.30.2
PATCH v2 2/2 bus: fsl-mc: using put_device() when add_device() failed in fsl_mc_device_add()
In reply to Su HuiWhen device_add(&mc_dev->dev) failed, calling put_device() to let 'mc_dev->dev.release' free the resource rather than goto label error_cleanup_dev. Otherwise, it can cause double free problem.
--- drivers/bus/fsl-mc/fsl-mc-bus.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/bus/fsl-mc/fsl-mc-bus.c +2 -1
@@ -895,7 +895,8 @@ int fsl_mc_device_add(struct fsl_mc_obj_desc *obj_desc,dev_err (parent_dev,"device_add() failed for device %s: %d\n" ,dev_name (&mc_dev->dev), error); - goto error_cleanup_dev; +put_device (&mc_dev->dev); +return error; }dev_dbg (parent_dev,"added %s\n" ,dev_name (&mc_dev->dev));
Signature · 1 line
2.30.2
Quoted 4 lines · Su Hui
This patchset fixes two double free problems in
fsl_mc_device_add(). One is reported by clang static checker, another is reported by Dan when reviewing the code.
Quoted 8 lines
ps: There is only patch 1 in v1 patch, patch 2 has no v1 version.
v1: https://lore.kernel.org/all/[email protected]/
Su Hui (2):
bus: fsl-mc: Fix the double free infsl_mc_device_add()
bus: fsl-mc: usingput_device()whenadd_device()failed infsl_mc_device_add()
Thanks!
regards,
dan carpenter