Skip to contentSkip to conversation

9pfs: fix dead code in qemu_open_flags_tostr()

PATCH In review Christian Schoenebeck 3 participants 5 messages Feb 10, 2025 – Feb 11, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 9pfs: fix dead code in qemu_open_flags_tostr()

Coverity scan complained about expression "|LARGEFILE" to be non reachable and the detailed Coverity report claims O_LARGEFILE was zero. I can't reproduce this here, but I assume that means there are at least some system(s) which define O_LARGEFILE as zero.

This is not really an issue, but to silence this Coverity warning, add a preprocessor wrapper that checks for O_LARGEFILE being non-zero for this overall expression. The 'defined(O_LARGEFILE)' check is not necessary, but it makes it more clear that we really want to check for the value of O_LARGEFILE, not just whether the macro was defined.

Fixes 9a0dd4b3

Resolves: Coverity CID 1591178

Reported-by Coverity Scan
---
 hw/9pfs/9p-util-generic.c | 2 ++
 1 file changed, 2 insertions(+)
hw/9pfs/9p-util-generic.c +2 -0
index 4c1e9c887d..02e359f17b 100644
@@ -19,7 +19,9 @@ char *qemu_open_flags_tostr(int flags)
         #ifdef O_DIRECT
         (flags & O_DIRECT) ? "|DIRECT" : "",
         #endif
+        #if defined(O_LARGEFILE) && O_LARGEFILE != 0
         (flags & O_LARGEFILE) ? "|LARGEFILE" : "",
+        #endif
         (flags & O_DIRECTORY) ? "|DIRECTORY" : "",
         (flags & O_NOFOLLOW) ? "|NOFOLLOW" : "",
         #ifdef O_NOATIME
Signature · 1 line
2.39.5
#1 lore raw
Quoted 4 lines · Christian Schoenebeck

Coverity scan complained about expression "|LARGEFILE" to be non reachable and the detailed Coverity report claims O_LARGEFILE was zero. I can't reproduce this here, but I assume that means there are at least some system(s) which define O_LARGEFILE as zero.

Is O_LARGEFILE a Linux-ism?

Commit 67b915a5dd5 ("win32 port (initial patch by kazu)") started to define it to 0 on 32-bit Windows. It isn't defined on my 64-bit Darwin, and apparently nor on other BSDs.

Quoted 28 lines

This is not really an issue, but to silence this Coverity warning, add a preprocessor wrapper that checks for O_LARGEFILE being non-zero for this overall expression. The 'defined(O_LARGEFILE)' check is not necessary, but it makes it more clear that we really want to check for the value of O_LARGEFILE, not just whether the macro was defined.

Fixes 9a0dd4b3

Resolves: Coverity CID 1591178

Reported-by Coverity Scan
---
  hw/9pfs/9p-util-generic.c | 2 ++
  1 file changed, 2 insertions(+)
hw/9pfs/9p-util-generic.c +2 -0
index 4c1e9c887d..02e359f17b 100644
@@ -19,7 +19,9 @@ char *qemu_open_flags_tostr(int flags)
          #ifdef O_DIRECT
          (flags & O_DIRECT) ? "|DIRECT" : "",
          #endif
+        #if defined(O_LARGEFILE) && O_LARGEFILE != 0
          (flags & O_LARGEFILE) ? "|LARGEFILE" : "",
+        #endif
          (flags & O_DIRECTORY) ? "|DIRECTORY" : "",
          (flags & O_NOFOLLOW) ? "|NOFOLLOW" : "",
          #ifdef O_NOATIME
#2 lore raw
Quoted 7 lines · CET Philippe Mathieu-Daudé
Quoted 4 lines · Christian Schoenebeck

Coverity scan complained about expression "|LARGEFILE" to be non reachable and the detailed Coverity report claims O_LARGEFILE was zero. I can't reproduce this here, but I assume that means there are at least some system(s) which define O_LARGEFILE as zero.

Is O_LARGEFILE a Linux-ism?

Ah right, O_LARGEFILE is indeed Linux-specific, not POSIX.

Quoted 3 lines

Commit 67b915a5dd5 ("win32 port (initial patch by kazu)") started to define it to 0 on 32-bit Windows. It isn't defined on my 64-bit Darwin, and apparently nor on other BSDs.

Yeah, that explains why O_LARGEFILE was defined as zero. I'll adjust the commit log message at least on my end. The code change itself is appropriate.

Thanks!

/Christian

Quoted 31 lines
Quoted 28 lines

This is not really an issue, but to silence this Coverity warning, add a preprocessor wrapper that checks for O_LARGEFILE being non-zero for this overall expression. The 'defined(O_LARGEFILE)' check is not necessary, but it makes it more clear that we really want to check for the value of O_LARGEFILE, not just whether the macro was defined.

Fixes 9a0dd4b3

Resolves: Coverity CID 1591178

Reported-by Coverity Scan
---
  hw/9pfs/9p-util-generic.c | 2 ++
  1 file changed, 2 insertions(+)
hw/9pfs/9p-util-generic.c +2 -0
index 4c1e9c887d..02e359f17b 100644
@@ -19,7 +19,9 @@ char *qemu_open_flags_tostr(int flags)
          #ifdef O_DIRECT
          (flags & O_DIRECT) ? "|DIRECT" : "",
          #endif
+        #if defined(O_LARGEFILE) && O_LARGEFILE != 0
          (flags & O_LARGEFILE) ? "|LARGEFILE" : "",
+        #endif
          (flags & O_DIRECTORY) ? "|DIRECTORY" : "",
          (flags & O_NOFOLLOW) ? "|NOFOLLOW" : "",
          #ifdef O_NOATIME
#3 lore raw
In reply to Christian Schoenebeck
Quoted 25 lines · Christian Schoenebeck

Coverity scan complained about expression "|LARGEFILE" to be non reachable and the detailed Coverity report claims O_LARGEFILE was zero. I can't reproduce this here, but I assume that means there are at least some system(s) which define O_LARGEFILE as zero.

This is not really an issue, but to silence this Coverity warning, add a preprocessor wrapper that checks for O_LARGEFILE being non-zero for this overall expression. The 'defined(O_LARGEFILE)' check is not necessary, but it makes it more clear that we really want to check for the value of O_LARGEFILE, not just whether the macro was defined.

Fixes 9a0dd4b3

Resolves: Coverity CID 1591178

Reported-by Coverity Scan
---
 hw/9pfs/9p-util-generic.c | 2 ++
 1 file changed, 2 insertions(+)
hw/9pfs/9p-util-generic.c +0 -0
index 4c1e9c887d..02e359f17b 100644

hw/9pfs/9p-util-generic.c char *qemu_open_flags_tostr(int flags) · line 27

Quoted 9 lines
hw/9pfs/9p-util-generic.c +2 -0
@@ -19,7 +19,9 @@ char *qemu_open_flags_tostr(int flags)
         #ifdef O_DIRECT
         (flags & O_DIRECT) ? "|DIRECT" : "",
         #endif
+        #if defined(O_LARGEFILE) && O_LARGEFILE != 0
         (flags & O_LARGEFILE) ? "|LARGEFILE" : "",
+        #endif
         (flags & O_DIRECTORY) ? "|DIRECTORY" : "",
         (flags & O_NOFOLLOW) ? "|NOFOLLOW" : "",
         #ifdef O_NOATIME

I don't think we need to make this change -- the code is correct, and osdep.h defines O_LARGEFILE if the system doesn't, exactly so that we don't need to put in extra ifdefs in the code itself. Coverity often fails to understand that some code is not dead in a different configuration or host OS than the one that got scanned. I've marked the issue as a false-positive in the Coverity UI.

thanks
-- PMM

#4 lore raw
Quoted 37 lines · CET Peter Maydell
Quoted 25 lines · Christian Schoenebeck

Coverity scan complained about expression "|LARGEFILE" to be non reachable and the detailed Coverity report claims O_LARGEFILE was zero. I can't reproduce this here, but I assume that means there are at least some system(s) which define O_LARGEFILE as zero.

This is not really an issue, but to silence this Coverity warning, add a preprocessor wrapper that checks for O_LARGEFILE being non-zero for this overall expression. The 'defined(O_LARGEFILE)' check is not necessary, but it makes it more clear that we really want to check for the value of O_LARGEFILE, not just whether the macro was defined.

Fixes 9a0dd4b3

Resolves: Coverity CID 1591178

Reported-by Coverity Scan
---
 hw/9pfs/9p-util-generic.c | 2 ++
 1 file changed, 2 insertions(+)
hw/9pfs/9p-util-generic.c +0 -0
index 4c1e9c887d..02e359f17b 100644

hw/9pfs/9p-util-generic.c char *qemu_open_flags_tostr(int flags) · line 27

Quoted 9 lines
hw/9pfs/9p-util-generic.c +2 -0
@@ -19,7 +19,9 @@ char *qemu_open_flags_tostr(int flags)
         #ifdef O_DIRECT
         (flags & O_DIRECT) ? "|DIRECT" : "",
         #endif
+        #if defined(O_LARGEFILE) && O_LARGEFILE != 0
         (flags & O_LARGEFILE) ? "|LARGEFILE" : "",
+        #endif
         (flags & O_DIRECTORY) ? "|DIRECTORY" : "",
         (flags & O_NOFOLLOW) ? "|NOFOLLOW" : "",
         #ifdef O_NOATIME
Quoted 7 lines

I don't think we need to make this change -- the code is correct, and osdep.h defines O_LARGEFILE if the system doesn't, exactly so that we don't need to put in extra ifdefs in the code itself. Coverity often fails to understand that some code is not dead in a different configuration or host OS than the one that got scanned. I've marked the issue as a false-positive in the Coverity UI.

Fine with me, thanks!

/Christian