From: Yu Watanabe Date: Sat, 12 Apr 2025 18:38:50 +0000 (+0900) Subject: network/wiphy: use hash_ops with destructor for managing Wiphy objects X-Git-Tag: v258-rc1~789^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=52278e06347dec58e3264c623e02ef72e510fc6d;p=thirdparty%2Fsystemd.git network/wiphy: use hash_ops with destructor for managing Wiphy objects --- diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index dbaebb1b0c9..0fa3ae2a5b9 100644 --- a/src/network/networkd-manager.c +++ b/src/network/networkd-manager.c @@ -692,7 +692,7 @@ Manager* manager_free(Manager *m) { m->tuntap_fds_by_name = hashmap_free(m->tuntap_fds_by_name); m->wiphy_by_name = hashmap_free(m->wiphy_by_name); - m->wiphy_by_index = hashmap_free_with_destructor(m->wiphy_by_index, wiphy_free); + m->wiphy_by_index = hashmap_free(m->wiphy_by_index); ordered_set_free(m->address_pools); diff --git a/src/network/networkd-wiphy.c b/src/network/networkd-wiphy.c index 441713fa0c8..798531f8e65 100644 --- a/src/network/networkd-wiphy.c +++ b/src/network/networkd-wiphy.c @@ -12,7 +12,7 @@ #include "udev-util.h" #include "wifi-util.h" -Wiphy *wiphy_free(Wiphy *w) { +static Wiphy* wiphy_free(Wiphy *w) { if (!w) return NULL; @@ -29,6 +29,13 @@ Wiphy *wiphy_free(Wiphy *w) { return mfree(w); } +DEFINE_TRIVIAL_CLEANUP_FUNC(Wiphy*, wiphy_free); + +DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR( + wiphy_hash_ops, + void, trivial_hash_func, trivial_compare_func, + Wiphy, wiphy_free); + static int wiphy_new(Manager *manager, sd_netlink_message *message, Wiphy **ret) { _cleanup_(wiphy_freep) Wiphy *w = NULL; _cleanup_free_ char *name = NULL; @@ -56,7 +63,7 @@ static int wiphy_new(Manager *manager, sd_netlink_message *message, Wiphy **ret) .name = TAKE_PTR(name), }; - r = hashmap_ensure_put(&manager->wiphy_by_index, NULL, UINT32_TO_PTR(w->index), w); + r = hashmap_ensure_put(&manager->wiphy_by_index, &wiphy_hash_ops, UINT32_TO_PTR(w->index), w); if (r < 0) return r; diff --git a/src/network/networkd-wiphy.h b/src/network/networkd-wiphy.h index b9056e802c7..8f92112148a 100644 --- a/src/network/networkd-wiphy.h +++ b/src/network/networkd-wiphy.h @@ -31,9 +31,6 @@ typedef struct Wiphy { RFKillState rfkill_state; } Wiphy; -Wiphy *wiphy_free(Wiphy *w); -DEFINE_TRIVIAL_CLEANUP_FUNC(Wiphy*, wiphy_free); - int wiphy_get_by_index(Manager *manager, uint32_t index, Wiphy **ret); int wiphy_get_by_name(Manager *manager, const char *name, Wiphy **ret);