]> git.baikalelectronics.ru Git - kernel.git/commit
usb: typec: tcpci: fix of node refcount leak in tcpci_register_port()
authorYang Yingliang <yangyingliang@huawei.com>
Mon, 21 Nov 2022 06:24:16 +0000 (14:24 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 18 Jan 2023 10:41:22 +0000 (11:41 +0100)
commitf5393bde4f6ee3566c5f5c19d44b904b2a576b94
tree65626b2ddb104cc0f0f9ebbaefd82ef8bb42cce0
parent06ed45948c43668059f4bfc397243addce8c404f
usb: typec: tcpci: fix of node refcount leak in tcpci_register_port()

[ Upstream commit 9bc82c6d1c83c937c00c3f7737e3728328c4ef42 ]

I got the following report while doing device(mt6370-tcpc) load
test with CONFIG_OF_UNITTEST and CONFIG_OF_DYNAMIC enabled:

  OF: ERROR: memory leak, expected refcount 1 instead of 2,
  of_node_get()/of_node_put() unbalanced - destroy cset entry:
  attach overlay node /i2c/pmic@34/tcpc/connector

The 'fwnode' set in tcpci_parse_config() which is called
in tcpci_register_port(), its node refcount is increased
in device_get_named_child_node(). It needs be put while
exiting, so call fwnode_handle_put() in the error path of
tcpci_register_port() and in tcpci_unregister_port() to
avoid leak.

Fixes: f2f44ae069ce ("usb: typec: add fwnode to tcpc")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20221121062416.1026192-1-yangyingliang@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/usb/typec/tcpm/tcpci.c