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

[PATCH v2 4/6] dt-overlay: Support target-path being root node


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Michal Orzel <michal.orzel@xxxxxxx>
  • Date: Fri, 4 Oct 2024 14:22:18 +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 (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=rJLyeaB5M/7YIwM/WFENv9oGD3G+4gjHz/pbXz8yRWs=; b=gxhVCnpZNNyBEmNsXydXPkhHMV19LJkkc0cC5N2KCiO+p5wSW6epJg0cdl0s+J2HtCNz7tOWG27qx3P9QLdMBSE8DM2xBS3/N0pz7E0yQQLo+obskig5UqhdJvSehieRKkNuguu04P9E8ovGSfxPJ5NjSLPMSdZKrtuTu5Cezevk2a7QGTKqC+o3O66UdbXzi41m7fv1K78cFHls+AljWWdM4l8z+zT17V8y2s6aVvYcunMHcUir0Zd1RoxoIVSmJA5S0JLwz+AgDn7di4uyGnMjB5aNlWOyWrXIUwNjZAwK8qwegzkSGy+L32T69AZe6Mzt6hDxpKzNjsj/IM2aNw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=iG6IjzYO9AO3iSWdMkQcIP4fBNpwJMmjxBx2GU/iT7GyCzFUDIYfXjgUBCHGnVti4rEcHzilB/92aR4L6TKUpj/KH9BqTXylzKcezFs01fK3QZ4kyjFHnbLzlEKKMruLtbw6UHY6ShKVsY1rbDv/o3Q4cFKHLZQmBraI6msGfM2/UqDrgLVLpgf50AWdKwOAZbQslWCZW0kPxNLleR3iOQ8/DQSzaeKFZg2+hR7tU0SHc2ztmWbxLOLTeAHKgeb3zd27PgLe+1stEqGKdxkmF4LTmyUqHyU0clqMZni4RUbThcZ81UFbQV151DHqUxYcvlv5fr0orQJ9TmCR8VxaFg==
  • Cc: Michal Orzel <michal.orzel@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>
  • Delivery-date: Fri, 04 Oct 2024 12:22:51 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Even though in most cases device nodes are not present directly under
the root node, it's a perfectly valid configuration (e.g. Qemu virt
machine dtb). At the moment, we don't handle this scenario which leads
to unconditional addition of extra leading '/' in the node full path.
This makes the attempt to add such device overlay to fail.

Signed-off-by: Michal Orzel <michal.orzel@xxxxxxx>
---
Changes in v2:
 - Use ?: instead of implicit bool->int conversion
---
 xen/common/dt-overlay.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/xen/common/dt-overlay.c b/xen/common/dt-overlay.c
index d18bd12bd38d..bfa153250922 100644
--- a/xen/common/dt-overlay.c
+++ b/xen/common/dt-overlay.c
@@ -325,6 +325,7 @@ static int overlay_get_nodes_info(const void *fdto, char 
**nodes_full_path)
             int node_name_len;
             unsigned int target_path_len = strlen(target_path);
             unsigned int node_full_name_len;
+            unsigned int extra_len;
 
             node_name = fdt_get_name(fdto, subnode, &node_name_len);
 
@@ -332,10 +333,13 @@ static int overlay_get_nodes_info(const void *fdto, char 
**nodes_full_path)
                 return node_name_len;
 
             /*
-             * Magic number 2 is for adding '/' and '\0'. This is done to keep
-             * the node_full_path in the correct full node name format.
+             * Extra length is for adding '/' and '\0' unless the target path 
is
+             * root in which case we don't add the '/' at the beginning. This 
is
+             * done to keep the node_full_path in the correct full node name
+             * format.
              */
-            node_full_name_len = target_path_len + node_name_len + 2;
+            extra_len = (target_path_len > 1) ? 2 : 1;
+            node_full_name_len = target_path_len + node_name_len + extra_len;
 
             nodes_full_path[node_num] = xmalloc_bytes(node_full_name_len);
 
@@ -344,9 +348,11 @@ static int overlay_get_nodes_info(const void *fdto, char 
**nodes_full_path)
 
             memcpy(nodes_full_path[node_num], target_path, target_path_len);
 
-            nodes_full_path[node_num][target_path_len] = '/';
+            /* Target is not root - add separator */
+            if ( target_path_len > 1 )
+                nodes_full_path[node_num][target_path_len++] = '/';
 
-            memcpy(nodes_full_path[node_num] + target_path_len + 1,
+            memcpy(nodes_full_path[node_num] + target_path_len,
                     node_name, node_name_len);
 
             nodes_full_path[node_num][node_full_name_len - 1] = '\0';
-- 
2.25.1




 


Rackspace

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