]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
net: lwip: dns: Call env_set() from dns loop instead of found callback
authorJonas Karlman <jonas@kwiboo.se>
Sat, 17 Jan 2026 00:24:39 +0000 (00:24 +0000)
committerJerome Forissier <jerome.forissier@arm.com>
Wed, 4 Feb 2026 08:04:36 +0000 (09:04 +0100)
The lwIP dns command handle env_set() calls from the found callback and
printf() to console in the dns loop. Making it more complex than it
needs to be.

Simplify and ensure any environment variable that is being set is the
same value that would have been printed on console.

There should not be any intended change in behavior, besides the change
from using ip4addr helper to using version less ipaddr helper.

Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
Reviewed-by: Jerome Forissier <jerome.forissier@arm.com>
net/lwip/dns.c

index 2b2a5947a2b830343be5a1fba1ab70271431b6ee..2222e2b0b0453b41cf36ea9b25061d9e3b6e8841 100644 (file)
@@ -14,7 +14,6 @@
 
 struct dns_cb_arg {
        ip_addr_t host_ipaddr;
-       const char *var;
        bool done;
 };
 
@@ -26,7 +25,6 @@ static void do_dns_tmr(void *arg)
 static void dns_cb(const char *name, const ip_addr_t *ipaddr, void *arg)
 {
        struct dns_cb_arg *dns_cb_arg = arg;
-       char *ipstr = ip4addr_ntoa(ipaddr);
 
        dns_cb_arg->done = true;
 
@@ -37,21 +35,17 @@ static void dns_cb(const char *name, const ip_addr_t *ipaddr, void *arg)
        }
 
        dns_cb_arg->host_ipaddr.addr = ipaddr->addr;
-
-       if (dns_cb_arg->var)
-               env_set(dns_cb_arg->var, ipstr);
 }
 
 static int dns_loop(struct udevice *udev, const char *name, const char *var)
 {
        struct dns_cb_arg dns_cb_arg = { };
        struct netif *netif;
+       const char *ipstr;
        ip_addr_t ipaddr;
        ulong start;
        int ret;
 
-       dns_cb_arg.var = var;
-
        netif = net_lwip_new_netif(udev);
        if (!netif)
                return CMD_RET_FAILURE;
@@ -85,8 +79,11 @@ static int dns_loop(struct udevice *udev, const char *name, const char *var)
        net_lwip_remove_netif(netif);
 
        if (dns_cb_arg.done && dns_cb_arg.host_ipaddr.addr != 0) {
-               if (!var)
-                       printf("%s\n", ipaddr_ntoa(&dns_cb_arg.host_ipaddr));
+               ipstr = ipaddr_ntoa(&dns_cb_arg.host_ipaddr);
+               if (var)
+                       env_set(var, ipstr);
+               else
+                       printf("%s\n", ipstr);
                return CMD_RET_SUCCESS;
        }