From: Greg KH <gregkh@linuxfoundation.org>
To: Yang Yingliang <yangyingliang@huawei.com>
Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
balbi@kernel.org
Subject: Re: [PATCH] usb: phy: isp1301: add release func to dev to avoid memory leak
Date: Mon, 18 Oct 2021 17:07:16 +0200 [thread overview]
Message-ID: <YW2NpDG6hGJk4UR9@kroah.com> (raw)
In-Reply-To: <20211015051624.1655193-1-yangyingliang@huawei.com>
On Fri, Oct 15, 2021 at 01:16:24PM +0800, Yang Yingliang wrote:
> After calling usb_add_phy_dev(), client->dev.type will be changed
> to 'usb_pyh_dev_type', the release() func is null, it cause the
> following WARNING:
>
> Device '1-001c' does not have a release() function, it is broken and must be fixed. See Documentation/core-api/kobject.rst.
> WARNING: CPU: 1 PID: 405 at device_release+0x1b7/0x240
> Call Trace:
> kobject_put+0x1e5/0x540
> device_unregister+0x35/0xc0
> i2c_unregister_device+0x114/0x1f0
>
> It cause 'client' leaked which is allocated in i2c_new_client_device():
>
> unreferenced object 0xffff88800670b000 (size 2048):
> comm "xrun", pid 429, jiffies 4294946742 (age 235.248s)
> hex dump (first 32 bytes):
> 00 00 1c 00 69 73 70 31 33 30 31 00 00 00 00 00 ....isp1301.....
> 00 00 00 00 00 00 00 00 c0 e4 17 c1 ff ff ff ff ................
> backtrace:
> [<00000000a4641100>] kmem_cache_alloc_trace+0x186/0x2b0
> [<00000000d9d933e7>] i2c_new_client_device+0x56/0xb40
> [<000000007255bed2>] new_device_store+0x1f4/0x410
>
> So add release func to dev to avoid this memory leak.
>
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Fixes: 790d3a5ab6e36 ("usb: phy: isp1301: give it a context structure")
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
> drivers/usb/phy/phy-isp1301.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/usb/phy/phy-isp1301.c b/drivers/usb/phy/phy-isp1301.c
> index ad3d57f1c273..04f005572484 100644
> --- a/drivers/usb/phy/phy-isp1301.c
> +++ b/drivers/usb/phy/phy-isp1301.c
> @@ -111,6 +111,7 @@ static int isp1301_probe(struct i2c_client *client,
> phy->init = isp1301_phy_init;
> phy->set_vbus = isp1301_phy_set_vbus;
> phy->type = USB_PHY_TYPE_USB2;
> + client->dev.release = client->dev.type->release;
messing with a release pointer is almost never a good idea, and a sign
that something is really wrong.
Why is the type not set properly here so as to get the correct release
callback when the device is created? Why do you have to manually change
this now after the fact?
thanks,
greg k-h
prev parent reply other threads:[~2021-10-18 15:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-15 5:16 Yang Yingliang
2021-10-18 15:07 ` Greg KH [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=YW2NpDG6hGJk4UR9@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=balbi@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--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
all inboxes | Powered by JetHome®