* [PATCH] Removed unnecessary initialization of "ret"
@ 2024-10-27 21:18 MottiKumar Babu
2024-10-28 3:24 ` Shuah Khan
0 siblings, 1 reply; 3+ messages in thread
From: MottiKumar Babu @ 2024-10-27 21:18 UTC (permalink / raw)
Cc: rostedt, mhiramat, mark.rutland, mathieu.desnoyers, linux-kernel,
linux-trace-kernel, linux-kernel-mentees, anupnewsmail, skhan
The initialization of ret to 0 was redundant since ret is set to meaningful values later in the function. This change simplifies the code and avoids confusion about its initial state.
The issue was reported by Coverity Scan.
Report:
CID 1633338 Unused value - An assigned value that is never used may represent unnecessary computation, an incorrect algorithm, or possibly the need for cleanup or refactoring.
In register_ftrace_graph: A value assigned to a variable is never used. (CWE-563)
Signed-off-by: MottiKumar Babu <mottikumarbabu@gmail.com>
---
kernel/trace/fgraph.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c
index 69e226a48daa..b13ab2ad0e88 100644
--- a/kernel/trace/fgraph.c
+++ b/kernel/trace/fgraph.c
@@ -1249,7 +1249,7 @@ int register_ftrace_graph(struct fgraph_ops *gops)
{
static bool fgraph_initialized;
int command = 0;
- int ret = 0;
+ int ret;
int i = -1;
guard(mutex)(&ftrace_lock);
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Removed unnecessary initialization of "ret"
2024-10-27 21:18 [PATCH] Removed unnecessary initialization of "ret" MottiKumar Babu
@ 2024-10-28 3:24 ` Shuah Khan
2024-10-28 5:14 ` Steven Rostedt
0 siblings, 1 reply; 3+ messages in thread
From: Shuah Khan @ 2024-10-28 3:24 UTC (permalink / raw)
To: MottiKumar Babu
Cc: rostedt, mhiramat, mark.rutland, mathieu.desnoyers, linux-kernel,
linux-trace-kernel, linux-kernel-mentees, anupnewsmail,
Shuah Khan
On 10/27/24 15:18, MottiKumar Babu wrote:
> The initialization of ret to 0 was redundant since ret is set to meaningful values later in the function. This change simplifies the code and avoids confusion about its initial state.
>
> The issue was reported by Coverity Scan.
>
> Report:
> CID 1633338 Unused value - An assigned value that is never used may represent unnecessary computation, an incorrect algorithm, or possibly the need for cleanup or refactoring.
> In register_ftrace_graph: A value assigned to a variable is never used. (CWE-563)
>
>
Check submitting patches document for how to write short log and change logs.
> Signed-off-by: MottiKumar Babu <mottikumarbabu@gmail.com>
> ---
> kernel/trace/fgraph.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c
> index 69e226a48daa..b13ab2ad0e88 100644
> --- a/kernel/trace/fgraph.c
> +++ b/kernel/trace/fgraph.c
> @@ -1249,7 +1249,7 @@ int register_ftrace_graph(struct fgraph_ops *gops)
> {
> static bool fgraph_initialized;
> int command = 0;
> - int ret = 0;
> + int ret;
> int i = -1;
>
> guard(mutex)(&ftrace_lock);
It makes sense to initialize ret - i think you might see a warning about
ret being not initialized before use. I don't see much value in saving
unnecessary computation.
thanks,
-- Shuah
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Removed unnecessary initialization of "ret"
2024-10-28 3:24 ` Shuah Khan
@ 2024-10-28 5:14 ` Steven Rostedt
0 siblings, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2024-10-28 5:14 UTC (permalink / raw)
To: Shuah Khan
Cc: MottiKumar Babu, mhiramat, mark.rutland, mathieu.desnoyers,
linux-kernel, linux-trace-kernel, linux-kernel-mentees,
anupnewsmail
On Sun, 27 Oct 2024 21:24:55 -0600
Shuah Khan <skhan@linuxfoundation.org> wrote:
> > diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c
> > index 69e226a48daa..b13ab2ad0e88 100644
> > --- a/kernel/trace/fgraph.c
> > +++ b/kernel/trace/fgraph.c
> > @@ -1249,7 +1249,7 @@ int register_ftrace_graph(struct fgraph_ops *gops)
> > {
> > static bool fgraph_initialized;
> > int command = 0;
> > - int ret = 0;
> > + int ret;
> > int i = -1;
> >
> > guard(mutex)(&ftrace_lock);
>
> It makes sense to initialize ret - i think you might see a warning about
> ret being not initialized before use. I don't see much value in saving
> unnecessary computation.
FYI, I'm rewriting this code for the next merge window, so this patch
doesn't need to be applied (as it's not something Linus would take in
an -rc release cycle).
-- Steve
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-10-28 5:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-27 21:18 [PATCH] Removed unnecessary initialization of "ret" MottiKumar Babu
2024-10-28 3:24 ` Shuah Khan
2024-10-28 5:14 ` Steven Rostedt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox