]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
net: Stop conflating return value with file size in net_loop()
authorYuya Hamamachi <yuya.hamamachi.sx@renesas.com>
Thu, 29 Jan 2026 22:30:18 +0000 (23:30 +0100)
committerJerome Forissier <jerome.forissier@arm.com>
Fri, 6 Feb 2026 15:37:31 +0000 (16:37 +0100)
The net_loop() currently conflates return value with file size
at the end of successful transfer, in NETLOOP_SUCCESS state.

The return type of net_loop() is int, which makes this practice
workable for file sizes below 2 GiB, but anything above that will
lead to overflow and bogus negative return value from net_loop().

The return file size is only used by a few sites in the code base,
which can be easily fixed. Change the net_loop() return value to
always be only a return code, in case of error the returned value
is the error code, in case of successful transfer the value is 0
or 1 instead of 0 or net_boot_file_size . This surely always fits
into a signed integer.

By keeping the return code 0 or 1 in case of successful transfer,
no conditionals which depended on the old behavior are broken, but
all the sites had to be inspected and updated accordingly.

Fix the few sites which depend on the file size by making them
directly use the net_boot_file_size variable value. This variable
is accessible to all of those sites already, because they all
include net-common.h .

Signed-off-by: Yuya Hamamachi <yuya.hamamachi.sx@renesas.com>
Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
cmd/mvebu/bubt.c
cmd/net.c
common/update.c
net/net.c

index 2755c26cdf7339470bfdea6de95b753c8439cf40..f8e97d0392079053fd3c6dc8bfcd190c4349d68d 100644 (file)
@@ -661,7 +661,7 @@ static size_t tftp_read_file(const char *file_name)
         */
        image_load_addr = get_load_addr();
        ret = net_loop(TFTPGET);
-       return ret > 0 ? ret : 0;
+       return ret > 0 ? net_boot_file_size : 0;
 }
 
 static int is_tftp_active(void)
index 24099764493ed326bfe0140933dee308c5cc9414..f6f556f36ae7a24fb74023e0f37630304cda772c 100644 (file)
--- a/cmd/net.c
+++ b/cmd/net.c
@@ -354,8 +354,8 @@ static int netboot_common(enum proto_t proto, struct cmd_tbl *cmdtp, int argc,
                          char *const argv[])
 {
        char *s;
-       int   rcode = 0;
-       int   size;
+       int rcode;
+       u32 size;
 
        net_boot_file_name_explicit = false;
        *net_boot_file_name = '\0';
@@ -396,8 +396,9 @@ static int netboot_common(enum proto_t proto, struct cmd_tbl *cmdtp, int argc,
                }
        }
 
-       size = net_loop(proto);
-       if (size < 0) {
+       rcode = net_loop(proto);
+       size = net_boot_file_size;
+       if (rcode < 0) {
                bootstage_error(BOOTSTAGE_ID_NET_NETLOOP_OK);
                return CMD_RET_FAILURE;
        }
index 6801b49479d6a8e8831ba30b37e9edcbd73a48ac..0bafffede9e7560c4d94068f787522940794059d 100644 (file)
@@ -32,7 +32,7 @@ static uchar *saved_prot_info;
 #endif
 static int update_load(char *filename, ulong msec_max, int cnt_max, ulong addr)
 {
-       int size, rv;
+       int rv;
        ulong saved_timeout_msecs;
        int saved_timeout_count;
        char *saved_netretry, *saved_bootfile;
@@ -54,12 +54,12 @@ static int update_load(char *filename, ulong msec_max, int cnt_max, ulong addr)
        /* download the update file */
        image_load_addr = addr;
        copy_filename(net_boot_file_name, filename, sizeof(net_boot_file_name));
-       size = net_loop(TFTPGET);
+       rv = net_loop(TFTPGET);
 
-       if (size < 0)
+       if (rv < 0)
                rv = 1;
-       else if (size > 0)
-               flush_cache(addr, size);
+       else
+               flush_cache(addr, net_boot_file_size);
 
        /* restore changed globals and env variable */
        tftp_timeout_ms = saved_timeout_msecs;
index 8a8160e633f6a4d524712701c5d89730267b087b..ae3b977781ff8b6cc5b772f09f6b7a00a3383472 100644 (file)
--- a/net/net.c
+++ b/net/net.c
@@ -692,7 +692,7 @@ restart:
 
                        eth_set_last_protocol(protocol);
 
-                       ret = net_boot_file_size;
+                       ret = !!net_boot_file_size;
                        debug_cond(DEBUG_INT_STATE, "--- net_loop Success!\n");
                        goto done;