diff mbox series

[v2,2/3] tools/virtiofsd/passthrough_ll: Remove unneeded variable assignment

Message ID 20200217094240.9927-3-philmd@redhat.com (mailing list archive)
State New, archived
Headers show
Series tools/virtiofsd: Fix warning reported by Clang static code analyzer | expand

Commit Message

Philippe Mathieu-Daudé Feb. 17, 2020, 9:42 a.m. UTC
Fix warning reported by Clang static code analyzer:

    CC      tools/virtiofsd/passthrough_ll.o
  tools/virtiofsd/passthrough_ll.c:925:9: warning: Value stored to 'newfd' is never read
          newfd = -1;
          ^       ~~
  tools/virtiofsd/passthrough_ll.c:942:9: warning: Value stored to 'newfd' is never read
          newfd = -1;
          ^       ~~

Fixes: 7c6b66027
Reported-by: Clang Static Analyzer
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
v2: do not set newfd, use it (jtomko)
---
 tools/virtiofsd/passthrough_ll.c | 2 --
 1 file changed, 2 deletions(-)

Comments

Ján Tomko Feb. 17, 2020, 11:42 a.m. UTC | #1
On Mon, Feb 17, 2020 at 10:42:39AM +0100, Philippe Mathieu-Daudé wrote:
>Fix warning reported by Clang static code analyzer:
>
>    CC      tools/virtiofsd/passthrough_ll.o
>  tools/virtiofsd/passthrough_ll.c:925:9: warning: Value stored to 'newfd' is never read
>          newfd = -1;
>          ^       ~~
>  tools/virtiofsd/passthrough_ll.c:942:9: warning: Value stored to 'newfd' is never read
>          newfd = -1;
>          ^       ~~
>
>Fixes: 7c6b66027
>Reported-by: Clang Static Analyzer
>Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>---
>v2: do not set newfd, use it (jtomko)
>---
> tools/virtiofsd/passthrough_ll.c | 2 --
> 1 file changed, 2 deletions(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano
Dr. David Alan Gilbert Feb. 17, 2020, 12:07 p.m. UTC | #2
* Philippe Mathieu-Daudé (philmd@redhat.com) wrote:
> Fix warning reported by Clang static code analyzer:
> 
>     CC      tools/virtiofsd/passthrough_ll.o
>   tools/virtiofsd/passthrough_ll.c:925:9: warning: Value stored to 'newfd' is never read
>           newfd = -1;
>           ^       ~~
>   tools/virtiofsd/passthrough_ll.c:942:9: warning: Value stored to 'newfd' is never read
>           newfd = -1;
>           ^       ~~
> 
> Fixes: 7c6b66027
> Reported-by: Clang Static Analyzer
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

OK; actually one of those is in upstream, and another was added
by Miklos's 'virtiofsd: fail when parent inode isn't known in
lo_do_lookup()' - which kind of balances that if out.
I suspect the reason was because out_err: closes newfd if it's
not -1, so they were keeping it safe like that just in case another
error case gets added.

Dave

> ---
> v2: do not set newfd, use it (jtomko)
> ---
>  tools/virtiofsd/passthrough_ll.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
> index e9e71d5fc2..02ff01fad0 100644
> --- a/tools/virtiofsd/passthrough_ll.c
> +++ b/tools/virtiofsd/passthrough_ll.c
> @@ -922,7 +922,6 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
>      inode = lo_find(lo, &e->attr);
>      if (inode) {
>          close(newfd);
> -        newfd = -1;
>      } else {
>          inode = calloc(1, sizeof(struct lo_inode));
>          if (!inode) {
> @@ -939,7 +938,6 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
>  
>          inode->nlookup = 1;
>          inode->fd = newfd;
> -        newfd = -1;
>          inode->key.ino = e->attr.st_ino;
>          inode->key.dev = e->attr.st_dev;
>          pthread_mutex_init(&inode->plock_mutex, NULL);
> -- 
> 2.21.1
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
diff mbox series

Patch

diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
index e9e71d5fc2..02ff01fad0 100644
--- a/tools/virtiofsd/passthrough_ll.c
+++ b/tools/virtiofsd/passthrough_ll.c
@@ -922,7 +922,6 @@  static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
     inode = lo_find(lo, &e->attr);
     if (inode) {
         close(newfd);
-        newfd = -1;
     } else {
         inode = calloc(1, sizeof(struct lo_inode));
         if (!inode) {
@@ -939,7 +938,6 @@  static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
 
         inode->nlookup = 1;
         inode->fd = newfd;
-        newfd = -1;
         inode->key.ino = e->attr.st_ino;
         inode->key.dev = e->attr.st_dev;
         pthread_mutex_init(&inode->plock_mutex, NULL);