Re: [PATCH] libtracefs: Fix the label usage in tracefs_instances_walk()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, 12 Mar 2023 15:45:21 +0100
Markus Elfring <Markus.Elfring@xxxxxx> 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@xxxxxx>
> ---
>  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
> 




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux