@@ -712,11 +712,52 @@ static s64 arm64_ftr_safe_value(const struct arm64_ftr_bits *ftrp, s64 new,
712
712
713
713
static void __init sort_ftr_regs (void )
714
714
{
715
- int i ;
715
+ unsigned int i ;
716
+
717
+ for (i = 0 ; i < ARRAY_SIZE (arm64_ftr_regs ); i ++ ) {
718
+ const struct arm64_ftr_reg * ftr_reg = arm64_ftr_regs [i ].reg ;
719
+ const struct arm64_ftr_bits * ftr_bits = ftr_reg -> ftr_bits ;
720
+ unsigned int j = 0 ;
721
+
722
+ /*
723
+ * Features here must be sorted in descending order with respect
724
+ * to their shift values and should not overlap with each other.
725
+ */
726
+ for (; ftr_bits -> width != 0 ; ftr_bits ++ , j ++ ) {
727
+ unsigned int width = ftr_reg -> ftr_bits [j ].width ;
728
+ unsigned int shift = ftr_reg -> ftr_bits [j ].shift ;
729
+ unsigned int prev_shift ;
730
+
731
+ WARN ((shift + width ) > 64 ,
732
+ "%s has invalid feature at shift %d\n" ,
733
+ ftr_reg -> name , shift );
734
+
735
+ /*
736
+ * Skip the first feature. There is nothing to
737
+ * compare against for now.
738
+ */
739
+ if (j == 0 )
740
+ continue ;
716
741
717
- /* Check that the array is sorted so that we can do the binary search */
718
- for (i = 1 ; i < ARRAY_SIZE (arm64_ftr_regs ); i ++ )
742
+ prev_shift = ftr_reg -> ftr_bits [j - 1 ].shift ;
743
+ WARN ((shift + width ) > prev_shift ,
744
+ "%s has feature overlap at shift %d\n" ,
745
+ ftr_reg -> name , shift );
746
+ }
747
+
748
+ /*
749
+ * Skip the first register. There is nothing to
750
+ * compare against for now.
751
+ */
752
+ if (i == 0 )
753
+ continue ;
754
+ /*
755
+ * Registers here must be sorted in ascending order with respect
756
+ * to sys_id for subsequent binary search in get_arm64_ftr_reg()
757
+ * to work correctly.
758
+ */
719
759
BUG_ON (arm64_ftr_regs [i ].sys_id < arm64_ftr_regs [i - 1 ].sys_id );
760
+ }
720
761
}
721
762
722
763
/*
0 commit comments