From 5f88cf2a224af9a289d6f297fe24e5a23b1d38ca Mon Sep 17 00:00:00 2001 From: Ben Marsh Date: Tue, 24 Oct 2023 09:39:13 +0100 Subject: [PATCH] subsys/mgmt/mcumgr: Reduce unnecessary ROM usage mcumgr's SMP UDP transport was unnecessarily using a potentially large amount of ROM space due to static initialising fields in a config struct that also contains buffers/stacks. This has been changed to instead initialise fields in the start function, reducing ROM usage by ~5K in the default configuration with IPv4 and IPv6 enabled. (cherry picked from commit f9809a0a72ea2a5acd32f92bbcd07b99038f96cd) Original-Signed-off-by: Ben Marsh GitOrigin-RevId: f9809a0a72ea2a5acd32f92bbcd07b99038f96cd Change-Id: I34e9b2cdd378a94b9c79a400d17e19fc205c04b4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/4995672 Commit-Queue: Fabio Baltieri Tested-by: Fabio Baltieri Tested-by: ChromeOS Prod (Robot) Reviewed-by: Fabio Baltieri --- subsys/mgmt/mcumgr/transport/src/smp_udp.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/subsys/mgmt/mcumgr/transport/src/smp_udp.c b/subsys/mgmt/mcumgr/transport/src/smp_udp.c index f59ca884cd0..6c0043d3f0c 100644 --- a/subsys/mgmt/mcumgr/transport/src/smp_udp.c +++ b/subsys/mgmt/mcumgr/transport/src/smp_udp.c @@ -81,20 +81,7 @@ struct configs { #endif }; -static struct configs configs = { -#ifdef CONFIG_MCUMGR_TRANSPORT_UDP_IPV4 - .ipv4 = { - .proto = PROTOCOL_IPV4, - .sock = -1, - }, -#endif -#ifdef CONFIG_MCUMGR_TRANSPORT_UDP_IPV6 - .ipv6 = { - .proto = PROTOCOL_IPV6, - .sock = -1, - }, -#endif -}; +static struct configs configs; static struct net_mgmt_event_callback smp_udp_mgmt_cb; @@ -382,6 +369,9 @@ static void smp_udp_start(void) int rc; #ifdef CONFIG_MCUMGR_TRANSPORT_UDP_IPV4 + configs.ipv4.proto = PROTOCOL_IPV4; + configs.ipv4.sock = -1; + k_sem_init(&configs.ipv4.network_ready_sem, 0, 1); configs.ipv4.smp_transport.functions.output = smp_udp4_tx; configs.ipv4.smp_transport.functions.get_mtu = smp_udp_get_mtu; @@ -401,6 +391,9 @@ static void smp_udp_start(void) #endif #ifdef CONFIG_MCUMGR_TRANSPORT_UDP_IPV6 + configs.ipv6.proto = PROTOCOL_IPV6; + configs.ipv6.sock = -1; + k_sem_init(&configs.ipv6.network_ready_sem, 0, 1); configs.ipv6.smp_transport.functions.output = smp_udp6_tx; configs.ipv6.smp_transport.functions.get_mtu = smp_udp_get_mtu;