[nss-drv] Use goto to reduce repeated code
Change-Id: Ia68d16df2c295023325d080bea6f818aae73ee6f
Signed-off-by: Stephen Wang <wstephen@codeaurora.org>
diff --git a/nss_ipv4.c b/nss_ipv4.c
index 2825370..da44fdc 100644
--- a/nss_ipv4.c
+++ b/nss_ipv4.c
@@ -343,19 +343,14 @@
nss_ipv4_conn_cfg,
NSS_MIN_NUM_CONN,
NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6);
-
- /*
- * Restore the current_value to its previous state
- */
- nss_ipv4_conn_cfg = i4cfgp.current_value;
- up(&i4cfgp.sem);
- return NSS_FAILURE;
+ goto failure;
}
nss_info("%p: IPv4 supported connections: %d\n", nss_ctx, nss_ipv4_conn_cfg);
nss_ipv4_msg_init(&nim, NSS_IPV4_RX_INTERFACE, NSS_IPV4_TX_CONN_CFG_RULE_MSG,
- sizeof(struct nss_ipv4_rule_conn_cfg_msg), (nss_ipv4_msg_callback_t *)nss_ipv4_conn_cfg_callback, NULL);
+ sizeof(struct nss_ipv4_rule_conn_cfg_msg),
+ (nss_ipv4_msg_callback_t *)nss_ipv4_conn_cfg_callback, NULL);
nirccm = &nim.msg.rule_conn_cfg;
nirccm->num_conn = htonl(nss_ipv4_conn_cfg);
@@ -365,13 +360,7 @@
nss_warning("%p: nss_tx error setting IPv4 Connections: %d\n",
nss_ctx,
nss_ipv4_conn_cfg);
-
- /*
- * Restore the current_value to its previous state
- */
- nss_ipv4_conn_cfg = i4cfgp.current_value;
- up(&i4cfgp.sem);
- return NSS_FAILURE;
+ goto failure;
}
/*
@@ -380,13 +369,7 @@
ret = wait_for_completion_timeout(&i4cfgp.complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
if (ret == 0) {
nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
-
- /*
- * Restore the current_value to its previous state
- */
- nss_ipv4_conn_cfg = i4cfgp.current_value;
- up(&i4cfgp.sem);
- return NSS_FAILURE;
+ goto failure;
}
/*
@@ -395,17 +378,19 @@
* i4cfgp.num_conn_valid, which holds the user input
*/
if (NSS_FAILURE == i4cfgp.response) {
-
- /*
- * Restore the current_value to its previous state
- */
- nss_ipv4_conn_cfg = i4cfgp.current_value;
- up(&i4cfgp.sem);
- return NSS_FAILURE;
+ goto failure;
}
up(&i4cfgp.sem);
return NSS_SUCCESS;
+
+failure:
+ /*
+ * Restore the current_value to its previous state
+ */
+ nss_ipv4_conn_cfg = i4cfgp.current_value;
+ up(&i4cfgp.sem);
+ return NSS_FAILURE;
}
static ctl_table nss_ipv4_table[] = {
diff --git a/nss_ipv6.c b/nss_ipv6.c
index 2725c20..6256415 100644
--- a/nss_ipv6.c
+++ b/nss_ipv6.c
@@ -341,13 +341,7 @@
nss_ipv6_conn_cfg,
NSS_MIN_NUM_CONN,
NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6);
-
- /*
- * Restore the current_value to its previous state
- */
- nss_ipv6_conn_cfg = i6cfgp.current_value;
- up(&i6cfgp.sem);
- return NSS_FAILURE;
+ goto failure;
}
@@ -364,13 +358,7 @@
nss_warning("%p: nss_tx error setting IPv6 Connections: %d\n",
nss_ctx,
nss_ipv6_conn_cfg);
-
- /*
- * Restore the current_value to its previous state
- */
- nss_ipv6_conn_cfg = i6cfgp.current_value;
- up(&i6cfgp.sem);
- return NSS_FAILURE;
+ goto failure;
}
/*
@@ -379,13 +367,7 @@
ret = wait_for_completion_timeout(&i6cfgp.complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
if (ret == 0) {
nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
-
- /*
- * Restore the current_value to its previous state
- */
- nss_ipv6_conn_cfg = i6cfgp.current_value;
- up(&i6cfgp.sem);
- return NSS_FAILURE;
+ goto failure;
}
/*
@@ -394,16 +376,19 @@
* i6cfgp.num_conn_valid, which holds the user input
*/
if (NSS_FAILURE == i6cfgp.response) {
- /*
- * Restore the current_value to its previous state
- */
- nss_ipv6_conn_cfg = i6cfgp.current_value;
- up(&i6cfgp.sem);
- return NSS_FAILURE;
+ goto failure;
}
up(&i6cfgp.sem);
return NSS_SUCCESS;
+
+failure:
+ /*
+ * Restore the current_value to its previous state
+ */
+ nss_ipv6_conn_cfg = i6cfgp.current_value;
+ up(&i6cfgp.sem);
+ return NSS_FAILURE;
}
static ctl_table nss_ipv6_table[] = {
diff --git a/nss_n2h.c b/nss_n2h.c
index f28a785..4300fe3 100755
--- a/nss_n2h.c
+++ b/nss_n2h.c
@@ -280,13 +280,7 @@
if ((*new_val < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ)) {
nss_warning("%p: core %d setting %d is less than minimum number of buffer",
nss_ctx, core_num, *new_val);
-
- /*
- * Restore the current_value to its previous state
- */
- *new_val = nss_n2h_nepbcfgp[core_num].current_value;
- up(&nss_n2h_nepbcfgp[core_num].sem);
- return NSS_FAILURE;
+ goto failure;
}
nss_info("%p: core %d number of empty pool buffer is : %d\n",
@@ -305,13 +299,7 @@
if (nss_tx_status != NSS_TX_SUCCESS) {
nss_warning("%p: core %d nss_tx error setting empty pool buffer: %d\n",
nss_ctx, core_num, *new_val);
-
- /*
- * Restore the current_value to its previous state
- */
- *new_val = nss_n2h_nepbcfgp[core_num].current_value;
- up(&nss_n2h_nepbcfgp[core_num].sem);
- return NSS_FAILURE;
+ goto failure;
}
/*
@@ -320,13 +308,7 @@
ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
if (ret == 0) {
nss_warning("%p: core %d Waiting for ack timed out\n", nss_ctx, core_num);
-
- /*
- * Restore the current_value to its previous state
- */
- *new_val = nss_n2h_nepbcfgp[core_num].current_value;
- up(&nss_n2h_nepbcfgp[core_num].sem);
- return NSS_FAILURE;
+ goto failure;
}
/*
@@ -335,17 +317,19 @@
* nss_n2h_nepbcfgp.num_conn_valid, which holds the user input
*/
if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response) {
-
- /*
- * Restore the current_value to its previous state
- */
- *new_val = nss_n2h_nepbcfgp[core_num].current_value;
- up(&nss_n2h_nepbcfgp[core_num].sem);
- return NSS_FAILURE;
+ goto failure;
}
up(&nss_n2h_nepbcfgp[core_num].sem);
return NSS_SUCCESS;
+
+failure:
+ /*
+ * Restore the current_value to its previous state
+ */
+ *new_val = nss_n2h_nepbcfgp[core_num].current_value;
+ up(&nss_n2h_nepbcfgp[core_num].sem);
+ return NSS_FAILURE;
}
/*