Skip to content

Commit 7d407ef

Browse files
hcodinagregkh
authored andcommitted
lib/vsprintf: Fix %pfwf when current node refcount == 0
commit 5c47251 upstream. A refcount issue can appeared in __fwnode_link_del() due to the pr_debug() call: WARNING: CPU: 0 PID: 901 at lib/refcount.c:25 refcount_warn_saturate+0xe5/0x110 Call Trace: <TASK> ... of_node_get+0x1e/0x30 of_fwnode_get+0x28/0x40 fwnode_full_name_string+0x34/0x90 fwnode_string+0xdb/0x140 ... vsnprintf+0x17b/0x630 ... __fwnode_link_del+0x25/0xa0 fwnode_links_purge+0x39/0xb0 of_node_release+0xd9/0x180 ... Indeed, an fwnode (of_node) is being destroyed and so, of_node_release() is called because the of_node refcount reached 0. From of_node_release() several function calls are done and lead to a pr_debug() calls with %pfwf to print the fwnode full name. The issue is not present if we change %pfwf to %pfwP. To print the full name, %pfwf iterates over the current node and its parents and obtain/drop a reference to all nodes involved. In order to allow to print the full name (%pfwf) of a node while it is being destroyed, do not obtain/drop a reference to this current node. Fixes: a92eb76 ("lib/vsprintf: Make use of fwnode API to obtain node names and separators") Cc: [email protected] Signed-off-by: Herve Codina <[email protected]> Reviewed-by: Sakari Ailus <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Signed-off-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 565fadc commit 7d407ef

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/vsprintf.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,15 +1984,20 @@ char *fwnode_full_name_string(struct fwnode_handle *fwnode, char *buf,
19841984

19851985
/* Loop starting from the root node to the current node. */
19861986
for (depth = fwnode_count_parents(fwnode); depth >= 0; depth--) {
1987-
struct fwnode_handle *__fwnode =
1988-
fwnode_get_nth_parent(fwnode, depth);
1987+
/*
1988+
* Only get a reference for other nodes (i.e. parent nodes).
1989+
* fwnode refcount may be 0 here.
1990+
*/
1991+
struct fwnode_handle *__fwnode = depth ?
1992+
fwnode_get_nth_parent(fwnode, depth) : fwnode;
19891993

19901994
buf = string(buf, end, fwnode_get_name_prefix(__fwnode),
19911995
default_str_spec);
19921996
buf = string(buf, end, fwnode_get_name(__fwnode),
19931997
default_str_spec);
19941998

1995-
fwnode_handle_put(__fwnode);
1999+
if (depth)
2000+
fwnode_handle_put(__fwnode);
19962001
}
19972002

19982003
return buf;

0 commit comments

Comments
 (0)