Skip to contentSkip to conversation

microvm: fix Coverity warnings

PATCH In review Gerd Hoffmann 3 participants 5 messages Nov 8, 2021

lore
Share & tools
lore
#0 lore raw

cover microvm: fix Coverity warnings

Gerd Hoffmann (2):
microvm: add missing g_free() call
microvm: check g_file_set_contents() return value

 hw/i386/microvm-dt.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/2 microvm: add missing g_free() call

Fixes CID 1465240
---
 hw/i386/microvm-dt.c | 2 ++
 1 file changed, 2 insertions(+)
hw/i386/microvm-dt.c +2 -0
index 875ba9196394..ad4e48e5fe60 100644
@@ -143,6 +143,8 @@ static void dt_add_pcie(MicrovmMachineState *mms)
     nr_pcie_buses = PCIE_ECAM_SIZE / PCIE_MMCFG_SIZE_MIN;
     qemu_fdt_setprop_cells(mms->fdt, nodename, "bus-range", 0,
                            nr_pcie_buses - 1);
+
+    g_free(nodename);
 }
 
 static void dt_add_ioapic(MicrovmMachineState *mms, SysBusDevice *dev)
Signature · 1 line
2.31.1
#3 lore raw

PATCH 2/2 microvm: check g_file_set_contents() return value

In reply to Gerd Hoffmann
Fixes CID 1465239
---
 hw/i386/microvm-dt.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
hw/i386/microvm-dt.c +4 -1
index ad4e48e5fe60..774e0bc7fef3 100644
@@ -334,7 +334,10 @@ void dt_setup_microvm(MicrovmMachineState *mms)
 
     if (debug) {
         fprintf(stderr, "%s: writing microvm.fdt\n", __func__);
-        g_file_set_contents("microvm.fdt", mms->fdt, size, NULL);
+        if (!g_file_set_contents("microvm.fdt", mms->fdt, size, NULL)) {
+            fprintf(stderr, "%s: writing microvm.fdt failed\n", __func__);
+            return;
+        }
         int ret = system("dtc -I dtb -O dts microvm.fdt");
         if (ret != 0) {
             fprintf(stderr, "%s: oops, dtc not installed?\n", __func__);
Signature · 1 line
2.31.1
#4 lore raw

Re: [PATCH 2/2] microvm: check g_file_set_contents() return value

Quoted 13 lines · Gerd Hoffmann
Fixes CID 1465239
---
 hw/i386/microvm-dt.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
hw/i386/microvm-dt.c +0 -0
index ad4e48e5fe60..774e0bc7fef3 100644
@@ -334,7 +334,10 @@ void dt_setup_microvm(MicrovmMachineState *mms)
 

hw/i386/microvm-dt.c void dt_setup_microvm(MicrovmMachineState *mms) · line 343

Quoted 10 lines
hw/i386/microvm-dt.c +4 -1
     if (debug) {
         fprintf(stderr, "%s: writing microvm.fdt\n", __func__);
-        g_file_set_contents("microvm.fdt", mms->fdt, size, NULL);
+        if (!g_file_set_contents("microvm.fdt", mms->fdt, size, NULL)) {
+            fprintf(stderr, "%s: writing microvm.fdt failed\n", __func__);
+            return;
+        }
         int ret = system("dtc -I dtb -O dts microvm.fdt");
         if (ret != 0) {
             fprintf(stderr, "%s: oops, dtc not installed?\n", __func__);

Side note -- rather than invoking dtc from QEMU like this, it would be more in line with the way other machine types deal with debugging of autogenerated dtb files to support "-machine dumpdtb=file.dtb" and let the end user decompile the dtb themselves.

-- PMM