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

[PATCH v3] xen/dt: Remove loop in dt_read_number()


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Alejandro Vallejo <agarciav@xxxxxxx>
  • Date: Thu, 19 Jun 2025 13:42:04 +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=dR665VFbvpwICSNfqh1RtfMKzGOK1awE1bBpdQm4HdA=; b=XoRdmHTRMrmoxGYfgZViBtspdAoiSYZv5s32PHrpo9h6/S49kKPSKt507s2l7LxCyF2eceyYXzgRIHqdD3kTheqseujUqXW9/N1oCbCVvAp6Q76oPvgKMWPACYpa/TgbhFNH+roryZYHf8IU5kqVmVcpvLdVH12dPGSZiSAOqknZ9PEnPe4xEkh8YASV1WuuZTwXXkp7XjvCco3zgPMVL/T2Zlm3hWlUeyLg7d/HRSHycrn0RfoDAXNMA7qgwuUl2O2nFjdC9ApQPU7ba/LnIozfySBvDyOrMUHj69ZQWii77vBufNepperPZtdEIqxSy8tuaMoGIQQp/jtZNGhzIg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=evNbsyADLA/XXN8TreMBZFMBMxpBxPwSRQJK6zSTzgtovQrQKDwCAV8T4ojmN0BQk7+AcRTY2LB3c0WIp5AcPYEbPYMGtkHl1pxFrEwPPEDEpE6zv7dYK+aVJcmT9MHJ0eAy8s1pquG7w71rKPwSzhDNWCSyh8fkpHtcjiGl2+thLpZeG8N4ID30xI51wKyvADj/tLaEt78xezx8ibsqK81NfspvkjLHu+V3yXIkN924+Z5F+GcNAzw3dHU1+3cnBy62dSHmULtHySpwTLSHaYDtXfVudS06dI0Zwu2speCmEhuvx7vhWp0PDfnIXJ3IOdtGjQX3kdBdHqVvURZDGg==
  • Cc: Alejandro Vallejo <agarciav@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>
  • Delivery-date: Thu, 19 Jun 2025 11:42:37 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

The DT spec declares only two number types for a property: u32 and u64,
as per Table 2.3 in Section 2.2.4. Remove unbounded loop and replace
with a switch statement. Default to a size of 1 cell in the nonsensical
size case, with a warning printed on the Xen console.

Suggested-by: Daniel P. Smith" <dpsmith@xxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Alejandro Vallejo <agarciav@xxxxxxx>
---
If there's any #address-size > 2 out there at least we'll know in debug builds.
It's not like this function can cope with them either way.

I haven't tested things past CI.

pipeline: 
https://gitlab.com/xen-project/people/agvallejo/xen/-/pipelines/1876848415

v3:
  * s/WARNING/ERR
  * //-style comment to /**/-style comment
  * break after ASSERT_UNREACHABLE() to please MISRA
---
 xen/include/xen/device_tree.h | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h
index 75017e4266..d2de7c3a13 100644
--- a/xen/include/xen/device_tree.h
+++ b/xen/include/xen/device_tree.h
@@ -261,10 +261,22 @@ void intc_dt_preinit(void);
 /* Helper to read a big number; size is in cells (not bytes) */
 static inline u64 dt_read_number(const __be32 *cell, int size)
 {
-    u64 r = 0;
+    u64 r = be32_to_cpu(*cell);
+
+    switch ( size )
+    {
+    case 1:
+        break;
+    case 2:
+        r = (r << 32) | be32_to_cpu(cell[1]);
+        break;
+    default:
+        /* Nonsensical size. default to 1 */
+        printk(XENLOG_ERR "dt_read_number(,%d) bad size\n", size);
+        ASSERT_UNREACHABLE();
+        break;
+    };
 
-    while ( size-- )
-        r = (r << 32) | be32_to_cpu(*(cell++));
     return r;
 }
 

base-commit: 22650d6054625be10172fe0c78b9cadd1a39bd63
-- 
2.43.0




 


Rackspace

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