Storage capacities above 4 GiB are truncated when stored in size_t
on 32-bit systems. Use a 64-bit accumulator and promote the block
count before multiplication so 32-bit LBA configurations are also
handled correctly.

Fixes: 86d462c05d57 ("cmd: add a fetch utility")

Signed-off-by: Han Gao <[email protected]>
---
 cmd/ufetch.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cmd/ufetch.c b/cmd/ufetch.c
index d4b54f77b7b2..29ccbf654a4e 100644
--- a/cmd/ufetch.c
+++ b/cmd/ufetch.c
@@ -95,7 +95,7 @@ static int do_ufetch(struct cmd_tbl *cmdtp, int flag, int 
argc,
        const char *model, *compatible;
        char *ipaddr;
        int n_cmds, n_cpus = 0, compatlen;
-       size_t size = 0;
+       u64 size = 0;
        ofnode np;
        bool skip_ascii = false;
 
@@ -221,7 +221,7 @@ static int do_ufetch(struct cmd_tbl *cmdtp, int flag, int 
argc,
                        ret = uclass_find_device_by_seq(UCLASS_BLK, line - 
STORAGE, &dev);
                        if (!ret && dev) {
                                desc = dev_get_uclass_plat(dev);
-                               size = desc->lba * desc->blksz;
+                               size = (u64)desc->lba * desc->blksz;
                                printf("%4s %d: " RESET, 
blk_get_uclass_name(desc->uclass_id),
                                        desc->lun);
                                if (size)

---
base-commit: 211de43d0f954a00a490220c1aac9db298287c40
change-id: 20260919-fixfetch-d7aa5b94d9b7

Best regards,
--  
Han Gao <[email protected]>

Reply via email to