]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: rename unref_and_replace_full to unref_and_replace_new_ref
authorZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Thu, 7 May 2026 19:43:32 +0000 (21:43 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Fri, 8 May 2026 09:14:13 +0000 (11:14 +0200)
We have a number of *_unref_and_replace macros. One could think that
they are like the various free_and_replace variants, but they actually
create a new ref to the passed object. The free_and_replace variants
take ownership of the argument. This inconsistency is surprising. Rename
all those functions to have "_new_ref" at the end to make the difference
clear.

src/basic/cleanup-util.h
src/libsystemd-network/dhcp-lease-internal.h
src/libsystemd-network/sd-dhcp-client.c
src/libsystemd-network/sd-dhcp6-client.c
src/libsystemd/sd-device/device-util.h
src/network/networkd-dhcp6.c
src/network/networkd-link.c
src/network/networkd-wiphy.c
src/shared/blockdev-util.c
src/udev/udev-manager.c

index 041c37530aaa9299d7bea7f7a3584254eade45f2..e3a2ade4ed98427017eb88f9ea7ada0b0a00eb7c 100644 (file)
@@ -19,13 +19,13 @@ typedef void* (*mfree_func_t)(void *p);
 
 /* This is similar to free_and_replace_full(), but NULL is not assigned to 'b', and its reference counter is
  * increased. */
-#define unref_and_replace_full(a, b, ref_func, unref_func)      \
-        ({                                       \
-                typeof(a)* _a = &(a);            \
-                typeof(b) _b = ref_func(b);      \
-                unref_func(*_a);                 \
-                *_a = _b;                        \
-                0;                               \
+#define unref_and_replace_new_ref(a, b, ref_func, unref_func) \
+        ({                                                    \
+                typeof(a)* _a = &(a);                         \
+                typeof(b) _b = ref_func(b);                   \
+                unref_func(*_a);                              \
+                *_a = _b;                                     \
+                0;                                            \
         })
 
 #define _DEFINE_TRIVIAL_REF_FUNC(type, name, scope)                                     \
index 744580fc48a8823b39e04e72be1731cf09f00a19..1eab7f89b616cc663b79aa66a4cddde3d81847bb 100644 (file)
@@ -97,5 +97,5 @@ void dhcp_lease_set_timestamp(sd_dhcp_lease *lease, const triple_timestamp *time
 int dhcp_lease_set_default_subnet_mask(sd_dhcp_lease *lease);
 int dhcp_lease_set_client_id(sd_dhcp_lease *lease, const sd_dhcp_client_id *client_id);
 
-#define dhcp_lease_unref_and_replace(a, b)                              \
-        unref_and_replace_full(a, b, sd_dhcp_lease_ref, sd_dhcp_lease_unref)
+#define dhcp_lease_unref_and_replace_new_ref(a, b)                      \
+        unref_and_replace_new_ref(a, b, sd_dhcp_lease_ref, sd_dhcp_lease_unref)
index 9742ab833bd5beeca547a3c7e0eb408862efbab3..922dd5881ca9ed7bc1178794810dfbf43c2db916 100644 (file)
@@ -1594,7 +1594,7 @@ static int client_handle_offer_or_rapid_ack(sd_dhcp_client *client, DHCPMessage
 
         dhcp_lease_set_timestamp(lease, timestamp);
 
-        dhcp_lease_unref_and_replace(client->lease, lease);
+        dhcp_lease_unref_and_replace_new_ref(client->lease, lease);
 
         if (client->lease->rapid_commit) {
                 log_dhcp_client(client, "ACK");
@@ -1678,7 +1678,7 @@ static int client_handle_ack(sd_dhcp_client *client, DHCPMessage *message, size_
         else
                 r = SD_DHCP_CLIENT_EVENT_IP_CHANGE;
 
-        dhcp_lease_unref_and_replace(client->lease, lease);
+        dhcp_lease_unref_and_replace_new_ref(client->lease, lease);
 
         log_dhcp_client(client, "ACK");
         return r;
@@ -2281,7 +2281,7 @@ sd_event* sd_dhcp_client_get_event(sd_dhcp_client *client) {
 int sd_dhcp_client_attach_device(sd_dhcp_client *client, sd_device *dev) {
         assert_return(client, -EINVAL);
 
-        return device_unref_and_replace(client->dev, dev);
+        return device_unref_and_replace_new_ref(client->dev, dev);
 }
 
 static sd_dhcp_client* dhcp_client_free(sd_dhcp_client *client) {
index ee67664364c9fef470899cf1cffae326a5a99fa1..5e71d63de5a43e855543162197bebe5a510b2cdd 100644 (file)
@@ -1533,7 +1533,7 @@ sd_event *sd_dhcp6_client_get_event(sd_dhcp6_client *client) {
 int sd_dhcp6_client_attach_device(sd_dhcp6_client *client, sd_device *dev) {
         assert_return(client, -EINVAL);
 
-        return device_unref_and_replace(client->dev, dev);
+        return device_unref_and_replace_new_ref(client->dev, dev);
 }
 
 static sd_dhcp6_client *dhcp6_client_free(sd_dhcp6_client *client) {
index 3bbe321f61649df655608e3212c4928a4e4d2054..e4350a679b690854126b971ac6f1551bb009cb25 100644 (file)
@@ -6,8 +6,8 @@
 #include "sd-forward.h"
 #include "log.h"
 
-#define device_unref_and_replace(a, b)                                  \
-        unref_and_replace_full(a, b, sd_device_ref, sd_device_unref)
+#define device_unref_and_replace_new_ref(a, b)                          \
+        unref_and_replace_new_ref(a, b, sd_device_ref, sd_device_unref)
 
 #define FOREACH_DEVICE_PROPERTY(device, key, value)                     \
         for (const char *value, *key = sd_device_get_property_first(device, &value); \
index c230a86587464a1ebe5cd3bfebe75ab21e61ec7a..799caeb15b312fb73f520ce6c2b82394ff1602a2 100644 (file)
@@ -364,7 +364,7 @@ static int dhcp6_lease_information_acquired(sd_dhcp6_client *client, Link *link)
         if (r < 0)
                 return log_link_error_errno(link, r, "Failed to get DHCPv6 lease: %m");
 
-        unref_and_replace_full(link->dhcp6_lease, lease, sd_dhcp6_lease_ref, sd_dhcp6_lease_unref);
+        unref_and_replace_new_ref(link->dhcp6_lease, lease, sd_dhcp6_lease_ref, sd_dhcp6_lease_unref);
 
         link_dirty(link);
         return 0;
index c6bc8fc4b1c4de1b4c3247ba138f59dbe607b036..dcd081039bf55a1dd745f34ec2b8a763d35b97a6 100644 (file)
@@ -1678,7 +1678,7 @@ static int link_initialized(Link *link, sd_device *device) {
 
         /* Always replace with the new sd_device object. As the sysname (and possibly other properties
          * or sysattrs) may be outdated. */
-        device_unref_and_replace(link->dev, device);
+        device_unref_and_replace_new_ref(link->dev, device);
 
         r = link_managed_by_us(link);
         if (r <= 0)
index 1dde69a43b44db0175374b14704a7236f7e1b285..f715f244d6b29ba159ce0c0c607a0c1df856227f 100644 (file)
@@ -469,7 +469,7 @@ int manager_udev_process_wiphy(Manager *m, sd_device *device, sd_device_action_t
                 return 0;
         }
 
-        return device_unref_and_replace(w->dev, action == SD_DEVICE_REMOVE ? NULL : device);
+        return device_unref_and_replace_new_ref(w->dev, action == SD_DEVICE_REMOVE ? NULL : device);
 }
 
 int manager_udev_process_rfkill(Manager *m, sd_device *device, sd_device_action_t action) {
@@ -501,5 +501,5 @@ int manager_udev_process_rfkill(Manager *m, sd_device *device, sd_device_action_
                 return 0;
         }
 
-        return device_unref_and_replace(w->rfkill, action == SD_DEVICE_REMOVE ? NULL : device);
+        return device_unref_and_replace_new_ref(w->rfkill, action == SD_DEVICE_REMOVE ? NULL : device);
 }
index 12a4f59c28a6942b29cfc7f1d463421c247dfebe..83eb67c54152debf96ccb407b80b8772e4c84a1f 100644 (file)
@@ -207,7 +207,7 @@ int block_device_new_from_fd(int fd, BlockDeviceLookupFlags flags, sd_device **r
 
                 r = block_device_get_originating(dev_whole_disk, &dev_origin, /* recursive= */ false);
                 if (r >= 0)
-                        device_unref_and_replace(dev, dev_origin);
+                        device_unref_and_replace_new_ref(dev, dev_origin);
                 else if (r != -ENOENT)
                         return r;
         }
index 7c2530f17fec8b2e5e7c3e801c02b0b1b11d07e3..44d2ee6400362e3c35cda989d0b24f60f1821265 100644 (file)
@@ -683,7 +683,7 @@ static void event_find_blocker(Event *event) {
                 log_device_debug(event->dev, "SEQNUM=%" PRIu64 " blocked by SEQNUM=%" PRIu64,
                                  event->seqnum, e->seqnum);
 
-                unref_and_replace_full(event->blocker, e, event_ref, event_unref);
+                unref_and_replace_new_ref(event->blocker, e, event_ref, event_unref);
                 return;
         }