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

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


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Alejandro Vallejo <agarciav@xxxxxxx>
  • Date: Tue, 17 Jun 2025 13:07:40 +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=uNYUIHXWtbZjevhX/1UeT4Xuly3MaAkGOlEVEfaYe3w=; b=Xhxdy7gO3FINJ7fx9R7ASoTRmdB2xO8VZyDwFkCZC8RvjH7APVOYJkurZEpRvOXnCToJRx+p520RqHNH0JbIyPduG51KmTEpff4QDHnvSw4xCK84+IOyxVUgABnRBDckceCzCUOXkAijWHRQ1TRULtKtAcy/BUHT141k1NhJsImWcJOt0CcRhB2S1HuDw6bkrG1W7lELcS3DkyRrzgIVvqgG4eLcB1wPZwAoWxk2W7pA30E1QRyfjb56WEcoqY0HyVKjjnyTsaMsloTu6P9hKDSTzCs+h7nQrusYAX5IkF2sCiBm16EayAk7tmBoMNNzTpntAsESkJOOKrXw5SNxcA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=dMvGCeL5li0+J2E3W+rmcwPQTuHi/wRb3GcNNIjbIWxrWGxT8TyKmiuHl478VhOjgSuZ3nKQPdia7/Gf42vxu/OIlWVtQWhzUQMF0o9zmvkakpGjgWLAnoKH4ckqMIjiI04s+OD0HTnCaknb3814tJwqwzJDkDDOcVBSrCcyjZj0Rvpz8IXcSM9buxRq8YV9PT/bE6tC+qK9xk6swfp4fAN7e2E/XJeMsiZimTBX/aqtTtu0/8HxXcH6k3lmN5QZiemI91lsVuOnN5EfpDTVdGVY2BGbeh6X/YrYzmdWJwTA8kDWci0KNSU53jkHA8KZ2UAfALdBfN7GxFhF75rkag==
  • Cc: Alejandro Vallejo <agarciav@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, "Daniel P . Smith " <dpsmith@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Tue, 17 Jun 2025 11:08:27 +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>
---
Based on this suggestion by Daniel:

    
https://lore.kernel.org/xen-devel/a66c11c4-cfac-4934-b1f5-e07c728db8de@xxxxxxxxxxxxxxxxxxxx/

I'd be happier panicking there, seeing how DTs are by their very nature
trusted blobs. But I suspect defaulting to something will find less
resistance in review. I don't care much either way.
---
 xen/include/xen/device_tree.h | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h
index 75017e4266..2daef8659e 100644
--- a/xen/include/xen/device_tree.h
+++ b/xen/include/xen/device_tree.h
@@ -261,10 +261,19 @@ 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]);
+    default:
+        // Nonsensical size. default to 1.
+        printk(XENLOG_WARNING "dt_read_number(%d) bad size", size);
+    };
 
-    while ( size-- )
-        r = (r << 32) | be32_to_cpu(*(cell++));
     return r;
 }
 

base-commit: 14c57887f36937c1deb9eeca852c3a7595d2d0b8
-- 
2.43.0




 


Rackspace

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