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

[PATCH v2 5/6] dt-overlay: Ignore nodes that do not have __overlay__ as their subnode


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Michal Orzel <michal.orzel@xxxxxxx>
  • Date: Fri, 4 Oct 2024 14:22:19 +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=3coa7/Q00XcmaWZs7n/oiZYQzKwgScWsvnM72TeQSnY=; b=PgABqA59YjClm1v6vFW9bg/zDJd8e+htlibpbR3WLNq24vnC5ok5wOPuUU7crQ/Zx1ZP6Fk6SRHQ/CIGFI687giyfIcD2lJBIFlHo0CuQ8dNHTtrMKsZ1Eo9AGH0GtmtjIQyAnqELMGbaCFk2e2kclip0mans65qrXQQI7I+rYGMQwP8NuUttK1YNZNcUGn4dVUPudCnpT5brM2ywV2ZbkC3TOoxMxisv8gdefVEuWNFDvGheGQdP1hJGXzIU/6f40U9LPnQF8j8dTF/Y0W8VBz9k4BGgGdJx39KPESByrqrLZMZOLkxI1oKk2STT2lHbI46krZ+DjofOXugjAKHzA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=oLEncfoH8xaSWzO7h/E+0tPRLcqlcBRxUIXkZZgUF2RgePyqZVvBPBbT4UfS221bZAT6IjiQTMIqaN9sEZiGp+f+SL8zv+8jA2zddWTNomBQcpzI3+EgUsoyvOWJqtM/8k592zy4qwRwdB7FfHDjtVjp2Qy3ENyn2gkivPHHZVeQogs0z2vc25sMG13GGXKOjzmlpfzNrdUgMOetzkeJ7n2ehZpjY1SqGEeSC/PVMA+wm7UZTjrj0KI65W4MMorEgNRqnJzoxJqm7vfYQaCgyyC2/E6U9DUlS18LT1DT4c309xtMm0ChSlmq9OReQWx25mUCSCQSzzHXDD4KDZ2jxA==
  • 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>

Assumption stated in the comments as if fdt_for_each_subnode() checks
for parent < 0 is utterly wrong. If parent is < 0, node offset is set to
0 (i.e. the very first node in the tree) and the loop's body is executed.
This incorrect assumption causes overlay_node_count() to also count nodes
that do not have __overlay__ as their subnode. The same story goes for
overlay_get_nodes_info(), where we end up requiring each node directly
under root node to have "target-path" set. DTBOs can specify other nodes
including special ones like __symbols__, __fixups__ that can be left to
reduce the number of steps a user needs to do to when it comes to invalid
phandles.

Fix it by adding checks if overlay < 0 after respective calls to
fdt_subnode_offset().

Signed-off-by: Michal Orzel <michal.orzel@xxxxxxx>
---
Changes in v2:
 - New patch
---
 xen/common/dt-overlay.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/xen/common/dt-overlay.c b/xen/common/dt-overlay.c
index bfa153250922..4d75b5b36a99 100644
--- a/xen/common/dt-overlay.c
+++ b/xen/common/dt-overlay.c
@@ -274,11 +274,9 @@ static unsigned int overlay_node_count(const void 
*overlay_fdt)
         int overlay;
 
         overlay = fdt_subnode_offset(overlay_fdt, fragment, "__overlay__");
+        if ( overlay < 0 )
+            continue;
 
-        /*
-         * overlay value can be < 0. But fdt_for_each_subnode() loop checks for
-         * overlay >= 0. So, no need for a overlay>=0 check here.
-         */
         fdt_for_each_subnode(subnode, overlay_fdt, overlay)
         {
             num_overlay_nodes++;
@@ -305,6 +303,10 @@ static int overlay_get_nodes_info(const void *fdto, char 
**nodes_full_path)
         int subnode;
         const char *target_path;
 
+        overlay = fdt_subnode_offset(fdto, fragment, "__overlay__");
+        if ( overlay < 0 )
+            continue;
+
         target = fdt_overlay_target_offset(device_tree_flattened, fdto,
                                            fragment, &target_path);
         if ( target < 0 )
@@ -313,12 +315,6 @@ static int overlay_get_nodes_info(const void *fdto, char 
**nodes_full_path)
         if ( target_path == NULL )
             return -EINVAL;
 
-        overlay = fdt_subnode_offset(fdto, fragment, "__overlay__");
-
-        /*
-         * overlay value can be < 0. But fdt_for_each_subnode() loop checks for
-         * overlay >= 0. So, no need for a overlay>=0 check here.
-         */
         fdt_for_each_subnode(subnode, fdto, overlay)
         {
             const char *node_name = NULL;
-- 
2.25.1




 


Rackspace

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