All of lore.kernel.org
 help / color / mirror / Atom feed
From: Felipe Balbi <balbi@kernel.org>
To: Xidong Wang <wangxidong_97@163.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Johan Hovold <johan@kernel.org>,
	Michal Nazarewicz <mina86@mina86.com>,
	Vincent Pelletier <plr.vincent@gmail.com>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [1/1] usb:gadget:function:fix memory leak
Date: Thu, 26 Jul 2018 14:08:09 +0300	[thread overview]
Message-ID: <87fu061ch2.fsf@linux.intel.com> (raw)

hi,

Xidong Wang <wangxidong_97@163.com> writes:
> In function f_audio_set_alt(), the memory allocated by
> usb_ep_alloc_request() is not released on the error path
> that req->buf, which holds the return value of kzalloc(),
> is NULL. This will result in a memory leak bug.
>
> Signed-off-by: Xidong Wang <wangxidong_97@163.com>
> ---
>  drivers/usb/gadget/function/f_uac1_legacy.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/gadget/function/f_uac1_legacy.c b/drivers/usb/gadget/function/f_uac1_legacy.c
> index 24c086b..2fcdade 100644
> --- a/drivers/usb/gadget/function/f_uac1_legacy.c
> +++ b/drivers/usb/gadget/function/f_uac1_legacy.c
> @@ -630,8 +630,11 @@ static int f_audio_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
>  							ERROR(cdev,
>  							"%s queue req: %d\n",
>  							out_ep->name, err);
> -					} else
> +					} else {
> +						usb_ep_free_request(
> +							out_ep, req);
>  						err = -ENOMEM;
> +					}

I feel like this hunk has been ping ponging between having
usb_ep_free_request() and not having it because completion callback will
call usb_ep_free_request() or something along those lines.

Can we get a final solution that solves all cases and doesn't introduce
other bugs?

WARNING: multiple messages have this Message-ID (diff)
From: Felipe Balbi <balbi@kernel.org>
To: Xidong Wang <wangxidong_97@163.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Johan Hovold <johan@kernel.org>,
	Michal Nazarewicz <mina86@mina86.com>,
	Vincent Pelletier <plr.vincent@gmail.com>
Cc: wangxidong_97@163.com, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/1] usb:gadget:function:fix memory leak
Date: Thu, 26 Jul 2018 14:08:09 +0300	[thread overview]
Message-ID: <87fu061ch2.fsf@linux.intel.com> (raw)
In-Reply-To: <1532344186-30505-1-git-send-email-wangxidong_97@163.com>

[-- Attachment #1: Type: text/plain, Size: 1320 bytes --]


hi,

Xidong Wang <wangxidong_97@163.com> writes:
> In function f_audio_set_alt(), the memory allocated by
> usb_ep_alloc_request() is not released on the error path
> that req->buf, which holds the return value of kzalloc(),
> is NULL. This will result in a memory leak bug.
>
> Signed-off-by: Xidong Wang <wangxidong_97@163.com>
> ---
>  drivers/usb/gadget/function/f_uac1_legacy.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/gadget/function/f_uac1_legacy.c b/drivers/usb/gadget/function/f_uac1_legacy.c
> index 24c086b..2fcdade 100644
> --- a/drivers/usb/gadget/function/f_uac1_legacy.c
> +++ b/drivers/usb/gadget/function/f_uac1_legacy.c
> @@ -630,8 +630,11 @@ static int f_audio_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
>  							ERROR(cdev,
>  							"%s queue req: %d\n",
>  							out_ep->name, err);
> -					} else
> +					} else {
> +						usb_ep_free_request(
> +							out_ep, req);
>  						err = -ENOMEM;
> +					}

I feel like this hunk has been ping ponging between having
usb_ep_free_request() and not having it because completion callback will
call usb_ep_free_request() or something along those lines.

Can we get a final solution that solves all cases and doesn't introduce
other bugs?

-- 
balbi

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

             reply	other threads:[~2018-07-26 11:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-26 11:08 Felipe Balbi [this message]
2018-07-26 11:08 ` [PATCH 1/1] usb:gadget:function:fix memory leak Felipe Balbi
  -- strict thread matches above, loose matches on Subject: below --
2018-07-23 11:09 [1/1] " Xidong Wang
2018-07-23 11:09 ` [PATCH 1/1] " Xidong Wang

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=87fu061ch2.fsf@linux.intel.com \
    --to=balbi@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=johan@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mina86@mina86.com \
    --cc=plr.vincent@gmail.com \
    --cc=wangxidong_97@163.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.