diff mbox series

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

Message ID 20211108130718.840216-3-kraxel@redhat.com
State New
Headers show
Series microvm: fix Coverity warnings | expand

Commit Message

Gerd Hoffmann Nov. 8, 2021, 1:07 p.m. UTC
Fixes: CID 1465239
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/i386/microvm-dt.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Peter Maydell Nov. 8, 2021, 3:35 p.m. UTC | #1
On Mon, 8 Nov 2021 at 13:11, Gerd Hoffmann <kraxel@redhat.com> wrote:
>
> Fixes: CID 1465239
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  hw/i386/microvm-dt.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/hw/i386/microvm-dt.c b/hw/i386/microvm-dt.c
> index ad4e48e5fe60..774e0bc7fef3 100644
> --- a/hw/i386/microvm-dt.c
> +++ b/hw/i386/microvm-dt.c
> @@ -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__);

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
diff mbox series

Patch

diff --git a/hw/i386/microvm-dt.c b/hw/i386/microvm-dt.c
index ad4e48e5fe60..774e0bc7fef3 100644
--- a/hw/i386/microvm-dt.c
+++ b/hw/i386/microvm-dt.c
@@ -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__);