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

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


  • To: Michal Orzel <michal.orzel@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Vikram Garhwal <vikram.garhwal@xxxxxxx>
  • Date: Tue, 6 Jun 2023 12:08:05 -0700
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; 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=elbq9BM8aMXeGiCqJfyYwlMljiOFmcpGL/tOAUT+CEw=; b=UuzkMnnVz3SXEn/6omNLwJDoc+sElSu3VGxYX0LW306bdSoYO52P/o96lZF3MDYQJISS/EDdKQEGU9ZQAsplmCPPVmJwlCUwRcU91/b4uVgdJ1FbspBXQ1+/lpcDazKV6BFv9uzniqYCmZ4TCFLMBCjt/GUQRPeE3DJIMmmaIDkIHIas+kjDKp4jX3DjPmg0YoQGXVDncKViaNAKC/ngQplDpLPQzAIY3KeyC3dEnKYI4Le3E+/on8rFrtrj2JJo6M57qT4s48F6nme2nhkkQ0dL6k6VMI9NwN72KbcbA04kQzKEfRrZ/N095FwPjfNqNiJcYwxaK1mVIkzayM8Tjg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iqynDioXzhMBQcZnCuw4HgvQ8/6Ju0SYsp0b+rFGTZ2IHLFImT5pEmgNcWDuwrtAzCrld2IcmC9xesMKVNbR/CgcatPz375FrC6vMlIx5Bve6mulIUDK2yztR9pWo3jOsaFaTl0qV5zgZDj3Un13HxHemiWMBZkNatHentprKgWnyNn3tMMok11hDBqlibdzuByQQE1luPKVLmYMFj2QsmeJ7RnWVt0QYM2UbxtfjmSfyML0pBFU0QNhyWj596Xbs0HsVGaHAlbA+m7QFc2CSxyGAFIe4g6RS43m4DA6kXb14tPTHYuwFP425GcVatxJbzYqzLJFQ3Sq2UWQoYmO4A==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com;
  • Cc: sstabellini@xxxxxxxxxx, jbeulich@xxxxxxxx, Julien Grall <julien@xxxxxxx>
  • Delivery-date: Tue, 06 Jun 2023 19:08:31 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Hi Michal,

On 6/2/23 12:14 AM, Michal Orzel wrote:
Title: s/unflatten_device_tree/__unflatten_device_tree/ or you mean to propagate
errors from unflatten_dt_node?

On 02/06/2023 02:48, Vikram Garhwal wrote:
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: Henry Wang <Henry.Wang@xxxxxxx>
---
  xen/common/device_tree.c | 15 +++++++++++++--
  1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c
index dfdb10e488..117ccccb09 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,19 @@ 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));
+        return -EINVAL;
What about memory that we allocated? Shouldn't it be freed in case of these two 
errors?
For now it is called from boot so we do panic but later in this series this 
could result
in a memory leak. Am I correct?
Yeah, that's correct. Let me add the memory free handling in v8.

+    }
+
      if ( be32_to_cpu(((__be32 *)mem)[size / 4]) != 0xdeadbeef )
-        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]));
+        return -EINVAL;
+    }
+
      *allnextp = NULL;
dt_dprintk(" <- unflatten_device_tree()\n");
~Michal




 


Rackspace

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