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]
Message-ID: <1339678809.24180.5.camel@joe2Laptop>
Date:	Thu, 14 Jun 2012 06:00:09 -0700
From:	Joe Perches <joe@...ches.com>
To:	Alexander Gordeev <agordeev@...hat.com>
Cc:	linux-kernel@...r.kernel.org, x86@...nel.org,
	Suresh Siddha <suresh.b.siddha@...el.com>,
	Yinghai Lu <yinghai@...nel.org>
Subject: Re: [PATCH 3/6] x86/apic: Fix ugly casting and branching in
 cpu_mask_to_apicid_and()

On Thu, 2012-06-14 at 09:49 +0200, Alexander Gordeev wrote:
[]
> diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
[]
> @@ -2127,19 +2127,19 @@ int default_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
>  				   const struct cpumask *andmask,
>  				   unsigned int *apicid)
>  {
> -	int cpu;
> +	unsigned int cpu;
>  
>  	for_each_cpu_and(cpu, cpumask, andmask) {
>  		if (cpumask_test_cpu(cpu, cpu_online_mask))
>  			break;
>  	}
>  
> -	if (likely((unsigned int)cpu < nr_cpu_ids)) {
> +	if (likely(cpu < nr_cpu_ids)) {
>  		*apicid = per_cpu(x86_cpu_to_apicid, cpu);
>  		return 0;
> -	} else {
> -		return -EINVAL;
>  	}
> +
> +	return -EINVAL;

I think you should reverse the test and make the
expected common case the normal non-indented return.

	if (unlikely(cpu >= nr_cpu_ids))
		return -EINVAL;

	*apicid = per_cpu(x86_cpu_to_apicid, cpu);
	return 0;
}

Perhaps the unlikely isn't necessary.

> diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
[]
> @@ -285,12 +285,12 @@ uv_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
>  			break;
>  	}
>  
> -	if (likely((unsigned int)cpu < nr_cpu_ids)) {
> +	if (likely(cpu < nr_cpu_ids)) {
>  		*apicid = per_cpu(x86_cpu_to_apicid, cpu) | uv_apicid_hibits;
>  		return 0;
> -	} else {
> -		return -EINVAL;
>  	}
> +
> +	return -EINVAL;

here too

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ