From: Peter Chen <peter.chen@nxp.com>
To: Zhang Qilong <zhangqilong3@huawei.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: Re: [PATCH 1/2] usb: gadget: f_midi: Fix memleak in f_midi_alloc
Date: Mon, 16 Nov 2020 12:59:57 +0000 [thread overview]
Message-ID: <20201116125928.GB28313@b29397-desktop> (raw)
In-Reply-To: <20201116121710.1546690-2-zhangqilong3@huawei.com>
On 20-11-16 20:17:09, Zhang Qilong wrote:
> In the error path, if midi is not null, we should to
> free the midi->id if necessary to prevent memleak.
>
> Fixes: b85e9de9e818d ("usb: gadget: f_midi: convert to new function interface with backward compatibility")
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
> ---
> drivers/usb/gadget/function/f_midi.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c
> index 85cb15734aa8..596fd7ce56fb 100644
> --- a/drivers/usb/gadget/function/f_midi.c
> +++ b/drivers/usb/gadget/function/f_midi.c
> @@ -1345,7 +1345,10 @@ static struct usb_function *f_midi_alloc(struct usb_function_instance *fi)
>
> setup_fail:
> mutex_unlock(&opts->lock);
> + if (midi)
> + kfree(midi->id);
> kfree(midi);
> +
> return ERR_PTR(status);
> }
>
It is better to add another goto label for this memory free.
--
Thanks,
Peter Chen
next prev parent reply other threads:[~2020-11-16 13:00 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 [this message]
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
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=20201116125928.GB28313@b29397-desktop \
--to=peter.chen@nxp.com \
--cc=balbi@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-usb@vger.kernel.org \
--cc=zhangqilong3@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;
as well as URLs for NNTP newsgroup(s).