]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/libsystemd-network/sd-ipv4ll.c
tree-wide: drop {} from one-line if blocks
[thirdparty/systemd.git] / src / libsystemd-network / sd-ipv4ll.c
index 0cb77ccf713cbc80e2d1255293e6c6d432b60995..14b9444dab0ef0d842a85348ac19c14c88b47dc6 100644 (file)
@@ -26,7 +26,6 @@
 #include "util.h"
 #include "siphash24.h"
 #include "list.h"
-#include "refcnt.h"
 #include "random-util.h"
 
 #include "ipv4ll-internal.h"
@@ -68,7 +67,7 @@ typedef enum IPv4LLState {
 } IPv4LLState;
 
 struct sd_ipv4ll {
-        RefCount n_ref;
+        unsigned n_ref;
 
         IPv4LLState state;
         int index;
@@ -464,9 +463,8 @@ int sd_ipv4ll_get_address(sd_ipv4ll *ll, struct in_addr *address){
         assert_return(ll, -EINVAL);
         assert_return(address, -EINVAL);
 
-        if (ll->claimed_address == 0) {
+        if (ll->claimed_address == 0)
                 return -ENOENT;
-        }
 
         address->s_addr = ll->claimed_address;
         return 0;
@@ -507,7 +505,7 @@ error:
 }
 
 bool sd_ipv4ll_is_running(sd_ipv4ll *ll) {
-        assert_return(ll, -EINVAL);
+        assert_return(ll, false);
 
         return !IN_SET(ll->state, IPV4LL_STATE_INIT, IPV4LL_STATE_STOPPED);
 }
@@ -598,30 +596,39 @@ int sd_ipv4ll_stop(sd_ipv4ll *ll) {
 }
 
 sd_ipv4ll *sd_ipv4ll_ref(sd_ipv4ll *ll) {
-        if (ll)
-                assert_se(REFCNT_INC(ll->n_ref) >= 2);
+
+        if (!ll)
+                return NULL;
+
+        assert(ll->n_ref >= 1);
+        ll->n_ref++;
 
         return ll;
 }
 
 sd_ipv4ll *sd_ipv4ll_unref(sd_ipv4ll *ll) {
-        if (ll && REFCNT_DEC(ll->n_ref) == 0) {
-                ll->receive_message =
-                        sd_event_source_unref(ll->receive_message);
-                ll->fd = safe_close(ll->fd);
 
-                ll->timer = sd_event_source_unref(ll->timer);
+        if (!ll)
+                return NULL;
 
-                sd_ipv4ll_detach_event(ll);
+        assert(ll->n_ref >= 1);
+        ll->n_ref--;
 
-                free(ll->random_data);
-                free(ll->random_data_state);
-                free(ll);
+        if (ll->n_ref > 0)
+                return ll;
 
-                return NULL;
-        }
+        ll->receive_message = sd_event_source_unref(ll->receive_message);
+        ll->fd = safe_close(ll->fd);
 
-        return ll;
+        ll->timer = sd_event_source_unref(ll->timer);
+
+        sd_ipv4ll_detach_event(ll);
+
+        free(ll->random_data);
+        free(ll->random_data_state);
+        free(ll);
+
+        return NULL;
 }
 
 DEFINE_TRIVIAL_CLEANUP_FUNC(sd_ipv4ll*, sd_ipv4ll_unref);
@@ -636,7 +643,7 @@ int sd_ipv4ll_new(sd_ipv4ll **ret) {
         if (!ll)
                 return -ENOMEM;
 
-        ll->n_ref = REFCNT_INIT;
+        ll->n_ref = 1;
         ll->state = IPV4LL_STATE_INIT;
         ll->index = -1;
         ll->fd = -1;