mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Li Huafei <lihuafei1@huawei.com>
Cc: <rostedt@goodmis.org>, <dan.carpenter@linaro.org>,
	<mhiramat@kernel.org>, <linux-kernel@vger.kernel.org>,
	<linux-trace-kernel@vger.kernel.org>, <oe-kbuild@lists.linux.dev>,
	<lkp@intel.com>
Subject: Re: [PATCH v2] fgraph: Fix missing unlock in register_ftrace_graph()
Date: Thu, 24 Oct 2024 23:28:02 +0900	[thread overview]
Message-ID: <20241024232802.57bb710cc1fee46608c4aed4@kernel.org> (raw)
In-Reply-To: <20241024155917.1019580-1-lihuafei1@huawei.com>

On Thu, 24 Oct 2024 23:59:17 +0800
Li Huafei <lihuafei1@huawei.com> wrote:

> Use guard(mutex)() to acquire and automatically release ftrace_lock,
> fixing the issue of not unlocking when calling cpuhp_setup_state()
> fails.
> 
> Fixes smatch warning:
> 
> kernel/trace/fgraph.c:1317 register_ftrace_graph() warn: inconsistent returns '&ftrace_lock'.
> 

Looks good to me.

Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Thank you,

> Fixes: 2c02f7375e65 ("fgraph: Use CPU hotplug mechanism to initialize idle shadow stacks")
> Reported-by: kernel test robot <lkp@intel.com>
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Closes: https://lore.kernel.org/r/202410220121.wxg0olfd-lkp@intel.com/
> Suggested-by: Steven Rostedt <rostedt@goodmis.org>
> Signed-off-by: Li Huafei <lihuafei1@huawei.com>
> ---
> Changes in v2:
>  - Use guard() to acquire and automatically release ftrace_lock.
> ---
>  kernel/trace/fgraph.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c
> index 41e7a15dcb50..cd1c2946018c 100644
> --- a/kernel/trace/fgraph.c
> +++ b/kernel/trace/fgraph.c
> @@ -1252,7 +1252,7 @@ int register_ftrace_graph(struct fgraph_ops *gops)
>  	int ret = 0;
>  	int i = -1;
>  
> -	mutex_lock(&ftrace_lock);
> +	guard(mutex)(&ftrace_lock);
>  
>  	if (!fgraph_initialized) {
>  		ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "fgraph_idle_init",
> @@ -1273,10 +1273,8 @@ int register_ftrace_graph(struct fgraph_ops *gops)
>  	}
>  
>  	i = fgraph_lru_alloc_index();
> -	if (i < 0 || WARN_ON_ONCE(fgraph_array[i] != &fgraph_stub)) {
> -		ret = -ENOSPC;
> -		goto out;
> -	}
> +	if (i < 0 || WARN_ON_ONCE(fgraph_array[i] != &fgraph_stub))
> +		return -ENOSPC;
>  	gops->idx = i;
>  
>  	ftrace_graph_active++;
> @@ -1313,8 +1311,6 @@ int register_ftrace_graph(struct fgraph_ops *gops)
>  		gops->saved_func = NULL;
>  		fgraph_lru_release_index(i);
>  	}
> -out:
> -	mutex_unlock(&ftrace_lock);
>  	return ret;
>  }
>  
> -- 
> 2.25.1
> 
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

      reply	other threads:[~2024-10-24 14:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-24 15:59 Li Huafei
2024-10-24 14:28 ` Masami Hiramatsu [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=20241024232802.57bb710cc1fee46608c4aed4@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=dan.carpenter@linaro.org \
    --cc=lihuafei1@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=oe-kbuild@lists.linux.dev \
    --cc=rostedt@goodmis.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

all inboxes | Powered by JetHome®