Skip to contentSkip to conversation

softmmu/physmem.c: Remove unneeded NULL check in qemu_ram_alloc_from_fd()

PATCH In review Peter Maydell 2 participants 2 messages Aug 12, 2021 – Aug 13, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 softmmu/physmem.c: Remove unneeded NULL check in qemu_ram_alloc_from_fd()

In the alignment check added to qemu_ram_alloc_from_fd() in commit ce317be98db0dfdfa, the condition includes a check that 'mr' is not NULL. This check is unnecessary because we can assume that the caller always passes us a valid MemoryRegion, and indeed later in the function we assume mr is not NULL when we pass it to file_ram_alloc() as new_block->mr. Remove it.

Fixes Coverity 1459867
Fixes ce317be98d ("exec: fetch the alignment of Linux devdax pmem character device nodes")
---
 softmmu/physmem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
softmmu/physmem.c +1 -1
index 3c1912a1a07..c47cb6da2e4 100644
@@ -2075,7 +2075,7 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
     }
 
     file_align = get_file_align(fd);
-    if (file_align > 0 && mr && file_align > mr->align) {
+    if (file_align > 0 && file_align > mr->align) {
         error_setg(errp, "backing store align 0x%" PRIx64
                    " is larger than 'align' option 0x%" PRIx64,
                    file_align, mr->align);
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 20 lines · Peter Maydell

In the alignment check added to qemu_ram_alloc_from_fd() in commit ce317be98db0dfdfa, the condition includes a check that 'mr' is not NULL. This check is unnecessary because we can assume that the caller always passes us a valid MemoryRegion, and indeed later in the function we assume mr is not NULL when we pass it to file_ram_alloc() as new_block->mr. Remove it.

Fixes Coverity 1459867
Fixes ce317be98d ("exec: fetch the alignment of Linux devdax pmem character device nodes")
---
  softmmu/physmem.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
softmmu/physmem.c +0 -0
index 3c1912a1a07..c47cb6da2e4 100644

softmmu/physmem.c RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, · line 2081

Quoted 8 lines
softmmu/physmem.c +1 -1
@@ -2075,7 +2075,7 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
      }
 
      file_align = get_file_align(fd);
-    if (file_align > 0 && mr && file_align > mr->align) {
+    if (file_align > 0 && file_align > mr->align) {
          error_setg(errp, "backing store align 0x%" PRIx64
                     " is larger than 'align' option 0x%" PRIx64,
                     file_align, mr->align);

'mr' is indeed not NULL in the current code.

Thanks,
Jingqi