diff mbox

[net-next,06/12] qlcnic: Convert nested if-else to switch-case

Message ID 1369379076-4718-7-git-send-email-shahed.shaikh@qlogic.com
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

Shahed Shaikh May 24, 2013, 7:04 a.m. UTC
From: Jitendra Kalsaria <jitendra.kalsaria@qlogic.com>

Signed-off-by: Jitendra Kalsaria <jitendra.kalsaria@qlogic.com>
Signed-off-by: Shahed Shaikh <shahed.shaikh@qlogic.com>
---
 .../net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c  |   18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)

Comments

David Laight May 24, 2013, 8:36 a.m. UTC | #1
> -
> -	if (priv_level == QLCNIC_NON_PRIV_FUNC) {
> +	switch (priv_level) {
> +	case QLCNIC_NON_PRIV_FUNC:
>  		ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
>  		ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
>  		nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
> -	} else if (priv_level == QLCNIC_PRIV_FUNC) {
> +		break;
> +	case QLCNIC_PRIV_FUNC:
>  		ahw->op_mode = QLCNIC_PRIV_FUNC;
>  		ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
>  		nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
> -	} else if (priv_level == QLCNIC_MGMT_FUNC) {
> +		break;
> +	case QLCNIC_MGMT_FUNC:
>  		ahw->op_mode = QLCNIC_MGMT_FUNC;
>  		ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
>  		nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
> -	} else {
> +		break;
> +	default:
> +		dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
>  		return -EIO;
>  	}

If the NON_PRIV case happens most of the time, then the old code would
have a single conditional branch that could easily be predicted correctly.
The switch statement version will either be a compare and an indirect jump
(a pipeline stall on a lot of cpus) or a compare-branch chain.

So this is necessarily an improvent!

	David



--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
index 55e5e1b..b5054e1 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
@@ -187,20 +187,24 @@  int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
 	else
 		priv_level = QLC_83XX_GET_FUNC_PRIVILEGE(op_mode,
 							 ahw->pci_func);
-
-	if (priv_level == QLCNIC_NON_PRIV_FUNC) {
+	switch (priv_level) {
+	case QLCNIC_NON_PRIV_FUNC:
 		ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
 		ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
 		nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
-	} else if (priv_level == QLCNIC_PRIV_FUNC) {
+		break;
+	case QLCNIC_PRIV_FUNC:
 		ahw->op_mode = QLCNIC_PRIV_FUNC;
 		ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
 		nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
-	} else if (priv_level == QLCNIC_MGMT_FUNC) {
+		break;
+	case QLCNIC_MGMT_FUNC:
 		ahw->op_mode = QLCNIC_MGMT_FUNC;
 		ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
 		nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
-	} else {
+		break;
+	default:
+		dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
 		return -EIO;
 	}
 
@@ -209,8 +213,8 @@  int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
 	else
 		adapter->flags &= ~QLCNIC_ESWITCH_ENABLED;
 
-	adapter->ahw->idc.vnic_state = QLCNIC_DEV_NPAR_NON_OPER;
-	adapter->ahw->idc.vnic_wait_limit = QLCNIC_DEV_NPAR_OPER_TIMEO;
+	ahw->idc.vnic_state = QLCNIC_DEV_NPAR_NON_OPER;
+	ahw->idc.vnic_wait_limit = QLCNIC_DEV_NPAR_OPER_TIMEO;
 
 	return 0;
 }