tethering: Reset the tethering refcount on error
authorPatrik Flykt <patrik.flykt@linux.intel.com>
Fri, 7 Sep 2012 11:55:10 +0000 (14:55 +0300)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Thu, 13 Sep 2012 10:42:12 +0000 (13:42 +0300)
Decrease the refcount with one on error.

src/tethering.c

index e343237..f3d67df 100644 (file)
@@ -198,8 +198,10 @@ void __connman_tethering_set_enabled(void)
                return;
 
        err = __connman_bridge_create(BRIDGE_NAME);
-       if (err < 0)
+       if (err < 0) {
+               __sync_fetch_and_sub(&tethering_enabled, 1);
                return;
+       }
 
        index = connman_inet_ifindex(BRIDGE_NAME);
        dhcp_ippool = __connman_ippool_create(index, 2, 252,
@@ -207,6 +209,7 @@ void __connman_tethering_set_enabled(void)
        if (dhcp_ippool == NULL) {
                connman_error("Fail to create IP pool");
                __connman_bridge_remove(BRIDGE_NAME);
+               __sync_fetch_and_sub(&tethering_enabled, 1);
                return;
        }
 
@@ -220,6 +223,7 @@ void __connman_tethering_set_enabled(void)
        if (err < 0 && err != -EALREADY) {
                __connman_ippool_unref(dhcp_ippool);
                __connman_bridge_remove(BRIDGE_NAME);
+               __sync_fetch_and_sub(&tethering_enabled, 1);
                return;
        }
 
@@ -238,6 +242,7 @@ void __connman_tethering_set_enabled(void)
                __connman_bridge_disable(BRIDGE_NAME);
                __connman_ippool_unref(dhcp_ippool);
                __connman_bridge_remove(BRIDGE_NAME);
+               __sync_fetch_and_sub(&tethering_enabled, 1);
                return;
        }