All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 02/55] hw/arm/sysbus-fdt: Replace error_setg(&error_fatal) by error_report() + exit()
Date: Fri, 29 Jun 2018 15:52:54 +0100	[thread overview]
Message-ID: <20180629145347.652-3-peter.maydell@linaro.org> (raw)
In-Reply-To: <20180629145347.652-1-peter.maydell@linaro.org>

From: Philippe Mathieu-Daudé <f4bug@amsat.org>

Use error_report() + exit() instead of error_setg(&error_fatal),
as suggested by the "qapi/error.h" documentation:

   Please don't error_setg(&error_fatal, ...), use error_report() and
   exit(), because that's more obvious.

This fixes CID 1352173:
    "Passing null pointer dt_name to qemu_fdt_node_path, which dereferences it."

And this also fixes:

    hw/arm/sysbus-fdt.c:322:9: warning: Array access (from variable 'node_path') results in a null pointer dereference
        if (node_path[1]) {
            ^~~~~~~~~~~~

Fixes: Coverity CID 1352173 (Dereference after null check)
Suggested-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Message-id: 20180625165749.3910-3-f4bug@amsat.org
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 hw/arm/sysbus-fdt.c | 53 +++++++++++++++++++++++++--------------------
 1 file changed, 30 insertions(+), 23 deletions(-)

diff --git a/hw/arm/sysbus-fdt.c b/hw/arm/sysbus-fdt.c
index 277ed872e7c..0d4c75702c3 100644
--- a/hw/arm/sysbus-fdt.c
+++ b/hw/arm/sysbus-fdt.c
@@ -92,16 +92,20 @@ static void copy_properties_from_host(HostProperty *props, int nb_props,
         r = qemu_fdt_getprop(host_fdt, node_path,
                              props[i].name,
                              &prop_len,
-                             props[i].optional ? &err : &error_fatal);
+                             &err);
         if (r) {
             qemu_fdt_setprop(guest_fdt, nodename,
                              props[i].name, r, prop_len);
         } else {
-            if (prop_len != -FDT_ERR_NOTFOUND) {
-                /* optional property not returned although property exists */
-                error_report_err(err);
-            } else {
+            if (props[i].optional && prop_len == -FDT_ERR_NOTFOUND) {
+                /* optional property does not exist */
                 error_free(err);
+            } else {
+                error_report_err(err);
+            }
+            if (!props[i].optional) {
+                /* mandatory property not found: bail out */
+                exit(1);
             }
         }
     }
@@ -138,9 +142,9 @@ static void fdt_build_clock_node(void *host_fdt, void *guest_fdt,
 
     node_offset = fdt_node_offset_by_phandle(host_fdt, host_phandle);
     if (node_offset <= 0) {
-        error_setg(&error_fatal,
-                   "not able to locate clock handle %d in host device tree",
-                   host_phandle);
+        error_report("not able to locate clock handle %d in host device tree",
+                     host_phandle);
+        exit(1);
     }
     node_path = g_malloc(path_len);
     while ((ret = fdt_get_path(host_fdt, node_offset, node_path, path_len))
@@ -149,16 +153,16 @@ static void fdt_build_clock_node(void *host_fdt, void *guest_fdt,
         node_path = g_realloc(node_path, path_len);
     }
     if (ret < 0) {
-        error_setg(&error_fatal,
-                   "not able to retrieve node path for clock handle %d",
-                   host_phandle);
+        error_report("not able to retrieve node path for clock handle %d",
+                     host_phandle);
+        exit(1);
     }
 
     r = qemu_fdt_getprop(host_fdt, node_path, "compatible", &prop_len,
                          &error_fatal);
     if (strcmp(r, "fixed-clock")) {
-        error_setg(&error_fatal,
-                   "clock handle %d is not a fixed clock", host_phandle);
+        error_report("clock handle %d is not a fixed clock", host_phandle);
+        exit(1);
     }
 
     nodename = strrchr(node_path, '/');
@@ -301,34 +305,37 @@ static int add_amd_xgbe_fdt_node(SysBusDevice *sbdev, void *opaque)
 
     dt_name = sysfs_to_dt_name(vbasedev->name);
     if (!dt_name) {
-        error_setg(&error_fatal, "%s incorrect sysfs device name %s",
-                    __func__, vbasedev->name);
+        error_report("%s incorrect sysfs device name %s",
+                     __func__, vbasedev->name);
+        exit(1);
     }
     node_path = qemu_fdt_node_path(host_fdt, dt_name, vdev->compat,
                                    &error_fatal);
     if (!node_path || !node_path[0]) {
-        error_setg(&error_fatal, "%s unable to retrieve node path for %s/%s",
-                   __func__, dt_name, vdev->compat);
+        error_report("%s unable to retrieve node path for %s/%s",
+                     __func__, dt_name, vdev->compat);
+        exit(1);
     }
 
     if (node_path[1]) {
-        error_setg(&error_fatal, "%s more than one node matching %s/%s!",
-                   __func__, dt_name, vdev->compat);
+        error_report("%s more than one node matching %s/%s!",
+                     __func__, dt_name, vdev->compat);
+        exit(1);
     }
 
     g_free(dt_name);
 
     if (vbasedev->num_regions != 5) {
-        error_setg(&error_fatal, "%s Does the host dt node combine XGBE/PHY?",
-                   __func__);
+        error_report("%s Does the host dt node combine XGBE/PHY?", __func__);
+        exit(1);
     }
 
     /* generate nodes for DMA_CLK and PTP_CLK */
     r = qemu_fdt_getprop(host_fdt, node_path[0], "clocks",
                          &prop_len, &error_fatal);
     if (prop_len != 8) {
-        error_setg(&error_fatal, "%s clocks property should contain 2 handles",
-                   __func__);
+        error_report("%s clocks property should contain 2 handles", __func__);
+        exit(1);
     }
     host_clock_phandles = (uint32_t *)r;
     guest_clock_phandles[0] = qemu_fdt_alloc_phandle(guest_fdt);
-- 
2.17.1

  parent reply	other threads:[~2018-06-29 14:54 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-29 14:52 [Qemu-devel] [PULL 00/55] target-arm queue Peter Maydell
2018-06-29 14:52 ` [Qemu-devel] [PULL 01/55] hw/block/fdc: Replace error_setg(&error_abort) by assert() Peter Maydell
2018-06-29 14:52 ` Peter Maydell [this message]
2018-06-29 14:52 ` [Qemu-devel] [PULL 03/55] device_tree: Replace error_setg(&error_fatal) by error_report() + exit() Peter Maydell
2018-06-29 14:52 ` [Qemu-devel] [PULL 04/55] device_tree: Add qemu_fdt_node_unit_path Peter Maydell
2018-06-29 14:52 ` [Qemu-devel] [PULL 05/55] hw/arm/virt: Silence dtc /intc warnings Peter Maydell
2018-06-29 14:52 ` [Qemu-devel] [PULL 06/55] hw/arm/virt: Silence dtc /memory warning Peter Maydell
2018-06-29 14:52 ` [Qemu-devel] [PULL 07/55] target/arm: Implement SVE Memory Contiguous Load Group Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 08/55] target/arm: Implement SVE Contiguous Load, first-fault and no-fault Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 09/55] target/arm: Implement SVE Memory Contiguous Store Group Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 10/55] target/arm: Implement SVE load and broadcast quadword Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 11/55] target/arm: Implement SVE integer convert to floating-point Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 12/55] target/arm: Implement SVE floating-point arithmetic (predicated) Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 13/55] target/arm: Implement SVE FP Multiply-Add Group Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 14/55] target/arm: Implement SVE Floating Point Accumulating Reduction Group Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 15/55] target/arm: Implement SVE load and broadcast element Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 16/55] target/arm: Implement SVE store vector/predicate register Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 17/55] target/arm: Implement SVE scatter stores Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 18/55] target/arm: Implement SVE prefetches Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 19/55] target/arm: Implement SVE gather loads Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 20/55] target/arm: Implement SVE first-fault " Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 21/55] target/arm: Implement SVE scatter store vector immediate Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 22/55] target/arm: Implement SVE floating-point compare vectors Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 23/55] target/arm: Implement SVE floating-point arithmetic with immediate Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 24/55] target/arm: Implement SVE Floating Point Multiply Indexed Group Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 25/55] target/arm: Implement SVE FP Fast Reduction Group Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 26/55] target/arm: Implement SVE Floating Point Unary Operations - Unpredicated Group Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 27/55] target/arm: Implement SVE FP Compare with Zero Group Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 28/55] target/arm: Implement SVE floating-point trig multiply-add coefficient Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 29/55] target/arm: Implement SVE floating-point convert precision Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 30/55] target/arm: Implement SVE floating-point convert to integer Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 31/55] target/arm: Implement SVE floating-point round to integral value Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 32/55] target/arm: Implement SVE floating-point unary operations Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 33/55] target/arm: Implement SVE MOVPRFX Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 34/55] target/arm: Implement SVE floating-point complex add Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 35/55] target/arm: Implement SVE fp complex multiply add Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 36/55] target/arm: Pass index to AdvSIMD FCMLA (indexed) Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 37/55] target/arm: Implement SVE fp complex multiply add (indexed) Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 38/55] target/arm: Implement SVE dot product (vectors) Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 39/55] target/arm: Implement SVE dot product (indexed) Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 40/55] target/arm: Enable SVE for aarch64-linux-user Peter Maydell
2018-11-12 21:10   ` Laurent Vivier
2018-11-12 22:12     ` Alex Bennée
2018-11-13  9:08       ` Laurent Vivier
2018-11-13  9:49     ` Richard Henderson
2018-11-13  9:57       ` Laurent Vivier
2018-11-13  9:51     ` Richard Henderson
2018-11-13 10:04       ` Laurent Vivier
2018-06-29 14:53 ` [Qemu-devel] [PULL 41/55] target/arm: Implement ARMv8.2-DotProd Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 42/55] target/arm: support reading of CNT[VCT|FRQ]_EL0 from user-space Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 43/55] i.mx7d: Remove unused header files Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 44/55] i.mx7d: Change SRC unimplemented device name from sdma to src Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 45/55] i.mx7d: Change IRQ number type from hwaddr to int Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 46/55] target/arm: Add ARM_FEATURE_V7VE for v7 Virtualization Extensions Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 47/55] target/arm: Remove redundant DIV detection for KVM Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 48/55] target/arm: Mark PMINTENSET accesses as possibly doing IO Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 49/55] sd: Don't trace SDRequest crc field Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 50/55] sdcard: Use the ldst API Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 51/55] target/arm: Fix SVE signed division vs x86 overflow exception Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 52/55] target/arm: Fix SVE system register access checks Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 53/55] target/arm: Prune a57 features from max Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 54/55] target/arm: Prune a15 " Peter Maydell
2018-06-29 14:53 ` [Qemu-devel] [PULL 55/55] target/arm: Add ID_ISAR6 Peter Maydell
2018-06-30 12:33 ` [Qemu-devel] [PULL 00/55] target-arm queue Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180629145347.652-3-peter.maydell@linaro.org \
    --to=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.