From: Guenter Roeck <linux@roeck-us.net>
To: Yang Yingliang <yangyingliang@huawei.com>
Cc: linux-usb@vger.kernel.org, heikki.krogerus@linux.intel.com,
jun.li@nxp.com, gregkh@linuxfoundation.org
Subject: Re: [PATCH v3] usb: typec: tcpci: fix of node refcount leak in tcpci_register_port()
Date: Wed, 23 Nov 2022 08:18:36 -0800 [thread overview]
Message-ID: <20221123161836.GA2374110@roeck-us.net> (raw)
In-Reply-To: <20221121062416.1026192-1-yangyingliang@huawei.com>
On Mon, Nov 21, 2022 at 02:24:16PM +0800, Yang Yingliang wrote:
> 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: 5e85a04c8c0d ("usb: typec: add fwnode to tcpc")
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
> ---
> v2 -> v3:
> Move fwnode_handle_put() into tcpci_unregister_port().
>
> v1 -> v2:
> Add description to how is the report generated and
> the review tag from Guenter.
> ---
> drivers/usb/typec/tcpm/tcpci.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c
> index b2bfcebe218f..72f8d1e87600 100644
> --- a/drivers/usb/typec/tcpm/tcpci.c
> +++ b/drivers/usb/typec/tcpm/tcpci.c
> @@ -794,8 +794,10 @@ struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data)
> return ERR_PTR(err);
>
> tcpci->port = tcpm_register_port(tcpci->dev, &tcpci->tcpc);
> - if (IS_ERR(tcpci->port))
> + if (IS_ERR(tcpci->port)) {
> + fwnode_handle_put(tcpci->tcpc.fwnode);
> return ERR_CAST(tcpci->port);
> + }
>
> return tcpci;
> }
> @@ -804,6 +806,7 @@ EXPORT_SYMBOL_GPL(tcpci_register_port);
> void tcpci_unregister_port(struct tcpci *tcpci)
> {
> tcpm_unregister_port(tcpci->port);
> + fwnode_handle_put(tcpci->tcpc.fwnode);
> }
> EXPORT_SYMBOL_GPL(tcpci_unregister_port);
>
> --
> 2.25.1
>
prev parent reply other threads:[~2022-11-23 16:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-21 6:24 [PATCH v3] usb: typec: tcpci: fix of node refcount leak in tcpci_register_port() Yang Yingliang
2022-11-21 8:59 ` Heikki Krogerus
2022-11-23 16:18 ` Guenter Roeck [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221123161836.GA2374110@roeck-us.net \
--to=linux@roeck-us.net \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=jun.li@nxp.com \
--cc=linux-usb@vger.kernel.org \
--cc=yangyingliang@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox