From: zhangqilong <zhangqilong3@huawei.com>
To: Peter Chen <peter.chen@nxp.com>
Cc: "balbi@kernel.org" <balbi@kernel.org>,
"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>
Subject: 答复: [PATCH 2/2] usb: gadget: Fix memleak in gadgetfs_fill_super
Date: Tue, 17 Nov 2020 01:44:54 +0000 [thread overview]
Message-ID: <21e2ad201ff54e7798c443fa66a5f39c@huawei.com> (raw)
In-Reply-To: <20201116130349.GC28313@b29397-desktop>
>
> On 20-11-16 20:17:10, Zhang Qilong wrote:
> > usb_get_gadget_udc_name will alloc memory for CHIP in "Enomem" branch.
> > we should free it before error returns to prevent memleak.
> >
> > Fixes: 175f712119c57 ("usb: gadget: provide interface for legacy
> > gadgets to get UDC name")
> > Reported-by: Hulk Robot <hulkci@huawei.com>
> > Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
> > ---
> > drivers/usb/gadget/legacy/inode.c | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/drivers/usb/gadget/legacy/inode.c
> > b/drivers/usb/gadget/legacy/inode.c
> > index 1b430b36d0a6..3cefc27be098 100644
> > --- a/drivers/usb/gadget/legacy/inode.c
> > +++ b/drivers/usb/gadget/legacy/inode.c
> > @@ -2039,6 +2039,9 @@ gadgetfs_fill_super (struct super_block *sb, struct
> fs_context *fc)
> > return 0;
> >
> > Enomem:
> > + free(CHIP);
> > + CHIP = NULL;
> > +
> > return -ENOMEM;
> > }
>
> It seems the dev_new also allocate the memory, would you please change it
> too, also, create a new goto entry for it.
If gadgetfs_create_file fails, the dev_new will be freed in put_dev.
Thanks,
Zhang
> --
>
> Thanks,
> Peter Chen
next prev parent reply other threads:[~2020-11-17 1:45 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-16 12:17 [PATCH 0/2] usb: gadget: Fix two memleaks in error handling Zhang Qilong
2020-11-16 12:17 ` [PATCH 1/2] usb: gadget: f_midi: Fix memleak in f_midi_alloc Zhang Qilong
2020-11-16 12:59 ` Peter Chen
2020-11-16 16:12 ` Sergei Shtylyov
2020-11-16 12:17 ` [PATCH 2/2] usb: gadget: Fix memleak in gadgetfs_fill_super Zhang Qilong
2020-11-16 13:04 ` Peter Chen
2020-11-17 1:44 ` zhangqilong [this message]
2020-11-16 15:06 ` kernel test robot
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=21e2ad201ff54e7798c443fa66a5f39c@huawei.com \
--to=zhangqilong3@huawei.com \
--cc=balbi@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-usb@vger.kernel.org \
--cc=peter.chen@nxp.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;
as well as URLs for NNTP newsgroup(s).