diff mbox series

[kvm-unit-tests,4/4] arm/arm64: Add sanity checks to the cpumask API

Message ID 20210319122414.129364-5-nikos.nikoleris@arm.com (mailing list archive)
State New, archived
Headers show
Series RFC: Minor arm/arm64 MMU fixes and checks | expand

Commit Message

Nikos Nikoleris March 19, 2021, 12:24 p.m. UTC
Make sure that any calls to the cpumask API target a valid CPU. The
CPU is identified by an int in the range [0, nr_cpus), where nr_cpus
is set based on information in the DT.

Signed-off-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
---
 lib/arm/asm/cpumask.h | 5 +++++
 1 file changed, 5 insertions(+)
diff mbox series

Patch

diff --git a/lib/arm/asm/cpumask.h b/lib/arm/asm/cpumask.h
index 02124de..3fa57bf 100644
--- a/lib/arm/asm/cpumask.h
+++ b/lib/arm/asm/cpumask.h
@@ -20,26 +20,31 @@  typedef struct cpumask {
 
 static inline void cpumask_set_cpu(int cpu, cpumask_t *mask)
 {
+	assert(cpu >= 0 && cpu < nr_cpus);
 	set_bit(cpu, cpumask_bits(mask));
 }
 
 static inline void cpumask_clear_cpu(int cpu, cpumask_t *mask)
 {
+	assert(cpu >= 0 && cpu < nr_cpus);
 	clear_bit(cpu, cpumask_bits(mask));
 }
 
 static inline int cpumask_test_cpu(int cpu, const cpumask_t *mask)
 {
+	assert(cpu >= 0 && cpu < nr_cpus);
 	return test_bit(cpu, cpumask_bits(mask));
 }
 
 static inline int cpumask_test_and_set_cpu(int cpu, cpumask_t *mask)
 {
+	assert(cpu >= 0 && cpu < nr_cpus);
 	return test_and_set_bit(cpu, cpumask_bits(mask));
 }
 
 static inline int cpumask_test_and_clear_cpu(int cpu, cpumask_t *mask)
 {
+	assert(cpu >= 0 && cpu < nr_cpus);
 	return test_and_clear_bit(cpu, cpumask_bits(mask));
 }