[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: Vikram Garhwal <vikram.garhwal@xxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Michal Orzel <michal.orzel@xxxxxxx>
  • Date: Fri, 2 Jun 2023 09:14:27 +0200
  • 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=r6jZ7rt2j6wcQAhRh4qz8ScSit6naE6QBba7jRqA9Ks=; b=KubQn5SsTGmK0JuP3PVuSclRRJoHyix6DZU9xgY6PbvdMaIavlyiMvzs2XEjyowUUmwjiPdEY5SnbTKpVDaUVdSMUynV8clRFjvq9xE/Ht0O5Wza57L/8VcZC3oUrxH6ZsYGE4KFUF0hyfAT9zEpYq5BKRUHMD8qs+wUmQTUX/4R6G85Vo39qW1e91nClcTDFqzUW6h5CBgkWAYTrpguvCr0Fj1RGqFPAAeLFPrHaw+NgxnJcYEysUd5iXG9qGnZ+UV5SM+mXw9Fzlg73q4iNZ5h8SMo+xnveD9whHsISmu1pfjql2MEx3/O8ttAUh6yKeknd+yILRZAz66q1byuvg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YD7SRBTlCfUB7LicxWST+Z0tHtmZzsHxq7id8nzLrcPMk8kqel0N43dKlIaBU6WF8weL+NfBAyHK5Sb6NcbjqmUDnGlVBnrv+ZYXWKgpwXxlFvcF0ArGJpFqjtKZc98MHLmfx6/33f1nKX37Ym2MbNr4FK2u78T161xtV/ijqIGDo3JBcImnQ6BD2cDY5HmshFDr0HikTfsVes+MdwDEli/1n3Lgdep1PnM+V5SNpDBDXnkBVmy9PWniPi7pX2idwiocxnta5nIeKdyyFdso/40DQqwLUjlQNL0BYtM27N0L9IQxAu4XmUL10XXEpV402TQMuswtecxmyaCDvluA9A==
  • Cc: <sstabellini@xxxxxxxxxx>, <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>
  • Delivery-date: Fri, 02 Jun 2023 07:14:41 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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?

> +    }
> +
>      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®.