summaryrefslogtreecommitdiff
path: root/cmd/net.c
diff options
context:
space:
mode:
authorYuya Hamamachi <[email protected]>2026-01-29 23:30:18 +0100
committerJerome Forissier <[email protected]>2026-02-06 16:37:31 +0100
commit86f90e2a5fb0283552f610e293fcee2a29724094 (patch)
treed47ef37d273972f484c8543f97dd50227e538c23 /cmd/net.c
parentb5213bbfdcb1812be510427857827ee8becb9f8f (diff)
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 <[email protected]> Signed-off-by: Marek Vasut <[email protected]>
Diffstat (limited to 'cmd/net.c')
-rw-r--r--cmd/net.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/cmd/net.c b/cmd/net.c
index 24099764493..f6f556f36ae 100644
--- 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;
}