All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Yeqi Fu <fufuyqqqqqq@gmail.com>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	lyz_cs@pku.edu.cn, Yeqi Fu <fuyq@stu.pku.edu.cn>
Subject: Re: [PATCH 2/2] usb: typec: fix memory leak
Date: Tue, 8 Mar 2022 08:09:07 +0100	[thread overview]
Message-ID: <YicBE18zTVVNLhsn@kroah.com> (raw)
In-Reply-To: <20220308065617.90401-1-fufuyqqqqqq@gmail.com>

On Mon, Mar 07, 2022 at 10:56:17PM -0800, Yeqi Fu wrote:
> From: Yeqi Fu <fuyq@stu.pku.edu.cn>
> 
> Resource release is needed on the error handling branch
> to prevent memory leak. Fix this by adding kfree to the
> error handling branch.
> 
> Signed-off-by: Yeqi Fu <fuyq@stu.pku.edu.cn>
> ---
>  drivers/usb/typec/class.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index ee0e520707dd..e210109c696d 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -2099,6 +2099,7 @@ struct typec_port *typec_register_port(struct device *parent,
>  	port->cap = kmemdup(cap, sizeof(*cap), GFP_KERNEL);
>  	if (!port->cap) {
>  		put_device(&port->dev);
> +		kfree(port);
>  		return ERR_PTR(-ENOMEM);
>  	}
>  
> @@ -2106,6 +2107,7 @@ struct typec_port *typec_register_port(struct device *parent,
>  	if (IS_ERR(port->sw)) {
>  		ret = PTR_ERR(port->sw);
>  		put_device(&port->dev);
> +		kfree(port);
>  		return ERR_PTR(ret);
>  	}
>  
> @@ -2113,6 +2115,7 @@ struct typec_port *typec_register_port(struct device *parent,
>  	if (IS_ERR(port->mux)) {
>  		ret = PTR_ERR(port->mux);
>  		put_device(&port->dev);
> +		kfree(port);
>  		return ERR_PTR(ret);
>  	}
>  
> @@ -2120,6 +2123,7 @@ struct typec_port *typec_register_port(struct device *parent,
>  	if (ret) {
>  		dev_err(parent, "failed to register port (%d)\n", ret);
>  		put_device(&port->dev);
> +		kfree(port);
>  		return ERR_PTR(ret);
>  	}

How was this tested?

  reply	other threads:[~2022-03-08  7:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-08  6:56 [PATCH 2/2] usb: typec: fix memory leak Yeqi Fu
2022-03-08  7:09 ` Greg Kroah-Hartman [this message]
2022-03-08  7:28 ` Heikki Krogerus

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=YicBE18zTVVNLhsn@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=fufuyqqqqqq@gmail.com \
    --cc=fuyq@stu.pku.edu.cn \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=lyz_cs@pku.edu.cn \
    /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.