Skip to contentSkip to conversation

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

PATCH Superseded Philippe Mathieu-Daudé 2 participants 8 messages Feb 15, 2020 – Feb 17, 2020 Arm/actions semi architecture

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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

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 | 6 +-----
 2 files changed, 2 insertions(+), 6 deletions(-)
Signature · 1 line
2.21.1
#1 lore raw

PATCH 1/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: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
Reviewed-by on v1 1/3
#2 lore raw

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

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

---
tools/virtiofsd/passthrough_ll.c | 2 --

1 file changed, 2 deletions(-)

Jano

#3 lore raw

PATCH 2/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: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
---
 tools/virtiofsd/passthrough_ll.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
tools/virtiofsd/passthrough_ll.c +1 -3
index e9e71d5fc2..b38e0e4d84 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) {
@@ -938,8 +937,7 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
         g_atomic_int_set(&inode->refcount, 2);
 
         inode->nlookup = 1;
-        inode->fd = newfd;
-        newfd = -1;
+        inode->fd = -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
#4 lore raw

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

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

---
tools/virtiofsd/passthrough_ll.c | 4 +---

1 file changed, 1 insertion(+), 3 deletions(-)
tools/virtiofsd/passthrough_ll.c +0 -1
index e9e71d5fc2..b38e0e4d84 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) {

tools/virtiofsd/passthrough_ll.c static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name, · line 940

Quoted 6 lines
tools/virtiofsd/passthrough_ll.c +1 -2
@@ -938,8 +937,7 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name,
        g_atomic_int_set(&inode->refcount, 2);
 
        inode->nlookup = 1;
-        inode->fd = newfd;
-        newfd = -1;
+        inode->fd = -1;

The functional equivalent is:

    inode->fd = newfd;

newfd cannot contain -1 here, as checked a few lines above:

     newfd = openat(dir->fd, name, O_PATH | O_NOFOLLOW);
     if (newfd == -1) {
         goto out_err;
     }

Jano

Quoted 7 lines
tools/virtiofsd/passthrough_ll.c +0 -0
        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
#5 lore raw

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

Quoted 43 lines · Ján Tomko
Quoted 31 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;
         ^       ~~

Fixes 7c6b66027
Reported-by Clang Static Analyzer

---
tools/virtiofsd/passthrough_ll.c | 4 +---

1 file changed, 1 insertion(+), 3 deletions(-)
tools/virtiofsd/passthrough_ll.c +0 -1
index e9e71d5fc2..b38e0e4d84 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) {

tools/virtiofsd/passthrough_ll.c static int lo_do_lookup(fuse_req_t req, fuse_ino_t · line 941

Quoted 7 lines
tools/virtiofsd/passthrough_ll.c +1 -2
@@ -938,8 +937,7 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t 
 parent, const char *name,
         g_atomic_int_set(&inode->refcount, 2);
 
         inode->nlookup = 1;
-        inode->fd = newfd;
-        newfd = -1;
+        inode->fd = -1;

The functional equivalent is:
    inode->fd = newfd;

Quoted 5 lines

newfd cannot contain -1 here, as checked a few lines above:
     newfd = openat(dir->fd, name, O_PATH | O_NOFOLLOW); if (newfd == -1) {
         goto out_err;
     }

Correct. I'll respin, thanks for the review!

Quoted 9 lines

Jano

Quoted 7 lines
tools/virtiofsd/passthrough_ll.c +0 -0
         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
#6 lore raw

PATCH 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 v1 3/3
#7 lore raw

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

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

---
RFC because untested
---
tools/virtiofsd/fuse_lowlevel.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)

Jano