usb: roles: fix of node refcount leak in usb_role_switch_is_parent()
authorYang Yingliang <yangyingliang@huawei.com>
Tue, 22 Nov 2022 11:12:26 +0000 (19:12 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 31 Dec 2022 12:14:30 +0000 (13:14 +0100)
commita41c2bba7f2853d9ede8b74f2d9a080db1e8e1ed
tree84b4210b7d3e91967d571376e432e70623c97e79
parent18b9202188a4e59923834c60b5c82ea1da7d1811
usb: roles: fix of node refcount leak in usb_role_switch_is_parent()

[ Upstream commit 1ab30c610630da5391a373cddb8a065bf4c4bc01 ]

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

The 'parent' returned by fwnode_get_parent() with refcount incremented.
it needs be put after using.

Fixes: 6fadd72943b8 ("usb: roles: get usb-role-switch from parent")
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Link: https://lore.kernel.org/r/20221122111226.251588-1-yangyingliang@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/usb/roles/class.c