From nobody Wed Feb 11 01:09:32 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1529946031980408.8351209195595; Mon, 25 Jun 2018 10:00:31 -0700 (PDT) Received: from localhost ([::1]:48339 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXUqt-0001QL-3D for importer@patchew.org; Mon, 25 Jun 2018 13:00:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38846) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXUoX-000067-U0 for qemu-devel@nongnu.org; Mon, 25 Jun 2018 12:58:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fXUoW-00070r-S8 for qemu-devel@nongnu.org; Mon, 25 Jun 2018 12:58:06 -0400 Received: from mail-qt0-x241.google.com ([2607:f8b0:400d:c0d::241]:39736) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fXUoW-000704-Le; Mon, 25 Jun 2018 12:58:04 -0400 Received: by mail-qt0-x241.google.com with SMTP id c23-v6so3650516qtn.6; Mon, 25 Jun 2018 09:58:04 -0700 (PDT) Received: from x1.local ([138.117.48.222]) by smtp.gmail.com with ESMTPSA id k129-v6sm9856727qkd.13.2018.06.25.09.58.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Jun 2018 09:58:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QeiPeokwUFZUcy7BROEsIlLnHLSoIbcdBHGtjnvFluU=; b=vJ0uuW1wddgq6lL90MWiaPmHG0Y5h4KEdc2RVncEazhSt0ydWNLrYBZdN6KSojKAeJ XlcGpeuL+XbeeD9X4PHAvcTDmtnQkPe2/Af+OwEI5nhTvUHHgrJicL51t57dG1eFtdGM 6HFGvHDcLtJVexfSA8yqb2tKWTSN1IliXrPWh6PqDEszeS931pUzhlxGowYr0mjrbKfu uHAnH9kz0+9GHep+Gmue+nGoyoCtMMnxR4b7BjyzFfDWtu2aOlA9yOb7uSriXVkI9ZCC h0AGQNVJ72/B4v+qZ6GpCIjKmvKoTi6GAXXJ3vPII6brk16JwnHbLvQTz9JIeBGLgeOP Ercg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=QeiPeokwUFZUcy7BROEsIlLnHLSoIbcdBHGtjnvFluU=; b=Qeq2nTDUqVbEB0YZidePxsAVUyEIxmO9VoxaajonmWLzDxKTIu5/imh7+xcsJruUfZ HAtyr484y7HPT2sm1vaXR/emTEnJhjbP5Bo+DHjwbSA0BcHtIVErd7D1kSvBtF7cqvUh loXaH41GqzxnovKGbgsm6mFgTow7tuwiVkgkJqt+AzOHK7FJP8CrI8SUhXA/7qfJu9nn ZNsK8VpT3vy+mou8DEdkhpqdfPWh9nAo3uA82zoRVtmYtLnCerZ+R/r7KgrvIZZVrKTg mnj9sLU/gjahx3C6pHEs/BJ9YA6iP4Reby76Q4DFknlPz5hyeYtItJIJB+Pw1v1HKmGX SDQw== X-Gm-Message-State: APt69E0MywynOAWu+le+5y8jtI+h9/I5QdHsVxy7XC+Xtbm9InpGaWTl cOwNG1aprQoYR/qrFZ7ccuY= X-Google-Smtp-Source: AAOMgpd3Hl+QQlaYsNlih9Td7f0aW6gPZ7Ge3qAd0kAyIb7ZqW+TIOuwJQH6HCjAkXVdBWncTibqzQ== X-Received: by 2002:a0c:ada5:: with SMTP id w34-v6mr11906299qvc.58.1529945883724; Mon, 25 Jun 2018 09:58:03 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Auger Eric , Markus Armbruster , Peter Maydell Date: Mon, 25 Jun 2018 13:57:48 -0300 Message-Id: <20180625165749.3910-3-f4bug@amsat.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180625165749.3910-1-f4bug@amsat.org> References: <20180625165749.3910-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::241 Subject: [Qemu-devel] [PATCH v4 2/3] hw/arm/sysbus-fdt: Replace error_setg(&error_fatal) by error_report() + exit() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "open list:ARM" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 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_p= ath') results in a null pointer dereference if (node_path[1]) { ^~~~~~~~~~~~ Fixes: Coverity CID 1352173 (Dereference after null check) Suggested-by: Eric Blake Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Eric Auger --- v3: display error if property required and returned -FDT_ERR_NOTFOUND 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 277ed872e7..0d4c75702c 100644 --- a/hw/arm/sysbus-fdt.c +++ b/hw/arm/sysbus-fdt.c @@ -92,16 +92,20 @@ static void copy_properties_from_host(HostProperty *pro= ps, int nb_props, r =3D 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 !=3D -FDT_ERR_NOTFOUND) { - /* optional property not returned although property exists= */ - error_report_err(err); - } else { + if (props[i].optional && prop_len =3D=3D -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, =20 node_offset =3D fdt_node_offset_by_phandle(host_fdt, host_phandle); if (node_offset <=3D 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 tr= ee", + host_phandle); + exit(1); } node_path =3D g_malloc(path_len); while ((ret =3D fdt_get_path(host_fdt, node_offset, node_path, path_le= n)) @@ -149,16 +153,16 @@ static void fdt_build_clock_node(void *host_fdt, void= *guest_fdt, node_path =3D 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); } =20 r =3D 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); } =20 nodename =3D strrchr(node_path, '/'); @@ -301,34 +305,37 @@ static int add_amd_xgbe_fdt_node(SysBusDevice *sbdev,= void *opaque) =20 dt_name =3D 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 =3D 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); } =20 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); } =20 g_free(dt_name); =20 if (vbasedev->num_regions !=3D 5) { - error_setg(&error_fatal, "%s Does the host dt node combine XGBE/PH= Y?", - __func__); + error_report("%s Does the host dt node combine XGBE/PHY?", __func_= _); + exit(1); } =20 /* generate nodes for DMA_CLK and PTP_CLK */ r =3D qemu_fdt_getprop(host_fdt, node_path[0], "clocks", &prop_len, &error_fatal); if (prop_len !=3D 8) { - error_setg(&error_fatal, "%s clocks property should contain 2 hand= les", - __func__); + error_report("%s clocks property should contain 2 handles", __func= __); + exit(1); } host_clock_phandles =3D (uint32_t *)r; guest_clock_phandles[0] =3D qemu_fdt_alloc_phandle(guest_fdt); --=20 2.18.0