Skip to contentSkip to conversation

Removed unnecessary initialization of "ret"

PATCH In review MottiKumar Babu 3 participants 3 messages Oct 27, 2024 – Oct 28, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Removed unnecessary initialization of "ret"

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)

---
 kernel/trace/fgraph.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/fgraph.c +1 -1
index 69e226a48daa..b13ab2ad0e88 100644
@@ -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);
Signature · 1 line
2.43.0
#1 lore raw
Quoted 9 lines · MottiKumar Babu

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.

Quoted 10 lines
---
  kernel/trace/fgraph.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/fgraph.c +0 -0
index 69e226a48daa..b13ab2ad0e88 100644

kernel/trace/fgraph.c int register_ftrace_graph(struct fgraph_ops *gops) · line 1255

Quoted 8 lines
kernel/trace/fgraph.c +1 -1
@@ -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

maintainer
#2 lore raw
Quoted 12 lines · On Sun, 27 Oct 2024 21:24:55 -0600 Shuah Khan <[email protected]> wrote:
Quoted 12 lines
kernel/trace/fgraph.c +1 -1
index 69e226a48daa..b13ab2ad0e88 100644
@@ -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;
 
Quoted 5 lines

kernel/trace/fgraph.c int register_ftrace_graph(struct fgraph_ops *gops) · line 1255

Quoted 1 line
kernel/trace/fgraph.c +0 -0
  	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