[PATCH linux-next] tools: fix warning comparing pointer to 0

Subsystems: bpf [general] (safe dynamic programs and tools), bpf [selftests] (test runners & infrastructure), kernel selftest framework, the rest

STALE1807d

2 messages, 2 authors, 2021-08-23 · open the first message on its own page

[PATCH linux-next] tools: fix warning comparing pointer to 0

From: CGEL <hidden>
Date: 2021-08-20 03:31:23

From: jing yangyang <redacted>

Fix the following coccicheck warning:
./tools/testing/selftests/bpf/progs/profiler.inc.h:364:18-22:WARNING
comparing pointer to 0
./tools/testing/selftests/bpf/progs/profiler.inc.h:537:23-27:WARNING
comparing pointer to 0
./tools/testing/selftests/bpf/progs/profiler.inc.h:544:21-25:WARNING
comparing pointer to 0
./tools/testing/selftests/bpf/progs/profiler.inc.h:770:13-17:WARNING
comparing pointer to 0

Reported-by: Zeal Robot <redacted>
Signed-off-by: jing yangyang <redacted>
---
 tools/testing/selftests/bpf/progs/profiler.inc.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/bpf/progs/profiler.inc.h b/tools/testing/selftests/bpf/progs/profiler.inc.h
index 4896fdf..5c0bdab 100644
--- a/tools/testing/selftests/bpf/progs/profiler.inc.h
+++ b/tools/testing/selftests/bpf/progs/profiler.inc.h
@@ -361,7 +361,7 @@ static INLINE void* populate_var_metadata(struct var_metadata_t* metadata,
 	int zero = 0;
 	struct var_kill_data_t* kill_data = bpf_map_lookup_elem(&data_heap, &zero);
 
-	if (kill_data == NULL)
+	if (!kill_dat)
 		return NULL;
 	struct task_struct* task = (struct task_struct*)bpf_get_current_task();
 
@@ -534,14 +534,14 @@ static INLINE bool is_dentry_allowed_for_filemod(struct dentry* file_dentry,
 	*device_id = dev_id;
 	bool* allowed_device = bpf_map_lookup_elem(&allowed_devices, &dev_id);
 
-	if (allowed_device == NULL)
+	if (!allowed_device)
 		return false;
 
 	u64 ino = BPF_CORE_READ(file_dentry, d_inode, i_ino);
 	*file_ino = ino;
 	bool* allowed_file = bpf_map_lookup_elem(&allowed_file_inodes, &ino);
 
-	if (allowed_file == NULL)
+	if (!allowed_fil)
 		if (!is_ancestor_in_allowed_inodes(BPF_CORE_READ(file_dentry, d_parent)))
 			return false;
 	return true;
@@ -689,7 +689,7 @@ int raw_tracepoint__sched_process_exec(struct bpf_raw_tracepoint_args* ctx)
 	u64 inode = BPF_CORE_READ(bprm, file, f_inode, i_ino);
 
 	bool* should_filter_binprm = bpf_map_lookup_elem(&disallowed_exec_inodes, &inode);
-	if (should_filter_binprm != NULL)
+	if (should_filter_binprm)
 		goto out;
 
 	int zero = 0;
-- 
1.8.3.1

Re: [PATCH linux-next] tools: fix warning comparing pointer to 0

From: Daniel Borkmann <daniel@iogearbox.net>
Date: 2021-08-23 15:54:27

On 8/20/21 5:30 AM, CGEL wrote:
From: jing yangyang <redacted>

Fix the following coccicheck warning:
./tools/testing/selftests/bpf/progs/profiler.inc.h:364:18-22:WARNING
comparing pointer to 0
./tools/testing/selftests/bpf/progs/profiler.inc.h:537:23-27:WARNING
comparing pointer to 0
./tools/testing/selftests/bpf/progs/profiler.inc.h:544:21-25:WARNING
comparing pointer to 0
./tools/testing/selftests/bpf/progs/profiler.inc.h:770:13-17:WARNING
comparing pointer to 0

Reported-by: Zeal Robot <redacted>
Signed-off-by: jing yangyang <redacted>
Please properly explain in the commit message what this 'fixes' exactly and
why it is needed.
quoted hunk
---
  tools/testing/selftests/bpf/progs/profiler.inc.h | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/bpf/progs/profiler.inc.h b/tools/testing/selftests/bpf/progs/profiler.inc.h
index 4896fdf..5c0bdab 100644
--- a/tools/testing/selftests/bpf/progs/profiler.inc.h
+++ b/tools/testing/selftests/bpf/progs/profiler.inc.h
@@ -361,7 +361,7 @@ static INLINE void* populate_var_metadata(struct var_metadata_t* metadata,
  	int zero = 0;
  	struct var_kill_data_t* kill_data = bpf_map_lookup_elem(&data_heap, &zero);
  
-	if (kill_data == NULL)
+	if (!kill_dat)
And please don't send broken stuff like this.
quoted hunk
  		return NULL;
  	struct task_struct* task = (struct task_struct*)bpf_get_current_task();
  
@@ -534,14 +534,14 @@ static INLINE bool is_dentry_allowed_for_filemod(struct dentry* file_dentry,
  	*device_id = dev_id;
  	bool* allowed_device = bpf_map_lookup_elem(&allowed_devices, &dev_id);
  
-	if (allowed_device == NULL)
+	if (!allowed_device)
  		return false;
  
  	u64 ino = BPF_CORE_READ(file_dentry, d_inode, i_ino);
  	*file_ino = ino;
  	bool* allowed_file = bpf_map_lookup_elem(&allowed_file_inodes, &ino);
  
-	if (allowed_file == NULL)
+	if (!allowed_fil)
... same. You did not bother to compile test even.
quoted hunk
  		if (!is_ancestor_in_allowed_inodes(BPF_CORE_READ(file_dentry, d_parent)))
  			return false;
  	return true;
@@ -689,7 +689,7 @@ int raw_tracepoint__sched_process_exec(struct bpf_raw_tracepoint_args* ctx)
  	u64 inode = BPF_CORE_READ(bprm, file, f_inode, i_ino);
  
  	bool* should_filter_binprm = bpf_map_lookup_elem(&disallowed_exec_inodes, &inode);
-	if (should_filter_binprm != NULL)
+	if (should_filter_binprm)
  		goto out;
  
  	int zero = 0;

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help