]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Use hashmap_ensure_replace() 33536/head
authorMatteo Croce <teknoraver@meta.com>
Fri, 28 Jun 2024 15:19:26 +0000 (17:19 +0200)
committerMatteo Croce <teknoraver@meta.com>
Fri, 28 Jun 2024 17:07:24 +0000 (19:07 +0200)
Use the new function `hashmap_ensure_replace()` where we're using
`hashmap_ensure_allocated()` and `hashmap_ensure_replace()`.

Signed-off-by: Matteo Croce <teknoraver@meta.com>
src/core/unit.c
src/libsystemd/sd-hwdb/sd-hwdb.c
src/libsystemd/sd-netlink/netlink-socket.c

index 0e931be484665549fdc5d61623c2f7216bc69845..a4e96116fc2bfdb0952857235aac5eb71151af2a 100644 (file)
@@ -2805,13 +2805,8 @@ int unit_watch_pidref(Unit *u, const PidRef *pid, bool exclusive) {
         new_array[n] = u;
         new_array[n+1] = NULL;
 
-        /* Make sure the hashmap is allocated */
-        r = hashmap_ensure_allocated(&u->manager->watch_pids_more, &pidref_hash_ops_free);
-        if (r < 0)
-                return r;
-
         /* Add or replace the old array */
-        r = hashmap_replace(u->manager->watch_pids_more, old_pid ?: pid, new_array);
+        r = hashmap_ensure_replace(&u->manager->watch_pids_more, &pidref_hash_ops_free, old_pid ?: pid, new_array);
         if (r < 0)
                 return r;
 
index f623d470648d0f3a18f8161e31037af2d2c3ef87..11c5092bc97fb6bd9d86e759bc8c63dad57bf911 100644 (file)
@@ -166,11 +166,7 @@ static int hwdb_add_property(sd_hwdb *hwdb, const struct trie_value_entry_f *ent
                 }
         }
 
-        r = ordered_hashmap_ensure_allocated(&hwdb->properties, &string_hash_ops);
-        if (r < 0)
-                return r;
-
-        r = ordered_hashmap_replace(hwdb->properties, key, (void *)entry);
+        r = ordered_hashmap_ensure_replace(&hwdb->properties, &string_hash_ops, key, (void *) entry);
         if (r < 0)
                 return r;
 
index 64cde89ecfafb1f79a81caf6af7b11bf7e797c53..d09dc31fa32f39ddd267d7cdeccdf1f7fbbe7f53 100644 (file)
@@ -86,15 +86,9 @@ static unsigned broadcast_group_get_ref(sd_netlink *nl, unsigned group) {
 }
 
 static int broadcast_group_set_ref(sd_netlink *nl, unsigned group, unsigned n_ref) {
-        int r;
-
         assert(nl);
 
-        r = hashmap_ensure_allocated(&nl->broadcast_group_refs, NULL);
-        if (r < 0)
-                return r;
-
-        return hashmap_replace(nl->broadcast_group_refs, UINT_TO_PTR(group), UINT_TO_PTR(n_ref));
+        return hashmap_ensure_replace(&nl->broadcast_group_refs, NULL, UINT_TO_PTR(group), UINT_TO_PTR(n_ref));
 }
 
 static int broadcast_group_join(sd_netlink *nl, unsigned group) {