libtracefs: Fix the label usage in tracefs_instances_walk()
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 5 lines · On Sun, 12 Mar 2023 15:45:21 +0100 Markus Elfring <[email protected]> wrote:
Date: Sun, 12 Mar 2023 15:23:09 +0100
The label “out” was used to jump to a source code place after two failure cases despite of the implementation detail that the variable “dir” contained still a null pointer.
What's wrong with that?
Quoted 6 lines
Use a more appropriate label instead.
Delete a pointer check and omit an extra variable initialisation which became unnecessary with this change.This issue was detected by using the Coccinelle software.
No, the code is fine *as is*!
Quoted 2 lines
Fixes 9150bc5fab4204392440b82b74e046e40723488c ("libtracefs: Add new tracefs API tracefs_instances_walk()")
It fixes NOTHING!
Quoted 24 lines
Signed-off-by Markus Elfring <[email protected]>---
src/tracefs-instance.c | 12 ++++++------1 file changed, 6 insertions(+), 6 deletions(-)src/tracefs-instance.c +2
-2@@ -694,7 +694,7 @@ int tracefs_instances_walk(int (*callback)(const char *, void *), void *context) { struct dirent *dent; char *path = NULL; - DIR *dir = NULL; + DIR *dir; struct stat st; int fret = -1; int ret;@@ -704,11 +704,12 @@ int tracefs_instances_walk(int (*callback)(const char *, void *), void *context) return -1; ret = stat(path, &st); if (ret < 0 || !S_ISDIR(st.st_mode)) - goto out; + goto put_tracing_file;
Quoted 5 lines
dir = opendir(path);
if (!dir)
- goto out;
+ gotoput_tracing_file;
out is a perfectly fine label. In fact, because it is the normal path, it is what I use. Don't change it!
src/tracefs-instance.c
Quoted 13 lines
+
fret = 0;
while ((dent = readdir(dir))) {
char *instance;src/tracefs-instance.c +0
-0@@ -727,9 +728,8 @@ int tracefs_instances_walk(int (*callback)(const char *, void *), void *context) } }src/tracefs-instance.c +2
-3-out: - if (dir) - closedir(dir); + closedir(dir); +put_tracing_file:
I'm fine if the patch just moves the out label, and removes the dir = NULL, but the label remains as "out:". And it's a clean up *not* a fix!
-- Steve
Quoted 6 lines
tracefs_put_tracing_file(path);
return fret;
}
--
2.39.2