"Das U-Boot" Source Tree
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: Stop conflating return value with file size in net_loop()

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>

authored by

Yuya Hamamachi and committed by
Jerome Forissier
86f90e2a b5213bbf

+12 -11
+1 -1
cmd/mvebu/bubt.c
··· 661 661 */ 662 662 image_load_addr = get_load_addr(); 663 663 ret = net_loop(TFTPGET); 664 - return ret > 0 ? ret : 0; 664 + return ret > 0 ? net_boot_file_size : 0; 665 665 } 666 666 667 667 static int is_tftp_active(void)
+5 -4
cmd/net.c
··· 354 354 char *const argv[]) 355 355 { 356 356 char *s; 357 - int rcode = 0; 358 - int size; 357 + int rcode; 358 + u32 size; 359 359 360 360 net_boot_file_name_explicit = false; 361 361 *net_boot_file_name = '\0'; ··· 396 396 } 397 397 } 398 398 399 - size = net_loop(proto); 400 - if (size < 0) { 399 + rcode = net_loop(proto); 400 + size = net_boot_file_size; 401 + if (rcode < 0) { 401 402 bootstage_error(BOOTSTAGE_ID_NET_NETLOOP_OK); 402 403 return CMD_RET_FAILURE; 403 404 }
+5 -5
common/update.c
··· 32 32 #endif 33 33 static int update_load(char *filename, ulong msec_max, int cnt_max, ulong addr) 34 34 { 35 - int size, rv; 35 + int rv; 36 36 ulong saved_timeout_msecs; 37 37 int saved_timeout_count; 38 38 char *saved_netretry, *saved_bootfile; ··· 54 54 /* download the update file */ 55 55 image_load_addr = addr; 56 56 copy_filename(net_boot_file_name, filename, sizeof(net_boot_file_name)); 57 - size = net_loop(TFTPGET); 57 + rv = net_loop(TFTPGET); 58 58 59 - if (size < 0) 59 + if (rv < 0) 60 60 rv = 1; 61 - else if (size > 0) 62 - flush_cache(addr, size); 61 + else 62 + flush_cache(addr, net_boot_file_size); 63 63 64 64 /* restore changed globals and env variable */ 65 65 tftp_timeout_ms = saved_timeout_msecs;
+1 -1
net/net.c
··· 692 692 693 693 eth_set_last_protocol(protocol); 694 694 695 - ret = net_boot_file_size; 695 + ret = !!net_boot_file_size; 696 696 debug_cond(DEBUG_INT_STATE, "--- net_loop Success!\n"); 697 697 goto done; 698 698