• Herve Codina's avatar
    lib/vsprintf: Fix %pfwf when current node refcount == 0 · 5c47251e
    Herve Codina authored
    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: a92eb762 ("lib/vsprintf: Make use of fwnode API to obtain node names and separators")
    Cc: stable@vger.kernel.org
    Signed-off-by: default avatarHerve Codina <herve.codina@bootlin.com>
    Reviewed-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
    Reviewed-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
    Signed-off-by: default avatarPetr Mladek <pmladek@suse.com>
    Link: https://lore.kernel.org/r/20231114152655.409331-1-herve.codina@bootlin.com
    5c47251e
vsprintf.c 87.8 KB