lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Fri, 24 May 2013 09:36:49 +0100
From:	"David Laight" <David.Laight@...LAB.COM>
To:	"Shahed Shaikh" <shahed.shaikh@...gic.com>, <davem@...emloft.net>
Cc:	<netdev@...r.kernel.org>, <Dept_NX_Linux_NIC_Driver@...gic.com>,
	"Jitendra Kalsaria" <jitendra.kalsaria@...gic.com>
Subject: RE: [PATCH net-next 06/12] qlcnic: Convert nested if-else to switch-case

> -
> -	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@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ