[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[XEN][PATCH v9 02/19] common/device_tree.c: unflatten_device_tree() propagate errors


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Vikram Garhwal <vikram.garhwal@xxxxxxx>
  • Date: Fri, 18 Aug 2023 17:28:33 -0700
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=zNJuXj7ZBUQRHz29zlrzeHOa0+tHLK1DzkscWEXkjVw=; b=KDk+B6DFnG+U9VbQehjedPFB5g9ME/Hb4vGgWIffyZG/aTDoGJKaIDqE40nOuevEV5ZZvobnx1EmEL0t5FtANz5az6jMeFDLSxH2pDKIC/fGEcC+wqlKFC6J1+t87N7Jz6fDsGsS/RtCzp+d0paPbBf6Tkkrz4qCBC9WwgiGLyTxFjJ/BWBQUubQY6QG34QDHRiy21Jhp1bFp9yTzAzIC/ATu+n5PfWoePkfT9sT1AUQslD7PXem+Sms8xLj5H0np9Mh6hYbasGan116vkKyp3DtBeQxK73cI7bjEO4dc4FWerKCNr3jjYFZjZes0Cym1Myw5NYthPpcilfZFjC4pw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jbFpBghYRnJUKXtI3ClucqSvq2ZgMXiIlXOyOiAtWBQPlic/LuB/MVNdEL+EoDPe8j6YDQu4fA4Ao89yTLxdGU2zv0LkI1AtWTryjdmBgLi7BKoW+CPqsvmTuJZ8vLrVFtng97grhNj//HrD47OdZ4mESLlZvb6c7xOM5MVkadK7N8NKApgHmhQcF99pmkAR0FVEJJsCT/f8hzhWep7hutJoEOxbNmxQEwfegVVhJzTIDVnYBqrv9CtBdGsu0okfwohSKA7l8+PdyXJQcXZZrabxwWTI19MFSvRH2Wq9zANjoTbYThwXRIepOIiYZQd2phz3duBHec6Wwg93yTIXZA==
  • Cc: <michal.orzel@xxxxxxx>, <sstabellini@xxxxxxxxxx>, <vikram.garhwal@xxxxxxx>, <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>
  • Delivery-date: Sat, 19 Aug 2023 00:29:19 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

This will be useful in dynamic node programming when new dt nodes are unflattend
during runtime. Invalid device tree node related errors should be propagated
back to the caller.

Signed-off-by: Vikram Garhwal <vikram.garhwal@xxxxxxx>

---
Changes from v7:
    Free allocated memory in case of errors when calling unflatten_dt_node.
---
---
 xen/common/device_tree.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c
index c91d54c493..cd9a6a5c93 100644
--- a/xen/common/device_tree.c
+++ b/xen/common/device_tree.c
@@ -2108,6 +2108,9 @@ static int __init __unflatten_device_tree(const void *fdt,
     /* First pass, scan for size */
     start = ((unsigned long)fdt) + fdt_off_dt_struct(fdt);
     size = unflatten_dt_node(fdt, 0, &start, NULL, NULL, 0);
+    if ( !size )
+        return -EINVAL;
+
     size = (size | 3) + 1;
 
     dt_dprintk("  size is %#lx allocating...\n", size);
@@ -2125,11 +2128,21 @@ static int __init __unflatten_device_tree(const void 
*fdt,
     start = ((unsigned long)fdt) + fdt_off_dt_struct(fdt);
     unflatten_dt_node(fdt, mem, &start, NULL, &allnextp, 0);
     if ( be32_to_cpup((__be32 *)start) != FDT_END )
-        printk(XENLOG_WARNING "Weird tag at end of tree: %08x\n",
+    {
+        printk(XENLOG_ERR "Weird tag at end of tree: %08x\n",
                   *((u32 *)start));
+        xfree((__be64 *)mem);
+        return -EINVAL;
+    }
+
     if ( be32_to_cpu(((__be32 *)mem)[size / 4]) != 0xdeadbeefU )
-        printk(XENLOG_WARNING "End of tree marker overwritten: %08x\n",
+    {
+        printk(XENLOG_ERR "End of tree marker overwritten: %08x\n",
                   be32_to_cpu(((__be32 *)mem)[size / 4]));
+        xfree((__be64 *)mem);
+        return -EINVAL;
+    }
+
     *allnextp = NULL;
 
     dt_dprintk(" <- unflatten_device_tree()\n");
-- 
2.17.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.