]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network/wiphy: use hash_ops with destructor for managing Wiphy objects 37121/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 12 Apr 2025 18:38:50 +0000 (03:38 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 13 Apr 2025 01:15:02 +0000 (10:15 +0900)
src/network/networkd-manager.c
src/network/networkd-wiphy.c
src/network/networkd-wiphy.h

index dbaebb1b0c9dfac3d75fd1848767e8f0f3a21d07..0fa3ae2a5b983b18718573cc8e13864eb79ec2e3 100644 (file)
@@ -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);
 
index 441713fa0c876700e36a68b61b10cb704b5bd6c5..798531f8e650f726b22a40da39a53f908ac41ba9 100644 (file)
@@ -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;
 
index b9056e802c7c29bd889d71c3c74edfacb1ed32f8..8f92112148ab411bec6ebb3bf0e57b4cca135458 100644 (file)
@@ -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);