]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
riscv: cpu: improve multi-letter extension detection in supports_extension()
authorConor Dooley <conor.dooley@microchip.com>
Mon, 4 Mar 2024 23:28:35 +0000 (23:28 +0000)
committerLeo Yu-Chi Liang <ycliang@andestech.com>
Tue, 12 Mar 2024 06:36:13 +0000 (14:36 +0800)
The first multi-letter extension after the single-letter extensions does
not have to be preceded by an underscore, which could cause the parser
to mistakenly find a single-letter extension after the start of the
multi-letter portion of the string.
Three letters precede multi-letter extensions (s, x & z), none of which
are valid single-letter extensions. The dt-binding also allows
multi-letter extensions starting with h, but no such extension have been
frozen or ratified, and the unprivileged spec no longer uses "h" as a
prefix for multi-letter hypervisor extensions, having moved to "sh"
instead. For that reason, modify the parser to stop at s, x & z to prevent
this overrun, ignoring h.

Signed-off-by: Conor Dooley <conor.dooley@microchip.com>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
arch/riscv/cpu/cpu.c

index 8445c5823e178cc61e786373434c29d807ee88ca..ecfefa1a0258403ca0fc13aabadc12aff054672b 100644 (file)
@@ -49,14 +49,24 @@ static inline bool supports_extension(char ext)
        }
        if (!cpu_get_desc(dev, desc, sizeof(desc))) {
                /*
-                * skip the first 4 characters (rv32|rv64) and
-                * check until underscore
+                * skip the first 4 characters (rv32|rv64)
                 */
                for (i = 4; i < sizeof(desc); i++) {
-                       if (desc[i] == '_' || desc[i] == '\0')
-                               break;
-                       if (desc[i] == ext)
-                               return true;
+                       switch (desc[i]) {
+                       case 's':
+                       case 'x':
+                       case 'z':
+                       case '_':
+                       case '\0':
+                               /*
+                                * Any of these characters mean the single
+                                * letter extensions have all been consumed.
+                                */
+                               return false;
+                       default:
+                               if (desc[i] == ext)
+                                       return true;
+                       }
                }
        }