Skip to contentSkip to conversation

arm64: cpufeature: Warn if we attempt to read a zero width field

PATCH Superseded Mark Brown 2 participants 2 messages Mar 2, 2022 – Mar 7, 2022 arm64

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH 1/1 arm64: cpufeature: Warn if we attempt to read a zero width field

Add a WARN_ON_ONCE() when extracting a field if no width is specified. This should never happen outside of development since it will be triggered with or without the feature so long as the relevant ID register is present.

---
 arch/arm64/include/asm/cpufeature.h | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/include/asm/cpufeature.h +1 -0
index 2fe54369ac3f..4c8badfa9e8b 100644
@@ -577,6 +577,7 @@ static inline u64 arm64_ftr_reg_user_value(const struct arm64_ftr_reg *reg)
 static inline int __attribute_const__
 cpuid_feature_extract_field_width(u64 features, int field, int width, bool sign)
 {
+	WARN_ON_ONCE(!width);
 	return (sign) ?
 		cpuid_feature_extract_signed_field_width(features, field, width) :
 		cpuid_feature_extract_unsigned_field_width(features, field, width);
Signature · 7 lines
2.30.2


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
maintainer
#1 lore raw
Quoted 15 lines · Mark Brown

Add a WARN_ON_ONCE() when extracting a field if no width is specified. This should never happen outside of development since it will be triggered with or without the feature so long as the relevant ID register is present.

---
 arch/arm64/include/asm/cpufeature.h | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/include/asm/cpufeature.h +0 -0
index 2fe54369ac3f..4c8badfa9e8b 100644

arch/arm64/include/asm/cpufeature.h static inline u64 arm64_ftr_reg_user_value(const struct arm64_ftr_reg *reg) · line 580

Quoted 4 lines
arch/arm64/include/asm/cpufeature.h +1 -0
@@ -577,6 +577,7 @@ static inline u64 arm64_ftr_reg_user_value(const struct arm64_ftr_reg *reg)
 static inline int __attribute_const__
 cpuid_feature_extract_field_width(u64 features, int field, int width, bool sign)
 {
+	WARN_ON_ONCE(!width);

I think this makes sense, but lets also override width to be 4 in this case, as that is much more likely to "work" than 0. i.e.

	if (WARN_ON_ONCE(!width))
		width = 4;

Will

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel