udhcpd: use ptr_to_globals for its lone global data (g_leases)
authorDenys Vlasenko <vda.linux@googlemail.com>
Thu, 1 Feb 2018 09:41:14 +0000 (10:41 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Thu, 1 Feb 2018 09:41:14 +0000 (10:41 +0100)
function                                             old     new   delta
udhcpd_main                                         1461    1463      +2
add_lease                                            320     318      -2
g_leases                                               4       -      -4
write_leases                                         223     214      -9
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/2 up/down: 2/-15)             Total: -13 bytes
   text    data     bss     dec     hex filename
 933232     481    6856  940569   e5a19 busybox_old
 933223     481    6852  940556   e5a0c busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
networking/udhcp/dhcpd.c

index 238542bb0c363e26186ae5284eb13edcf311906b..ff74507398c7e44b69280ea415de0a69b5c199c5 100644 (file)
@@ -45,7 +45,7 @@
 #include "dhcpd.h"
 
 /* globals */
-struct dyn_lease *g_leases;
+#define g_leases ((struct dyn_lease*)ptr_to_globals)
 /* struct server_config_t server_config is in bb_common_bufsiz1 */
 
 /* Takes the address of the pointer to the static_leases linked list,
@@ -880,7 +880,9 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
                server_config.max_leases = num_ips;
        }
 
-       g_leases = xzalloc(server_config.max_leases * sizeof(g_leases[0]));
+       /* this sets g_leases */
+       SET_PTR_TO_GLOBALS(xzalloc(server_config.max_leases * sizeof(g_leases[0])));
+
        read_leases(server_config.lease_file);
 
        if (udhcp_read_interface(server_config.interface,