@@ -103,42 +103,66 @@ static int timespec_to_char_array(struct timespec64 const *ts,
return 0;
}
-static int idtcm_strverscmp(const char *ver1, const char *ver2)
+static int idtcm_strverscmp(const char *version1, const char *version2)
{
u8 num1;
u8 num2;
int result = 0;
+ char ver1[16];
+ char ver2[16];
+ char *cur1;
+ char *cur2;
+ char *next1;
+ char *next2;
+
+ if (strscpy(ver1, version1, 16) < 0 ||
+ strscpy(ver2, version2, 16) < 0)
+ return -1;
+ cur1 = ver1;
+ cur2 = ver2;
/* loop through each level of the version string */
while (result == 0) {
+ next1 = strchr(cur1, '.');
+ next2 = strchr(cur2, '.');
+
+ /* kstrtou8 could fail for dot */
+ if (next1) {
+ *next1 = '\0';
+ next1++;
+ }
+
+ if (next2) {
+ *next2 = '\0';
+ next2++;
+ }
+
/* extract leading version numbers */
- if (kstrtou8(ver1, 10, &num1) < 0)
+ if (kstrtou8(cur1, 10, &num1) < 0)
return -1;
- if (kstrtou8(ver2, 10, &num2) < 0)
+ if (kstrtou8(cur2, 10, &num2) < 0)
return -1;
/* if numbers differ, then set the result */
if (num1 < num2)
+ return -1;
+ if (num1 > num2)
+ return 1;
+
+ /* if numbers are the same, go to next level */
+ if (!next1 && !next2)
+ break;
+ else if (!next1) {
result = -1;
- else if (num1 > num2)
+ } else if (!next2) {
result = 1;
- else {
- /* if numbers are the same, go to next level */
- ver1 = strchr(ver1, '.');
- ver2 = strchr(ver2, '.');
- if (!ver1 && !ver2)
- break;
- else if (!ver1)
- result = -1;
- else if (!ver2)
- result = 1;
- else {
- ver1++;
- ver2++;
- }
+ } else {
+ cur1 = next1;
+ cur2 = next2;
}
}
+
return result;
}
new file mode 100644
@@ -0,0 +1,12 @@
+ ldh [12]
+ jne #0x8100, nonvlan
+ ldh [16]
+ jne #0x88f7, bad
+ ldb [18]
+ ja test
+ nonvlan: jne #0x88f7, bad
+ ldb [14]
+ test: and #0x8
+ jeq #0, bad
+ good: ret #1500
+ bad: ret #0
new file mode 100644
@@ -0,0 +1,7 @@
+ ldh [12]
+ jne #0x88f7, bad
+ ldb [14]
+ and #0x8
+ jeq #0, bad
+ good: ret #1500
+ bad: ret #0