Skip to contentSkip to conversation

tools/testing: Check correct variable in open_procmap()

PATCH Applied Dan Carpenter 2 participants 2 messages May 28, 2025

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

PATCH 1/1 tools/testing: Check correct variable in open_procmap()

Check if "procmap_out->fd" is negative instead of "procmap_out" (which is a pointer).

Fixes bd23f293a0d5 ("tools/testing: add PROCMAP_QUERY helper functions in mm self tests")
---
 tools/testing/selftests/mm/vm_util.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/mm/vm_util.c +1 -1
index 1357e2d6a7b6..61d7bf1f8c62 100644
@@ -439,7 +439,7 @@ int open_procmap(pid_t pid, struct procmap_fd *procmap_out)
 	sprintf(path, "/proc/%d/maps", pid);
 	procmap_out->query.size = sizeof(procmap_out->query);
 	procmap_out->fd = open(path, O_RDONLY);
-	if (procmap_out < 0)
+	if (procmap_out->fd < 0)
 		ret = -errno;
 
 	return ret;
Signature · 1 line
2.47.2
Reviewed-by on v1 1/1
#1 lore raw

Thanks so much for catching this Dan!

Quoted 2 lines · Dan Carpenter

Check if "procmap_out->fd" is negative instead of "procmap_out" (which is a pointer).

Ye gods, so sorry for such a clanger! Entirely my fault, though I may mutter a grumble about C type safety under my breath :P

Quoted 3 lines
Fixes bd23f293a0d5 ("tools/testing: add PROCMAP_QUERY helper functions in mm self tests")
Quoted 18 lines
---
 tools/testing/selftests/mm/vm_util.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/mm/vm_util.c +1 -2
index 1357e2d6a7b6..61d7bf1f8c62 100644
@@ -439,7 +439,7 @@ int open_procmap(pid_t pid, struct procmap_fd *procmap_out)
 	sprintf(path, "/proc/%d/maps", pid);
 	procmap_out->query.size = sizeof(procmap_out->query);
 	procmap_out->fd = open(path, O_RDONLY);
-	if (procmap_out < 0)
+	if (procmap_out->fd < 0)
 		ret = -errno;
 
 	return ret;
--
Quoted 2 lines

2.47.2

Cheers, Lorenzo