[PATCH] iomem: Adjust address width for 64-bit addresses

From: Lingxiang Zheng
Date: Thu May 11 2023 - 12:28:23 EST


Modify the address width determination in /proc/iomem output to better
handle 64-bit addresses. The previous implementation did not correctly
account for 64-bit address space, as it would limit the address width to 8
hexadecimal characters. This change adjusts the address width according to
the following conditions:

1. If the resource's end address is less than 0x10000, set the width to 4.
2. If the resource's end address is greater than 0xFFFFFFFF, set the width to 16.
3. For other cases, set the width to 8.

Signed-off-by: Lingxiang Zheng <lxzheng@xxxxxxxxx>
---
kernel/resource.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/resource.c b/kernel/resource.c
index b1763b2fd7ef..d8f977d628f5 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -110,7 +110,7 @@ static int r_show(struct seq_file *m, void *v)
struct resource *root = pde_data(file_inode(m->file));
struct resource *r = v, *p;
unsigned long long start, end;
- int width = root->end < 0x10000 ? 4 : 8;
+ int width = root->end < 0x10000 ? 4 : root->end > 0xFFFFFFFF ? 16 : 8;
int depth;

for (depth = 0, p = r; depth < MAX_IORES_LEVEL; depth++, p = p->parent)
--
2.17.1