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

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


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Vikram Garhwal <vikram.garhwal@xxxxxxx>
  • Date: Thu, 31 Aug 2023 21:59:29 -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=cro8idbWK6/j9Apeo95KJGwjFsR6k97QUgTNDxCH+H8=; b=XLlDgpRWF3Wx5s+0rQY1Z6Bj8ImZaVj1ic5goFQ2666XbARlznpBZun9TUyFE4Y6/C9earruSe32CQnXoiuxe8Q9yFU4Dubb5DvUjJuqSruJl6evCWnVMieE2jRthoNgVBfSo5ZWCPsIdSM2MjlEAAsTBqBQoSNypzJ1pBiyvPs39WGX4nh2tEfp2+rkGCG9GGp66sJOATdhb7NDQ4pMBmGNBxx05LMk6xyN/LYrBL+OfkiSriOkp15A9+6z4JEBw6Nk8dlDUDc2xR/ECwkrJfG9nnH+vvb1EN57GN9rlofZ/TFgy1WYTXMVHGk9PEwTwPROeJ74rNI+dKyEzm8ZDQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cxtIzzVeUDUjkTHCNTKOPrS4P+7I1RAtfBIkHmElRsSicW1JcoIKnQVajirH6i5FWcliRVf2jEmnEk3M58j00FWMjppggT6vI59yvhZQxuzXJwMRtMh6Ql9tmoJrXtDSEyq04QGUBouP/Clb4bx+I6wEgkbNSfPZGrn+2lh8eTEVqsFVN7Td8z2lXBZEbtTgml674qjtdVIlDyfgRddSkCbMl/WZhh/8JMbOoTW4lf+tANmhtpW2V2/7Mp3tlFLtCx04UgOGVsMiTJf898w+Thb0PpK8q2NDwQHfTJ5tK/PSWVwJmGx1yFdG1DqryRBcSkiZTYs+ZcT9DEqB7xEy9Q==
  • Cc: <vikram.garhwal@xxxxxxx>, <julien@xxxxxxx>, <michal.orzel@xxxxxxx>, <sstabellini@xxxxxxxxxx>
  • Delivery-date: Fri, 01 Sep 2023 05:00:14 +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>
Reviewed-by: Michal Orzel <michal.orzel@xxxxxxx>
Acked-by: Stefano Stabellini <sstabellini@xxxxxxxxxx>

---
Changes from v9:
    Replace __be64 with void.
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 7c6b41c3b4..b6d9f018c6 100644
--- a/xen/common/device_tree.c
+++ b/xen/common/device_tree.c
@@ -2110,6 +2110,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);
@@ -2127,11 +2130,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((void *)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((void *)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®.