xen/dt: Remove loop in dt_read_number()

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@apertussolutions.com>
Signed-off-by: Alejandro Vallejo <agarciav@amd.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
This commit is contained in:
Alejandro Vallejo authored and Stefano Stabellini committed 2025-06-20 17:47:31 -07:00
1 parent 12d72d032e
commit c65ff27d71
1 file changed
+15 -3
+15 -3
View File
@@ -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;
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.