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

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


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Vikram Garhwal <vikram.garhwal@xxxxxxx>
  • Date: Wed, 16 Aug 2023 17:39: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=OnAkiyK51E8/9hbpYvNOl4Id3yZ+E95/wfBvKWMf7tM=; b=c/GWQZSVwjrUABqCorwLgvNh1Zd2MhHcfeW2yX9mK4Guor2D6UH5ylt8lql1jntXjKP4dCSQDSjVHq2CEr2jWqEYt6/qs2eGYS+FU6Yo1CyAYTrhKAKq0SKC6fnAuRzB6iaSWAbae6nb2yLiUB2F5ZLrJzbpB7zFArJHJijhnX58KkWEtXmuNlBSLPziZZR4frdWdsx6yjwg2UY2kX3890IYZiHx6SV//4XuyjSkdUddyVGxxaBIN6VSYYUWVOXjNCBXsrYF1q4q00T4Ir7zPY+YsTJHYSbciMA/42+zWdff+Im8bnDFsDqM575Bukje/zZn1t97hjS35Bh1Sduh5w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h6OPvYaVjUlHMn+GZEX3Iei4gYKFoXzi02+bDj4TDStNneoavNHrEjNn/EyOcbQAOmo0wuMiSOQTdT++kas3I1e7d/w+RqV7EXRjbCAR4gTbTgmv5Fn6GCKVsX8YDzf4Uu1w3M0cb4nWuzACBVpPcJZfu3MxjWJF69YeyZSkfXqhrhPI1VyCLqHkqyVFb9jtQmT9m5l7rU0MFhW/qvyrrzI7WwY9SwsJapS0UqCIaAdVgmYNfxSCfm/WODpk9aDLX7oQ5FMzuaCpaU/hI3aJILSG4w9VQhUpr7KwvF9g2isaZt7bAEDnr//PzmySXtjbwvGLiuH1lOm+3+7DoqGCKQ==
  • Cc: <michal.orzel@xxxxxxx>, <sstabellini@xxxxxxxxxx>, <vikram.garhwal@xxxxxxx>, Julien Grall <julien@xxxxxxx>
  • Delivery-date: Thu, 17 Aug 2023 00:40:11 +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.

Fixes: fb97eb614acf ("xen/arm: Create a hierarchical device tree")
Signed-off-by: Vikram Garhwal <vikram.garhwal@xxxxxxx>
Reviewed-by: Henry Wang <Henry.Wang@xxxxxxx>
Reviewed-by: Michal Orzel <michal.orzel@xxxxxxx>
Acked-by: Julien Grall <jgrall@xxxxxxxxxx>
---
 xen/common/device_tree.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c
index 0522fdf976..c91d54c493 100644
--- a/xen/common/device_tree.c
+++ b/xen/common/device_tree.c
@@ -2092,8 +2092,8 @@ static unsigned long __init 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;
@@ -2114,6 +2114,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(0xdeadbeefU);
 
@@ -2131,6 +2133,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,
@@ -2215,7 +2219,11 @@ 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®.