mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stephen Boyd <sboyd@kernel.org>
To: Ma Ke <make_ruc2021@163.com>, mchehab+huawei@kernel.org
Cc: linux-kernel@vger.kernel.org, Ma Ke <make_ruc2021@163.com>
Subject: Re: [PATCH] spmi: hisi-spmi-controller: fix potential memory leak in spmi_controller_probe()
Date: Mon, 23 Oct 2023 19:00:20 -0700	[thread overview]
Message-ID: <909e5d44d6cd79924d6e62d1b649646f.sboyd@kernel.org> (raw)
In-Reply-To: <20230922025216.3604978-1-make_ruc2021@163.com>

Quoting Ma Ke (2023-09-21 19:52:16)
> spmi_controller_alloc() allocates a memory space for ctrl. When some
> errors occur, ctrl should be handled by spmi_controller_put() and set
> spmi_controller->controller = NULL because spmi_controller->controller
> has a dangling pointer to the freed memory. When the failure happens,
> the function returns without calling spmi_controller_put() and setting
> spmi_controller->controller = NULL, which will lead to a memory leak.
> 
> When the failure happens, we can fix it by calling spmi_controller_put()
> and setting spmi_controller->controller = NULL in all of the places
> where we call spmi_controller_put().
> 
> Signed-off-by: Ma Ke <make_ruc2021@163.com>
> ---
>  drivers/spmi/hisi-spmi-controller.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/spmi/hisi-spmi-controller.c b/drivers/spmi/hisi-spmi-controller.c
> index 9cbd473487cb..5b3cfa7f5056 100644
> --- a/drivers/spmi/hisi-spmi-controller.c
> +++ b/drivers/spmi/hisi-spmi-controller.c
> @@ -321,6 +321,7 @@ static int spmi_controller_probe(struct platform_device *pdev)
>  
>  err_put_controller:
>         spmi_controller_put(ctrl);
> +       spmi_controller->controller = NULL;

The controller will most likely be freed after the put call one line
above so this will oops. No thanks.

      reply	other threads:[~2023-10-24  2:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-22  2:52 Ma Ke
2023-10-24  2:00 ` Stephen Boyd [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=909e5d44d6cd79924d6e62d1b649646f.sboyd@kernel.org \
    --to=sboyd@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=make_ruc2021@163.com \
    --cc=mchehab+huawei@kernel.org \
    /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

Powered by JetHome