Skip to contentSkip to conversation

tools/virtiofsd: Fix warning reported by Clang static code analyzer

PATCH In review Philippe Mathieu-Daudé 3 participants 11 messages Feb 17, 2020 – Feb 18, 2020 Arm/actions semi architecture

lore
Share & tools
lore
#0 lore raw

v2 cover tools/virtiofsd: Fix warning reported by Clang static code analyzer

Since v1:
- Addressed Ján Tomko review comment
- Added Ján Tomko R-b tag

Philippe Mathieu-Daudé (3):
tools/virtiofsd/passthrough_ll: Remove unneeded variable assignment tools/virtiofsd/passthrough_ll: Remove unneeded variable assignment tools/virtiofsd/fuse_lowlevel: Fix fuse_out_header::error value

 tools/virtiofsd/fuse_lowlevel.c  | 2 +-
 tools/virtiofsd/passthrough_ll.c | 4 ----
 2 files changed, 1 insertion(+), 5 deletions(-)
Signature · 1 line
2.21.1
#4 lore raw

PATCH v2 2/3 tools/virtiofsd/passthrough_ll: Remove unneeded variable assignment

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

---
v2: do not set newfd, use it (jtomko)

---
 tools/virtiofsd/passthrough_ll.c | 2 --
 1 file changed, 2 deletions(-)
tools/virtiofsd/passthrough_ll.c +0 -2
index e9e71d5fc2..02ff01fad0 100644
@@ -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);
Signature · 1 line
2.21.1
#1 lore raw

PATCH v2 1/3 tools/virtiofsd/passthrough_ll: Remove unneeded variable assignment

In reply to Philippe Mathieu-Daudé

Fix warning reported by Clang static code analyzer:

CC tools/virtiofsd/passthrough_ll.o
tools/virtiofsd/passthrough_ll.c:1083:5: warning: Value stored to 'saverr' is never read

      saverr = ENOMEM;
      ^        ~~~~~~
Fixes 7c6b66027
Reported-by Clang Static Analyzer
---
 tools/virtiofsd/passthrough_ll.c | 2 --
 1 file changed, 2 deletions(-)
tools/virtiofsd/passthrough_ll.c +0 -2
index c635fc8820..e9e71d5fc2 100644
@@ -1080,8 +1080,6 @@ static void lo_mknod_symlink(fuse_req_t req, fuse_ino_t parent,
         return;
     }
 
-    saverr = ENOMEM;
-
     saverr = lo_change_cred(req, &old);
     if (saverr) {
         goto out;
Signature · 1 line
2.21.1
#7 lore raw

RFC PATCH v2 3/3 tools/virtiofsd/fuse_lowlevel: Fix fuse_out_header::error value

In reply to Philippe Mathieu-Daudé

Fix warning reported by Clang static code analyzer:

CC tools/virtiofsd/fuse_lowlevel.o
tools/virtiofsd/fuse_lowlevel.c:195:9: warning: Value stored to 'error' is never read

          error = -ERANGE;
          ^       ~~~~~~~
Fixes 2de121f01e
Reported-by Clang Static Analyzer

---
RFC because untested

---
 tools/virtiofsd/fuse_lowlevel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/virtiofsd/fuse_lowlevel.c +1 -1
index 704c0369b2..2dd36ec03b 100644
@@ -192,7 +192,7 @@ int fuse_send_reply_iov_nofree(fuse_req_t req, int error, struct iovec *iov,
 
     if (error <= -1000 || error > 0) {
         fuse_log(FUSE_LOG_ERR, "fuse: bad error value: %i\n", error);
-        error = -ERANGE;
+        out.error = -ERANGE;
     }
 
     iov[0].iov_base = &out;
Signature · 1 line
2.21.1
Reviewed-by on v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] tools/virtiofsd/passthrough_ll: Remove unneeded variable assignment

In reply to Philippe Mathieu-Daudé
Quoted 11 lines · * Philippe Mathieu-Daudé ([email protected]) wrote:

Fix warning reported by Clang static code analyzer:

CC tools/virtiofsd/passthrough_ll.o
tools/virtiofsd/passthrough_ll.c:1083:5: warning: Value stored to 'saverr' is never read

      saverr = ENOMEM;
      ^        ~~~~~~
Fixes 7c6b66027
Reported-by Clang Static Analyzer

Thanks, you might want to snd that to the upstream libfuse (different context); it looks like it's the same there.

Dave

Quoted 20 lines
---
 tools/virtiofsd/passthrough_ll.c | 2 --
 1 file changed, 2 deletions(-)
tools/virtiofsd/passthrough_ll.c +0 -2
index c635fc8820..e9e71d5fc2 100644
@@ -1080,8 +1080,6 @@ static void lo_mknod_symlink(fuse_req_t req, fuse_ino_t parent,
         return;
     }
 
-    saverr = ENOMEM;
-
     saverr = lo_change_cred(req, &old);
     if (saverr) {
         goto out;
Signature · 1 line
2.21.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

Reviewed-by on v2 2/3
#5 lore raw

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

In reply to Philippe Mathieu-Daudé
Quoted 10 lines · Philippe Mathieu-Daudé

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;
         ^       ~~
Quoted 9 lines
Fixes 7c6b66027
Reported-by Clang Static Analyzer

---
v2: do not set newfd, use it (jtomko)
---
tools/virtiofsd/passthrough_ll.c | 2 --

1 file changed, 2 deletions(-)

Jano

#6 lore raw

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

In reply to Philippe Mathieu-Daudé
Quoted 10 lines · * Philippe Mathieu-Daudé ([email protected]) 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;
          ^       ~~
Quoted 3 lines
Fixes 7c6b66027
Reported-by Clang Static Analyzer

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

Quoted 29 lines

---
v2: do not set newfd, use it (jtomko)

---
 tools/virtiofsd/passthrough_ll.c | 2 --
 1 file changed, 2 deletions(-)
tools/virtiofsd/passthrough_ll.c +0 -2
index e9e71d5fc2..02ff01fad0 100644
@@ -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);
Signature · 1 line
2.21.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#3 lore raw

Re: [PATCH v2 1/3] tools/virtiofsd/passthrough_ll: Remove unneeded variable assignment

In reply to Dr. David Alan Gilbert
Quoted 8 lines · Dr. David Alan Gilbert
Quoted 7 lines · * Philippe Mathieu-Daudé ([email protected]) wrote:

Fix warning reported by Clang static code analyzer:

CC tools/virtiofsd/passthrough_ll.o
tools/virtiofsd/passthrough_ll.c:1083:5: warning: Value stored to 'saverr' is never read

       saverr = ENOMEM;
       ^        ~~~~~~
Quoted 7 lines
Quoted 4 lines
Fixes 7c6b66027
Reported-by Clang Static Analyzer

Thanks, you might want to snd that to the upstream libfuse (different context); it looks like it's the same there.

Done: https://github.com/libfuse/libfuse/pull/501

Quoted 2 lines

Thanks!

Reviewed-by on v2 3/3
#8 lore raw

Re: [RFC PATCH v2 3/3] tools/virtiofsd/fuse_lowlevel: Fix fuse_out_header::error value

In reply to Philippe Mathieu-Daudé
Quoted 11 lines · * Philippe Mathieu-Daudé ([email protected]) wrote:

Fix warning reported by Clang static code analyzer:

CC tools/virtiofsd/fuse_lowlevel.o
tools/virtiofsd/fuse_lowlevel.c:195:9: warning: Value stored to 'error' is never read

          error = -ERANGE;
          ^       ~~~~~~~
Fixes 2de121f01e
Reported-by Clang Static Analyzer

Nice, this actually fixes 3db2876

Quoted 22 lines

---
RFC because untested

---
 tools/virtiofsd/fuse_lowlevel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/virtiofsd/fuse_lowlevel.c +1 -1
index 704c0369b2..2dd36ec03b 100644
@@ -192,7 +192,7 @@ int fuse_send_reply_iov_nofree(fuse_req_t req, int error, struct iovec *iov,
 
     if (error <= -1000 || error > 0) {
         fuse_log(FUSE_LOG_ERR, "fuse: bad error value: %i\n", error);
-        error = -ERANGE;
+        out.error = -ERANGE;
     }
 
     iov[0].iov_base = &out;
Signature · 1 line
2.21.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#9 lore raw

Re: [RFC PATCH v2 3/3] tools/virtiofsd/fuse_lowlevel: Fix fuse_out_header::error value

Quoted 8 lines · Dr. David Alan Gilbert
Quoted 7 lines · * Philippe Mathieu-Daudé ([email protected]) wrote:

Fix warning reported by Clang static code analyzer:

CC tools/virtiofsd/fuse_lowlevel.o
tools/virtiofsd/fuse_lowlevel.c:195:9: warning: Value stored to 'error' is never read

           error = -ERANGE;
           ^       ~~~~~~~
Quoted 6 lines
Quoted 4 lines
Fixes 2de121f01e
Reported-by Clang Static Analyzer

Nice, this actually fixes 3db2876

Good catch, so this fix can be applied to QEMU (while patch #1 needs backport from upstream libfuse), right?

Quoted 2 lines

Thanks.

Quoted 26 lines
Quoted 23 lines

---
RFC because untested

---
  tools/virtiofsd/fuse_lowlevel.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/virtiofsd/fuse_lowlevel.c +1 -1
index 704c0369b2..2dd36ec03b 100644
@@ -192,7 +192,7 @@ int fuse_send_reply_iov_nofree(fuse_req_t req, int error, struct iovec *iov,
 
      if (error <= -1000 || error > 0) {
          fuse_log(FUSE_LOG_ERR, "fuse: bad error value: %i\n", error);
-        error = -ERANGE;
+        out.error = -ERANGE;
      }
 
      iov[0].iov_base = &out;
Signature · 1 line
2.21.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#10 lore raw

Re: [RFC PATCH v2 3/3] tools/virtiofsd/fuse_lowlevel: Fix fuse_out_header::error value

Quoted 14 lines · * Philippe Mathieu-Daudé ([email protected]) wrote:
Quoted 13 lines · Dr. David Alan Gilbert
Quoted 11 lines · * Philippe Mathieu-Daudé ([email protected]) wrote:

Fix warning reported by Clang static code analyzer:

CC tools/virtiofsd/fuse_lowlevel.o
tools/virtiofsd/fuse_lowlevel.c:195:9: warning: Value stored to 'error' is never read

           error = -ERANGE;
           ^       ~~~~~~~
Fixes 2de121f01e
Reported-by Clang Static Analyzer
Quoted 4 lines
Quoted 1 line

Nice, this actually fixes 3db2876

Good catch, so this fix can be applied to QEMU (while patch #1 needs backport from upstream libfuse), right?

I'll take all 3 into QEMU, libfuse can take it asynchronously.

Dave

Quoted 30 lines
Quoted 2 lines

Thanks.

Quoted 24 lines
Quoted 21 lines

---
RFC because untested

---
  tools/virtiofsd/fuse_lowlevel.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/virtiofsd/fuse_lowlevel.c +1 -1
index 704c0369b2..2dd36ec03b 100644
@@ -192,7 +192,7 @@ int fuse_send_reply_iov_nofree(fuse_req_t req, int error, struct iovec *iov,
      if (error <= -1000 || error > 0) {
          fuse_log(FUSE_LOG_ERR, "fuse: bad error value: %i\n", error);
-        error = -ERANGE;
+        out.error = -ERANGE;
      }
      iov[0].iov_base = &out;
Signature · 1 line
2.21.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK