Signed-off-by: Alexander Gordeev <[email protected]>
---
arch/x86/kernel/apic/apic.c | 8 ++++----
arch/x86/kernel/apic/es7000_32.c | 2 +-
arch/x86/kernel/apic/summit_32.c | 2 +-
arch/x86/kernel/apic/x2apic_uv_x.c | 8 ++++----
4 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 048a4f8..c421512 100644
--- 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;
}
/*
diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
index 2c5317e..effece2 100644
--- a/arch/x86/kernel/apic/es7000_32.c
+++ b/arch/x86/kernel/apic/es7000_32.c
@@ -529,7 +529,7 @@ static inline int
es7000_cpu_mask_to_apicid(const struct cpumask *cpumask, unsigned int *dest_id)
{
unsigned int round = 0;
- int cpu, uninitialized_var(apicid);
+ unsigned int cpu, uninitialized_var(apicid);
/*
* The cpus in the mask must all be on the apic cluster.
diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
index bbad180..b53fd6c 100644
--- a/arch/x86/kernel/apic/summit_32.c
+++ b/arch/x86/kernel/apic/summit_32.c
@@ -267,7 +267,7 @@ static inline int
summit_cpu_mask_to_apicid(const struct cpumask *cpumask, unsigned int *dest_id)
{
unsigned int round = 0;
- int cpu, apicid = 0;
+ unsigned int cpu, apicid = 0;
/*
* The cpus in the mask must all be on the apic cluster.
diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
index 026de01..8cfade9 100644
--- a/arch/x86/kernel/apic/x2apic_uv_x.c
+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
@@ -274,7 +274,7 @@ uv_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
const struct cpumask *andmask,
unsigned int *apicid)
{
- int cpu;
+ int unsigned cpu;
/*
* We're using fixed IRQ delivery, can only return one phys APIC ID.
@@ -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;
}
static unsigned int x2apic_get_apic_id(unsigned long x)
--
1.7.7.6
--
Regards,
Alexander Gordeev
[email protected]
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
Commit-ID: ea3807ea52a53f2cdfd60c89d8491fc9a8208d1c
Gitweb: http://git.kernel.org/tip/ea3807ea52a53f2cdfd60c89d8491fc9a8208d1c
Author: Alexander Gordeev <[email protected]>
AuthorDate: Thu, 14 Jun 2012 09:49:55 +0200
Committer: Ingo Molnar <[email protected]>
CommitDate: Thu, 14 Jun 2012 12:53:14 +0200
x86/apic: Fix ugly casting and branching in cpu_mask_to_apicid_and()
Signed-off-by: Alexander Gordeev <[email protected]>
Cc: Suresh Siddha <[email protected]>
Cc: Yinghai Lu <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
---
arch/x86/kernel/apic/apic.c | 8 ++++----
arch/x86/kernel/apic/es7000_32.c | 2 +-
arch/x86/kernel/apic/summit_32.c | 2 +-
arch/x86/kernel/apic/x2apic_uv_x.c | 8 ++++----
4 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 048a4f8..c421512 100644
--- 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;
}
/*
diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
index 2c5317e..effece2 100644
--- a/arch/x86/kernel/apic/es7000_32.c
+++ b/arch/x86/kernel/apic/es7000_32.c
@@ -529,7 +529,7 @@ static inline int
es7000_cpu_mask_to_apicid(const struct cpumask *cpumask, unsigned int *dest_id)
{
unsigned int round = 0;
- int cpu, uninitialized_var(apicid);
+ unsigned int cpu, uninitialized_var(apicid);
/*
* The cpus in the mask must all be on the apic cluster.
diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
index bbad180..b53fd6c 100644
--- a/arch/x86/kernel/apic/summit_32.c
+++ b/arch/x86/kernel/apic/summit_32.c
@@ -267,7 +267,7 @@ static inline int
summit_cpu_mask_to_apicid(const struct cpumask *cpumask, unsigned int *dest_id)
{
unsigned int round = 0;
- int cpu, apicid = 0;
+ unsigned int cpu, apicid = 0;
/*
* The cpus in the mask must all be on the apic cluster.
diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
index 026de01..8cfade9 100644
--- a/arch/x86/kernel/apic/x2apic_uv_x.c
+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
@@ -274,7 +274,7 @@ uv_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
const struct cpumask *andmask,
unsigned int *apicid)
{
- int cpu;
+ int unsigned cpu;
/*
* We're using fixed IRQ delivery, can only return one phys APIC ID.
@@ -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;
}
static unsigned int x2apic_get_apic_id(unsigned long x)