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

[XEN][PATCH v6 02/19] common/device_tree: handle memory allocation failure in __unflatten_device_tree()


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Vikram Garhwal <vikram.garhwal@xxxxxxx>
  • Date: Tue, 2 May 2023 16:36: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=vzddX9TV10ndAd/6iE6kCNK/WBOdnTL0B9KxpRRHgRI=; b=j3fsZJ9IS3+TAhj6342U+O5MPJm3D1bTxoachuuFo/r8ed1CYRt4rNRKAn9gD9n0krpTmCoebLydEExor4KfOcxoANBbt3fUieHqEAKR1t0CTUoqzdF80prbHe7a1Txqvz1yGL5JOBlgNKdtAlH1JdFggaU8Fdj3KgGz/OF6ulbE6PMMgPqiVGLQWlcYGv/zOj/KKcwimlVJL+oerHgfQ6rFa5k2ghnpXwHbkoZ80NmtxpJBKJIl2oICsPg0FtlN2TFxS2wgA9bbwe8KB50uqY4ZjyWMxxYOO7DPeZyurt/2WWGFzVwL5Maw0kDemxiYUKBl+FwoL7De839WZvrX1A==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U+Jo3aZ/KXfCpID5n2MqwuEg+k/PJWPStk/V7ThEjUdZSxD2n071o+4GiDyi7VQShAVY17IRY7Ygfy2XcBUTIEmJs0AUzAi+Fnktq7MGgARIkko7gEphpqHdWdZ7OE5/VhUK5LRMpnQThG34+rszzv/22fhLnNqzN/+7Pzldq0Muno6B553aa2LvDjmv+IBqyBfCl1PXWMUSqtZY3aOdnS+XotN2TdwdmXXCQ2A+k+3iQcdjgBfnmrm5B4A8n5GKu4s9i6HkjlKMgjDyfb/Jtd6wB+TFceuEhm7elEcPXrJS+G9ICJovNLTohBfS4myaVSYHLTJGDl1hj6QSAnh5jw==
  • Cc: <sstabellini@xxxxxxxxxx>, <vikram.garhwal@xxxxxxx>, <michal.orzel@xxxxxxx>, Julien Grall <julien@xxxxxxx>
  • Delivery-date: Tue, 02 May 2023 23:37:41 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Change __unflatten_device_tree() return type to integer so it can propagate
memory allocation failure. Add panic() in dt_unflatten_host_device_tree() for
memory allocation failure during boot.

Signed-off-by: Vikram Garhwal <vikram.garhwal@xxxxxxx>
---
 xen/common/device_tree.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c
index 5f7ae45304..fc38a0b3dd 100644
--- a/xen/common/device_tree.c
+++ b/xen/common/device_tree.c
@@ -2056,8 +2056,8 @@ static unsigned long unflatten_dt_node(const void *fdt,
  * @fdt: The fdt to expand
  * @mynodes: The device_node tree created by the call
  */
-static void __init __unflatten_device_tree(const void *fdt,
-                                           struct dt_device_node **mynodes)
+static int __init __unflatten_device_tree(const void *fdt,
+                                          struct dt_device_node **mynodes)
 {
     unsigned long start, mem, size;
     struct dt_device_node **allnextp = mynodes;
@@ -2078,6 +2078,8 @@ static void __init __unflatten_device_tree(const void 
*fdt,
 
     /* Allocate memory for the expanded device tree */
     mem = (unsigned long)_xmalloc (size + 4, __alignof__(struct 
dt_device_node));
+    if ( !mem )
+        return -ENOMEM;
 
     ((__be32 *)mem)[size / 4] = cpu_to_be32(0xdeadbeef);
 
@@ -2095,6 +2097,8 @@ static void __init __unflatten_device_tree(const void 
*fdt,
     *allnextp = NULL;
 
     dt_dprintk(" <- unflatten_device_tree()\n");
+
+    return 0;
 }
 
 static void dt_alias_add(struct dt_alias_prop *ap,
@@ -2179,7 +2183,10 @@ dt_find_interrupt_controller(const struct 
dt_device_match *matches)
 
 void __init dt_unflatten_host_device_tree(void)
 {
-    __unflatten_device_tree(device_tree_flattened, &dt_host);
+    int error = __unflatten_device_tree(device_tree_flattened, &dt_host);
+    if ( error )
+        panic("__unflatten_device_tree failed with error %d\n", error);
+
     dt_alias_scan();
 }
 
-- 
2.17.1




 


Rackspace

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