* Re: [PATCH] libtracefs: Fix the label usage in tracefs_instances_walk()
[not found] <4c0d9f08-2250-c7c4-4fb3-b10353be2941@web.de>
@ 2023-03-12 16:22 ` Steven Rostedt
0 siblings, 0 replies; only message in thread
From: Steven Rostedt @ 2023-03-12 16:22 UTC (permalink / raw)
To: Markus Elfring
Cc: Tzvetomir Stoyanov, linux-trace-devel, Daniel Wagner, Julia Lawall
On Sun, 12 Mar 2023 15:45:21 +0100
Markus Elfring <Markus.Elfring@web.de> 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?
>
> 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*!
>
> Fixes: 9150bc5fab4204392440b82b74e046e40723488c ("libtracefs: Add new tracefs API tracefs_instances_walk()")
It fixes NOTHING!
> Signed-off-by: Markus Elfring <Markus.Elfring@web.de>
> ---
> src/tracefs-instance.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/src/tracefs-instance.c b/src/tracefs-instance.c
> index 57f5c7f..952728e 100644
> --- a/src/tracefs-instance.c
> +++ b/src/tracefs-instance.c
> @@ -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;
>
> dir = opendir(path);
> if (!dir)
> - goto out;
> + goto put_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!
> +
> fret = 0;
> while ((dent = readdir(dir))) {
> char *instance;
> @@ -727,9 +728,8 @@ int tracefs_instances_walk(int (*callback)(const char *, void *), void *context)
> }
> }
>
> -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
> tracefs_put_tracing_file(path);
> return fret;
> }
> --
> 2.39.2
>
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-03-12 16:24 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <4c0d9f08-2250-c7c4-4fb3-b10353be2941@web.de>
2023-03-12 16:22 ` [PATCH] libtracefs: Fix the label usage in tracefs_instances_walk() Steven Rostedt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).