[PATCH v2 2/3] net: lwip: wget: return errno codes from wget_do_request()
Jerome Forissier
jerome.forissier at arm.com
Wed May 13 09:40:18 CEST 2026
On 12/05/2026 23:48, David Lechner wrote:
> Change the return values of the lwip implementation of wget_do_request()
> to be errno codes instead of command return codes.
>
> wget_do_request() is not a command, so it does not make sense to return
> command return codes from it. Also, the legacy network implementation of
> wget_do_request() already returns errno codes so it is logical for the
> lwip implementation to do the same.
>
> This fixes a bug in try_load_from_uri_path() in efi_manager.c where it
> checks that the return value of wget_do_request() is < 0. Before this
> change, CMD_RET_FAILURE would not be considered an error since it has a
> value of 1.
>
> The value of ENODEV is used in places where there could actually be a
> number of different causes of failure and it isn't possible to
> discriminate (i.e. failing function returns NULL for all errors). Since
> all callers of wget_do_request() don't propagate the error code, it
> doesn't matter so much that this is not ideal, at least at this point in
> time.
>
> Fixes: 3c656c928bd7 ("net: lwip: add wget command")
> Signed-off-by: David Lechner <dlechner at baylibre.com>
> ---
> net/lwip/wget.c | 28 +++++++++++++++++-----------
> 1 file changed, 17 insertions(+), 11 deletions(-)
>
> diff --git a/net/lwip/wget.c b/net/lwip/wget.c
> index f89a6580b41..3a0b0dca145 100644
> --- a/net/lwip/wget.c
> +++ b/net/lwip/wget.c
> @@ -300,10 +300,14 @@ static int wget_handle_request(struct wget_ctx *ctx, bool is_https,
> #endif
> httpc_connection_t conn;
> httpc_state_t *state;
> + int ret;
>
> /* if URL with hostname init dns */
> - if (!ipaddr_aton(ctx->server_name, NULL) && net_lwip_dns_init())
> - return CMD_RET_FAILURE;
> + if (!ipaddr_aton(ctx->server_name, NULL)) {
> + ret = net_lwip_dns_init();
> + if (ret)
> + return ret;
> + }
>
> memset(&conn, 0, sizeof(conn));
> #if CONFIG_IS_ENABLED(WGET_HTTPS)
> @@ -325,7 +329,7 @@ static int wget_handle_request(struct wget_ctx *ctx, bool is_https,
> printf("Error: cacert authentication "
> "mode is 'required' but no CA "
> "certificates given\n");
> - return CMD_RET_FAILURE;
> + return -EINVAL;
> }
> } else if (cacert_auth_mode == AUTH_NONE) {
> ca = NULL;
> @@ -350,7 +354,7 @@ static int wget_handle_request(struct wget_ctx *ctx, bool is_https,
>
> if (!tls_allocator.arg) {
> log_err("error: Cannot create a TLS connection\n");
> - return -1;
> + return -ENODEV;
> }
>
> conn.altcp_allocator = &tls_allocator;
> @@ -361,7 +365,7 @@ static int wget_handle_request(struct wget_ctx *ctx, bool is_https,
> conn.headers_done_fn = httpc_headers_done_cb;
> if (httpc_get_file_dns(ctx->server_name, ctx->port, ctx->path, &conn,
> httpc_recv_cb, ctx, &state)) {
> - return CMD_RET_FAILURE;
> + return -ENODEV;
> }
>
> errno = 0;
> @@ -378,7 +382,7 @@ static int wget_handle_request(struct wget_ctx *ctx, bool is_https,
> if (errno == EPERM && !wget_info->silent)
> printf("Certificate verification failed\n");
>
> - return -1;
> + return -errno ?: -EIO;
> }
>
> int wget_do_request(ulong dst_addr, char *uri)
> @@ -398,11 +402,13 @@ int wget_do_request(ulong dst_addr, char *uri)
> ctx.content_len = 0;
> ctx.hash_count = 0;
>
> - if (parse_url(uri, ctx.server_name, &ctx.port, &ctx.path, &is_https))
> - return CMD_RET_USAGE;
> + ret = parse_url(uri, ctx.server_name, &ctx.port, &ctx.path, &is_https);
> + if (ret)
> + return ret;
>
> - if (net_lwip_eth_start() < 0)
> - return CMD_RET_FAILURE;
> + ret = net_lwip_eth_start();
> + if (ret)
> + return ret;
>
> if (!wget_info)
> wget_info = &default_wget_info;
> @@ -411,7 +417,7 @@ int wget_do_request(ulong dst_addr, char *uri)
>
> netif = net_lwip_new_netif(udev);
> if (!netif)
> - return -1;
> + return -ENODEV;
>
> ret = wget_handle_request(&ctx, is_https, udev, netif);
>
>
Reviewed-by: Jerome Forissier <jerome.forissier at arm.com>
Thanks,
--
Jerome
More information about the U-Boot
mailing list