Linux USB
 help / color / mirror / Atom feed
From: "Chunfeng Yun (云春峰)" <Chunfeng.Yun@mediatek.com>
To: "yangyingliang@huawei.com" <yangyingliang@huawei.com>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"heikki.krogerus@linux.intel.com"
	<heikki.krogerus@linux.intel.com>
Cc: "linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>
Subject: Re: [PATCH v2] usb: roles: fix of node refcount leak in usb_role_switch_is_parent()
Date: Mon, 21 Nov 2022 07:49:31 +0000	[thread overview]
Message-ID: <097dc06a02377bf67e4d67a016060dbcd06f4798.camel@mediatek.com> (raw)
In-Reply-To: <20221119091541.1755640-1-yangyingliang@huawei.com>

On Sat, 2022-11-19 at 17:15 +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
> 
> 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")
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
> v1 -> v2:
>   Add description to how is the report generated.
> ---
>  drivers/usb/roles/class.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
> index dfaed7eee94f..289950e5fcfb 100644
> --- a/drivers/usb/roles/class.c
> +++ b/drivers/usb/roles/class.c
> @@ -106,10 +106,14 @@ usb_role_switch_is_parent(struct fwnode_handle
> *fwnode)
>  	struct fwnode_handle *parent = fwnode_get_parent(fwnode);
>  	struct device *dev;
>  
> -	if (!parent || !fwnode_property_present(parent, "usb-role-
> switch"))
> +	if (!parent || !fwnode_property_present(parent, "usb-role-
> switch")) {
> +		if (parent)
> +			fwnode_handle_put(parent);
>  		return NULL;
> +	}
>  
>  	dev = class_find_device_by_fwnode(role_class, parent);
> +	fwnode_handle_put(parent);
>  	return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER);
>  }
>  
+ Heikki



  reply	other threads:[~2022-11-21  7:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-19  9:15 [PATCH v2] usb: roles: fix of node refcount leak in usb_role_switch_is_parent() Yang Yingliang
2022-11-21  7:49 ` Chunfeng Yun (云春峰) [this message]
2022-11-21  8:55   ` Heikki Krogerus
2022-11-21  9:01     ` Yang Yingliang
2022-11-21  7:55 ` Chunfeng Yun (云春峰)
2022-11-21  8:28   ` Yang Yingliang

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=097dc06a02377bf67e4d67a016060dbcd06f4798.camel@mediatek.com \
    --to=chunfeng.yun@mediatek.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.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