Skip to contentSkip to conversation

linux/cpumask.h: add typechecking to cpumask_test_cpu

PATCH Applied Rasmus Villemoes 2 participants 2 messages Mar 30, 2015 – Mar 31, 2015 Bitmap API

lore
Share & tools
lore

Rasmus Villemoes

author reviewer
#0 lore raw

PATCH 1/1 linux/cpumask.h: add typechecking to cpumask_test_cpu

The Subtlety (1) referred to vanished with 6ba2ef7baac2 ("cpumask:
Move deprecated functions to end of header."). That used to mention some suboptimal code generation by a, by now, rather ancient gcc. With gcc 4.7, I don't see any change in the generated code by making it a static inline, so let's add type checking and get rid of the ghost reference.

---
 include/linux/cpumask.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/linux/cpumask.h +4 -4
index 086549a665e2..972c30e0714e 100644
@@ -289,11 +289,11 @@ static inline void cpumask_clear_cpu(int cpu, struct cpumask *dstp)
  * @cpumask: the cpumask pointer
  *
  * Returns 1 if @cpu is set in @cpumask, else returns 0
- *
- * No static inline type checking - see Subtlety (1) above.
  */
-#define cpumask_test_cpu(cpu, cpumask) \
-	test_bit(cpumask_check(cpu), cpumask_bits((cpumask)))
+static inline int cpumask_test_cpu(int cpu, const struct cpumask *cpumask)
+{
+	return test_bit(cpumask_check(cpu), cpumask_bits((cpumask)));
+}
 
 /**
  * cpumask_test_and_set_cpu - atomically test and set a cpu in a cpumask
Signature · 1 line
2.1.3
#1 lore raw
Quoted 8 lines · Rasmus Villemoes

The Subtlety (1) referred to vanished with 6ba2ef7baac2 ("cpumask:
Move deprecated functions to end of header."). That used to mention some suboptimal code generation by a, by now, rather ancient gcc. With gcc 4.7, I don't see any change in the generated code by making it a static inline, so let's add type checking and get rid of the ghost reference.

Thanks, applied.

Cheers,
Rusty.

Quoted 26 lines
---
 include/linux/cpumask.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/linux/cpumask.h +4 -4
index 086549a665e2..972c30e0714e 100644
@@ -289,11 +289,11 @@ static inline void cpumask_clear_cpu(int cpu, struct cpumask *dstp)
  * @cpumask: the cpumask pointer
  *
  * Returns 1 if @cpu is set in @cpumask, else returns 0
- *
- * No static inline type checking - see Subtlety (1) above.
  */
-#define cpumask_test_cpu(cpu, cpumask) \
-	test_bit(cpumask_check(cpu), cpumask_bits((cpumask)))
+static inline int cpumask_test_cpu(int cpu, const struct cpumask *cpumask)
+{
+	return test_bit(cpumask_check(cpu), cpumask_bits((cpumask)));
+}
 
 /**
  * cpumask_test_and_set_cpu - atomically test and set a cpu in a cpumask
Signature · 1 line
2.1.3