From: Steven Rostedt <rostedt@goodmis.org>
To: Markus Elfring <Markus.Elfring@web.de>
Cc: Tzvetomir Stoyanov <tz.stoyanov@gmail.com>,
linux-trace-devel@vger.kernel.org,
Daniel Wagner <dwagner@suse.de>,
Julia Lawall <julia.lawall@inria.fr>
Subject: Re: [PATCH] libtracefs: Fix the label usage in tracefs_instances_walk()
Date: Sun, 12 Mar 2023 12:22:32 -0400 [thread overview]
Message-ID: <20230312122232.7e88d259@rorschach.local.home> (raw)
In-Reply-To: <4c0d9f08-2250-c7c4-4fb3-b10353be2941@web.de>
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
>
parent reply other threads:[~2023-03-12 16:24 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <4c0d9f08-2250-c7c4-4fb3-b10353be2941@web.de>]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230312122232.7e88d259@rorschach.local.home \
--to=rostedt@goodmis.org \
--cc=Markus.Elfring@web.de \
--cc=dwagner@suse.de \
--cc=julia.lawall@inria.fr \
--cc=linux-trace-devel@vger.kernel.org \
--cc=tz.stoyanov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).