Skip to contentSkip to conversation

tools: fix warning comparing pointer to 0

PATCH In review CGEL 3 participants 3 messages Aug 20, 2021 – Aug 23, 2021

Subsystems (5)
lore
Share & tools
lore

CGEL

author
#0 lore raw

PATCH 1/1 tools: fix warning comparing pointer to 0

From: jing yangyang <[email protected]>

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

---
 tools/testing/selftests/bpf/progs/profiler.inc.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tools/testing/selftests/bpf/progs/profiler.inc.h +4 -4
index 4896fdf..5c0bdab 100644
@@ -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;
Signature · 1 line
1.8.3.1
#1 lore raw
Thank you for the patch! Yet something to improve:

Hi CGEL,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on next-20210819]

url:    https://github.com/0day-ci/linux/commits/CGEL/tools-fix-warning-comparing-pointer-to-0/20210820-113325
base:    33e65b1f975cd2814fc0ea9617250fc4c1d7a553
config: x86_64-rhel-8.3-kselftests (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.3-348-gf0e6938b-dirty
        # https://github.com/0day-ci/linux/commit/b8c00506ae6f75c8d0dcc46b55962bb93b6bbeb5
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review CGEL/tools-fix-warning-comparing-pointer-to-0/20210820-113325
        git checkout b8c00506ae6f75c8d0dcc46b55962bb93b6bbeb5
        # save the attached .config to linux build tree
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=x86_64 SHELL=/bin/bash -C tools/testing/selftests/bpf install

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

In file included from progs/profiler1.c:6:

>> progs/profiler.inc.h:364:7: error: use of undeclared identifier 'kill_dat'; did you mean 'kill_data'?
           if (!kill_dat)
                ^~~~~~~~
                kill_data
   progs/profiler.inc.h:362:26: note: 'kill_data' declared here
           struct var_kill_data_t* kill_data = bpf_map_lookup_elem(&data_heap, &zero);
                                   ^
>> progs/profiler.inc.h:544:7: error: use of undeclared identifier 'allowed_fil'; did you mean 'allowed_file'?
           if (!allowed_fil)
                ^~~~~~~~~~~
                allowed_file
   progs/profiler.inc.h:542:8: note: 'allowed_file' declared here
           bool* allowed_file = bpf_map_lookup_elem(&allowed_file_inodes, &ino);
                 ^

2 errors generated.

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

maintainer
#2 lore raw
In reply to CGEL
Quoted 12 lines · CGEL

From: jing yangyang <[email protected]>

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

Quoted 2 lines

Please properly explain in the commit message what this 'fixes' exactly and why it is needed.

Quoted 9 lines
---
  tools/testing/selftests/bpf/progs/profiler.inc.h | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
tools/testing/selftests/bpf/progs/profiler.inc.h +0 -0
index 4896fdf..5c0bdab 100644

tools/testing/selftests/bpf/progs/profiler.inc.h static INLINE void* populate_var_metadata(struct var_metadata_t* metadata, · line 364

Quoted 5 lines
tools/testing/selftests/bpf/progs/profiler.inc.h +1 -1
@@ -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 7 lines
tools/testing/selftests/bpf/progs/profiler.inc.h +0 -0
  		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);
 

tools/testing/selftests/bpf/progs/profiler.inc.h static INLINE bool is_dentry_allowed_for_filemod(struct dentry* file_dentry, · line 544

Quoted 10 lines
tools/testing/selftests/bpf/progs/profiler.inc.h +2 -2
-	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 13 lines
tools/testing/selftests/bpf/progs/profiler.inc.h +1 -1
  		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;