Skip to content

Commit 52278e0

Browse files
committed
network/wiphy: use hash_ops with destructor for managing Wiphy objects
1 parent 4cf443e commit 52278e0

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

src/network/networkd-manager.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ Manager* manager_free(Manager *m) {
692692
m->tuntap_fds_by_name = hashmap_free(m->tuntap_fds_by_name);
693693

694694
m->wiphy_by_name = hashmap_free(m->wiphy_by_name);
695-
m->wiphy_by_index = hashmap_free_with_destructor(m->wiphy_by_index, wiphy_free);
695+
m->wiphy_by_index = hashmap_free(m->wiphy_by_index);
696696

697697
ordered_set_free(m->address_pools);
698698

src/network/networkd-wiphy.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "udev-util.h"
1313
#include "wifi-util.h"
1414

15-
Wiphy *wiphy_free(Wiphy *w) {
15+
static Wiphy* wiphy_free(Wiphy *w) {
1616
if (!w)
1717
return NULL;
1818

@@ -29,6 +29,13 @@ Wiphy *wiphy_free(Wiphy *w) {
2929
return mfree(w);
3030
}
3131

32+
DEFINE_TRIVIAL_CLEANUP_FUNC(Wiphy*, wiphy_free);
33+
34+
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
35+
wiphy_hash_ops,
36+
void, trivial_hash_func, trivial_compare_func,
37+
Wiphy, wiphy_free);
38+
3239
static int wiphy_new(Manager *manager, sd_netlink_message *message, Wiphy **ret) {
3340
_cleanup_(wiphy_freep) Wiphy *w = NULL;
3441
_cleanup_free_ char *name = NULL;
@@ -56,7 +63,7 @@ static int wiphy_new(Manager *manager, sd_netlink_message *message, Wiphy **ret)
5663
.name = TAKE_PTR(name),
5764
};
5865

59-
r = hashmap_ensure_put(&manager->wiphy_by_index, NULL, UINT32_TO_PTR(w->index), w);
66+
r = hashmap_ensure_put(&manager->wiphy_by_index, &wiphy_hash_ops, UINT32_TO_PTR(w->index), w);
6067
if (r < 0)
6168
return r;
6269

src/network/networkd-wiphy.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ typedef struct Wiphy {
3131
RFKillState rfkill_state;
3232
} Wiphy;
3333

34-
Wiphy *wiphy_free(Wiphy *w);
35-
DEFINE_TRIVIAL_CLEANUP_FUNC(Wiphy*, wiphy_free);
36-
3734
int wiphy_get_by_index(Manager *manager, uint32_t index, Wiphy **ret);
3835
int wiphy_get_by_name(Manager *manager, const char *name, Wiphy **ret);
3936

0 commit comments

Comments
 (0)