of: property: decrement node refcount in of_fwnode_get_reference_args()
PATCH v2 1/1 of: property: decrement node refcount in of_fwnode_get_reference_args()
I got the the following report:
OF: ERROR: memory leak, expected refcount 1 instead of 4, of_node_get()/of_node_put() unbalanced - destroy cset entry:
attach overlay node /i2c/pmic@34/adc
In of_fwnode_get_reference_args(), the refcount of of_args.np has been incremented in the case of successful return from of_parse_phandle_with_args() or of_parse_phandle_with_fixed_args().
Decrement the refcount if of_args is not returned to the caller of of_fwnode_get_reference_args().
---
v1 -> v2:
Update title and commit message that suggested by Frank.
--- drivers/of/property.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/of/property.c +3 -1
@@ -993,8 +993,10 @@ of_fwnode_get_reference_args(const struct fwnode_handle *fwnode, nargs, index, &of_args);if (ret <0 )return ret; -if (!args) +if (!args) { +of_node_put (of_args.np);return 0 ; + } args->nargs = of_args.args_count; args->fwnode =of_fwnode_handle (of_args.np);
Signature · 1 line
2.25.1
On 11/20/22 19:42, Yang Yingliang wrote:
Thanks for the quick update to v2.
This part of the patch comment should also be removed, because (if I understand correctly) it does not occur in the existing tree, only if a proposed patch is applied:
Quoted 5 lines
I got the the following report:
OF: ERROR: memory leak, expected refcount 1 instead of 4, of_node_get()/of_node_put() unbalanced - destroy cset entry:
attach overlay node /i2c/pmic@34/adc
Am I correct? In any case I appreciate the error report which provides useful context for the underlying problem.
-Frank
Quoted 35 lines
In
of_fwnode_get_reference_args(), the refcount of of_args.np has been incremented in the case of successful return fromof_parse_phandle_with_args()orof_parse_phandle_with_fixed_args().Decrement the refcount if
of_argsis not returned to the caller ofof_fwnode_get_reference_args().Fixes 3e3119d3088f ("device property: Introduce fwnode_property_get_reference_args")Signed-off-by Yang Yingliang <[email protected]>Reviewed-by Sakari Ailus <[email protected]>Reviewed-by Frank Rowand <[email protected]>---
v1 -> v2:
Update title and commit message that suggested by Frank.--- drivers/of/property.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/of/property.c +3
-1@@ -993,8 +993,10 @@ of_fwnode_get_reference_args(const struct fwnode_handle *fwnode, nargs, index, &of_args);if (ret <0 )return ret; -if (!args) +if (!args) { +of_node_put (of_args.np);return 0 ; + } args->nargs = of_args.args_count; args->fwnode =of_fwnode_handle (of_args.np);