Send connman mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
https://lists.01.org/mailman/listinfo/connman
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of connman digest..."
Today's Topics:
1. [PATCH] ippool: Remove refcount on connman_ippool struct
(Nicolas Cornu)
2. [PATCH] ippool: Remove refcount on connman_ippool struct
(Nicolas Cornu)
----------------------------------------------------------------------
Message: 1
Date: Fri, 6 Jul 2018 16:07:45 +0200
From: Nicolas Cornu <[email protected]>
To: [email protected]
Cc: Nicolas Cornu <[email protected]>
Subject: [PATCH] ippool: Remove refcount on connman_ippool struct
Message-ID: <[email protected]>
From: Nicolas Cornu <[email protected]>
No one is using it, and it let us NULL the global ippool in tethering.
---
src/connman.h | 10 +---------
src/ippool.c | 24 +-----------------------
src/peer.c | 2 +-
src/tethering.c | 14 +++++++++-----
4 files changed, 12 insertions(+), 38 deletions(-)
diff --git a/src/connman.h b/src/connman.h
index fde899af..706ab981 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -975,15 +975,7 @@ typedef void (*ippool_collision_cb_t) (struct
connman_ippool *pool,
int __connman_ippool_init(void);
void __connman_ippool_cleanup(void);
-#define __connman_ippool_ref(ipconfig) \
- __connman_ippool_ref_debug(ipconfig, __FILE__, __LINE__, __func__)
-#define __connman_ippool_unref(ipconfig) \
- __connman_ippool_unref_debug(ipconfig, __FILE__, __LINE__, __func__)
-
-struct connman_ippool *__connman_ippool_ref_debug(struct connman_ippool *pool,
- const char *file, int line, const char *caller);
-void __connman_ippool_unref_debug(struct connman_ippool *pool,
- const char *file, int line, const char *caller);
+void __connman_ippool_free(struct connman_ippool *pool);
struct connman_ippool *__connman_ippool_create(int index,
unsigned int start,
diff --git a/src/ippool.c b/src/ippool.c
index cea1dccd..ef9d907a 100644
--- a/src/ippool.c
+++ b/src/ippool.c
@@ -43,8 +43,6 @@ struct address_info {
};
struct connman_ippool {
- unsigned int refcount;
-
struct address_info *info;
char *gateway;
@@ -65,30 +63,11 @@ static uint32_t block_20_bits;
static uint32_t block_24_bits;
static uint32_t subnet_mask_24;
-struct connman_ippool *
-__connman_ippool_ref_debug(struct connman_ippool *pool,
- const char *file, int line, const char *caller)
-{
- DBG("%p ref %d by %s:%d:%s()", pool, pool->refcount + 1,
- file, line, caller);
-
- __sync_fetch_and_add(&pool->refcount, 1);
-
- return pool;
-}
-
-void __connman_ippool_unref_debug(struct connman_ippool *pool,
- const char *file, int line, const char *caller)
+void __connman_ippool_free(struct connman_ippool *pool)
{
if (!pool)
return;
- DBG("%p ref %d by %s:%d:%s()", pool, pool->refcount - 1,
- file, line, caller);
-
- if (__sync_fetch_and_sub(&pool->refcount, 1) != 1)
- return;
-
if (pool->info) {
allocated_blocks = g_slist_remove(allocated_blocks, pool->info);
g_free(pool->info);
@@ -386,7 +365,6 @@ struct connman_ippool *__connman_ippool_create(int index,
info->start = block;
info->end = block + range;
- pool->refcount = 1;
pool->info = info;
pool->collision_cb = collision_cb;
pool->user_data = user_data;
diff --git a/src/peer.c b/src/peer.c
index 1b9b80e3..dbd9cd68 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -82,7 +82,7 @@ static void stop_dhcp_server(struct connman_peer *peer)
peer->dhcp_server = NULL;
if (peer->ip_pool)
- __connman_ippool_unref(peer->ip_pool);
+ __connman_ippool_free(peer->ip_pool);
peer->ip_pool = NULL;
peer->lease_ip = 0;
}
diff --git a/src/tethering.c b/src/tethering.c
index 4b202369..d222afca 100644
--- a/src/tethering.c
+++ b/src/tethering.c
@@ -225,7 +225,8 @@ int __connman_tethering_set_enabled(void)
connman_ipaddress_calc_netmask_len(subnet_mask),
broadcast);
if (err < 0 && err != -EALREADY) {
- __connman_ippool_unref(dhcp_ippool);
+ __connman_ippool_free(dhcp_ippool);
+ dhcp_ippool = NULL;
__connman_bridge_remove(BRIDGE_NAME);
__sync_fetch_and_sub(&tethering_enabled, 1);
return -EADDRNOTAVAIL;
@@ -261,7 +262,8 @@ int __connman_tethering_set_enabled(void)
24 * 3600, dns);
if (!tethering_dhcp_server) {
__connman_bridge_disable(BRIDGE_NAME);
- __connman_ippool_unref(dhcp_ippool);
+ __connman_ippool_free(dhcp_ippool);
+ dhcp_ippool = NULL;
__connman_bridge_remove(BRIDGE_NAME);
__sync_fetch_and_sub(&tethering_enabled, 1);
return -EOPNOTSUPP;
@@ -273,7 +275,8 @@ int __connman_tethering_set_enabled(void)
connman_error("Cannot enable NAT %d/%s", err, strerror(-err));
dhcp_server_stop(tethering_dhcp_server);
__connman_bridge_disable(BRIDGE_NAME);
- __connman_ippool_unref(dhcp_ippool);
+ __connman_ippool_free(dhcp_ippool);
+ dhcp_ippool = NULL;
__connman_bridge_remove(BRIDGE_NAME);
__sync_fetch_and_sub(&tethering_enabled, 1);
return -EOPNOTSUPP;
@@ -311,7 +314,8 @@ void __connman_tethering_set_disabled(void)
__connman_bridge_disable(BRIDGE_NAME);
- __connman_ippool_unref(dhcp_ippool);
+ __connman_ippool_free(dhcp_ippool);
+ dhcp_ippool = NULL;
__connman_bridge_remove(BRIDGE_NAME);
@@ -399,7 +403,7 @@ static void remove_private_network(gpointer user_data)
__connman_nat_disable(BRIDGE_NAME);
connman_rtnl_remove_watch(pn->iface_watch);
- __connman_ippool_unref(pn->pool);
+ __connman_ippool_free(pn->pool);
if (pn->watch > 0) {
g_dbus_remove_watch(connection, pn->watch);
--
2.17.1
------------------------------
Message: 2
Date: Fri, 6 Jul 2018 16:12:20 +0200
From: Nicolas Cornu <[email protected]>
To: [email protected]
Cc: Nicolas Cornu <[email protected]>
Subject: [PATCH] ippool: Remove refcount on connman_ippool struct
Message-ID: <[email protected]>
From: Nicolas Cornu <[email protected]>
No one is using it, and it let us NULL the global ippool in tethering.
---
In previous one I forgot unit test file.
src/connman.h | 10 +---------
src/ippool.c | 24 +-----------------------
src/peer.c | 2 +-
src/tethering.c | 14 +++++++++-----
unit/test-ippool.c | 18 +++++++++---------
5 files changed, 21 insertions(+), 47 deletions(-)
diff --git a/src/connman.h b/src/connman.h
index fde899af..706ab981 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -975,15 +975,7 @@ typedef void (*ippool_collision_cb_t) (struct
connman_ippool *pool,
int __connman_ippool_init(void);
void __connman_ippool_cleanup(void);
-#define __connman_ippool_ref(ipconfig) \
- __connman_ippool_ref_debug(ipconfig, __FILE__, __LINE__, __func__)
-#define __connman_ippool_unref(ipconfig) \
- __connman_ippool_unref_debug(ipconfig, __FILE__, __LINE__, __func__)
-
-struct connman_ippool *__connman_ippool_ref_debug(struct connman_ippool *pool,
- const char *file, int line, const char *caller);
-void __connman_ippool_unref_debug(struct connman_ippool *pool,
- const char *file, int line, const char *caller);
+void __connman_ippool_free(struct connman_ippool *pool);
struct connman_ippool *__connman_ippool_create(int index,
unsigned int start,
diff --git a/src/ippool.c b/src/ippool.c
index cea1dccd..ef9d907a 100644
--- a/src/ippool.c
+++ b/src/ippool.c
@@ -43,8 +43,6 @@ struct address_info {
};
struct connman_ippool {
- unsigned int refcount;
-
struct address_info *info;
char *gateway;
@@ -65,30 +63,11 @@ static uint32_t block_20_bits;
static uint32_t block_24_bits;
static uint32_t subnet_mask_24;
-struct connman_ippool *
-__connman_ippool_ref_debug(struct connman_ippool *pool,
- const char *file, int line, const char *caller)
-{
- DBG("%p ref %d by %s:%d:%s()", pool, pool->refcount + 1,
- file, line, caller);
-
- __sync_fetch_and_add(&pool->refcount, 1);
-
- return pool;
-}
-
-void __connman_ippool_unref_debug(struct connman_ippool *pool,
- const char *file, int line, const char *caller)
+void __connman_ippool_free(struct connman_ippool *pool)
{
if (!pool)
return;
- DBG("%p ref %d by %s:%d:%s()", pool, pool->refcount - 1,
- file, line, caller);
-
- if (__sync_fetch_and_sub(&pool->refcount, 1) != 1)
- return;
-
if (pool->info) {
allocated_blocks = g_slist_remove(allocated_blocks, pool->info);
g_free(pool->info);
@@ -386,7 +365,6 @@ struct connman_ippool *__connman_ippool_create(int index,
info->start = block;
info->end = block + range;
- pool->refcount = 1;
pool->info = info;
pool->collision_cb = collision_cb;
pool->user_data = user_data;
diff --git a/src/peer.c b/src/peer.c
index 1b9b80e3..dbd9cd68 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -82,7 +82,7 @@ static void stop_dhcp_server(struct connman_peer *peer)
peer->dhcp_server = NULL;
if (peer->ip_pool)
- __connman_ippool_unref(peer->ip_pool);
+ __connman_ippool_free(peer->ip_pool);
peer->ip_pool = NULL;
peer->lease_ip = 0;
}
diff --git a/src/tethering.c b/src/tethering.c
index 4b202369..d222afca 100644
--- a/src/tethering.c
+++ b/src/tethering.c
@@ -225,7 +225,8 @@ int __connman_tethering_set_enabled(void)
connman_ipaddress_calc_netmask_len(subnet_mask),
broadcast);
if (err < 0 && err != -EALREADY) {
- __connman_ippool_unref(dhcp_ippool);
+ __connman_ippool_free(dhcp_ippool);
+ dhcp_ippool = NULL;
__connman_bridge_remove(BRIDGE_NAME);
__sync_fetch_and_sub(&tethering_enabled, 1);
return -EADDRNOTAVAIL;
@@ -261,7 +262,8 @@ int __connman_tethering_set_enabled(void)
24 * 3600, dns);
if (!tethering_dhcp_server) {
__connman_bridge_disable(BRIDGE_NAME);
- __connman_ippool_unref(dhcp_ippool);
+ __connman_ippool_free(dhcp_ippool);
+ dhcp_ippool = NULL;
__connman_bridge_remove(BRIDGE_NAME);
__sync_fetch_and_sub(&tethering_enabled, 1);
return -EOPNOTSUPP;
@@ -273,7 +275,8 @@ int __connman_tethering_set_enabled(void)
connman_error("Cannot enable NAT %d/%s", err, strerror(-err));
dhcp_server_stop(tethering_dhcp_server);
__connman_bridge_disable(BRIDGE_NAME);
- __connman_ippool_unref(dhcp_ippool);
+ __connman_ippool_free(dhcp_ippool);
+ dhcp_ippool = NULL;
__connman_bridge_remove(BRIDGE_NAME);
__sync_fetch_and_sub(&tethering_enabled, 1);
return -EOPNOTSUPP;
@@ -311,7 +314,8 @@ void __connman_tethering_set_disabled(void)
__connman_bridge_disable(BRIDGE_NAME);
- __connman_ippool_unref(dhcp_ippool);
+ __connman_ippool_free(dhcp_ippool);
+ dhcp_ippool = NULL;
__connman_bridge_remove(BRIDGE_NAME);
@@ -399,7 +403,7 @@ static void remove_private_network(gpointer user_data)
__connman_nat_disable(BRIDGE_NAME);
connman_rtnl_remove_watch(pn->iface_watch);
- __connman_ippool_unref(pn->pool);
+ __connman_ippool_free(pn->pool);
if (pn->watch > 0) {
g_dbus_remove_watch(connection, pn->watch);
diff --git a/unit/test-ippool.c b/unit/test-ippool.c
index 17fac9d9..a6cae652 100644
--- a/unit/test-ippool.c
+++ b/unit/test-ippool.c
@@ -53,7 +53,7 @@ static void test_case_1(void)
pool = __connman_ippool_create(23, 1, 20, NULL, NULL);
g_assert(pool);
- __connman_ippool_unref(pool);
+ __connman_ippool_free(pool);
}
__connman_ippool_cleanup();
@@ -92,7 +92,7 @@ static void test_case_2(void)
"\tgateway %s broadcast %s mask %s", start_ip, end_ip,
gateway, broadcast, subnet_mask);
- __connman_ippool_unref(pool);
+ __connman_ippool_free(pool);
}
__connman_ippool_cleanup();
@@ -157,7 +157,7 @@ static void test_case_3(void)
for (it = list; it; it = it->next) {
pool = it->data;
- __connman_ippool_unref(pool);
+ __connman_ippool_free(pool);
}
g_slist_free(list);
@@ -219,7 +219,7 @@ static void test_case_4(void)
g_assert(flag == 1);
- __connman_ippool_unref(pool);
+ __connman_ippool_free(pool);
flag = 0;
@@ -246,7 +246,7 @@ static void test_case_4(void)
g_assert(flag == 1);
- __connman_ippool_unref(pool);
+ __connman_ippool_free(pool);
__connman_ippool_cleanup();
}
@@ -330,8 +330,8 @@ static void test_case_5(void)
g_assert(flag == 0);
- __connman_ippool_unref(pool1);
- __connman_ippool_unref(pool2);
+ __connman_ippool_free(pool1);
+ __connman_ippool_free(pool2);
__connman_ippool_cleanup();
}
@@ -425,8 +425,8 @@ static void test_case_6(void)
__connman_ippool_newaddr(25, start_ip, 24);
g_assert(flag == 1);
- __connman_ippool_unref(pool1);
- __connman_ippool_unref(pool2);
+ __connman_ippool_free(pool1);
+ __connman_ippool_free(pool2);
__connman_ippool_cleanup();
}
--
2.17.1
------------------------------
Subject: Digest Footer
_______________________________________________
connman mailing list
[email protected]
https://lists.01.org/mailman/listinfo/connman
------------------------------
End of connman Digest, Vol 33, Issue 2
**************************************