[PATCH i-g-t 02/10] lib/xe: Use stricter line-equality check when checking for workarounds

Gustavo Sousa <[email protected]>
Newsgroups org.freedesktop.lists.igt-dev
Message-ID <[email protected]>
Currently debugfs_file_has_wa() uses strstr() to check if a workaround
name is present in the debugfs dump.  Using strstr() would match the
workaround name anywhere in the dump buffer and with that we risk
producing unexpected results if the checked workaround name happens to
be a substring of another workaround present in the dump.

Fix that by making sure we match the workaround name with the full
line from the dump.

Signed-off-by: Gustavo Sousa <[email protected]>
---
 lib/xe/xe_wa.c | 39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/lib/xe/xe_wa.c b/lib/xe/xe_wa.c
index ff5daf529831..d44431e7e61f 100644
--- a/lib/xe/xe_wa.c
+++ b/lib/xe/xe_wa.c
@@ -13,6 +13,43 @@
 #include "xe/xe_wa.h"
 #include "xe/xe_query.h"
 
+static bool debugfs_dump_has_wa(char *dump, const char *wa)
+{
+	char *a = dump;
+
+	while (*a) {
+		const char *b = wa;
+
+		/*
+		 * Each workaround name is indented by one tab
+		 * character; unindented lines are used as "section
+		 * names" identifying the type of workarounds that
+		 * follow (e.g. "GT Workarounds", "Engine Workarounds"
+		 * etc).
+		 */
+		if (*a++ != '\t')
+			goto next_line;
+
+		while (*a == *b && !(*a == '\0' || *a == '\n' || *b == '\0')) {
+			a++;
+			b++;
+		}
+
+		if ((*a == '\0' || *a == '\n') && *b == '\0')
+			return true;
+
+	next_line:
+		/* No match for this line, advance to the next one. */
+		while (*a != '\n' && *a != '\0')
+			a++;
+
+		if (*a == '\n')
+			a++;
+	}
+
+	return false;
+}
+
 static int debugfs_file_has_wa(int drm_fd, int debugfs_fd,
 			       const char *debugfs_name, const char *wa)
 {
@@ -23,7 +60,7 @@ static int debugfs_file_has_wa(int drm_fd, int debugfs_fd,
 
 	debugfs_dump = igt_sysfs_get(debugfs_fd, debugfs_name);
 	if (debugfs_dump) {
-		char *has_wa = strstr(debugfs_dump, wa);
+		bool has_wa = debugfs_dump_has_wa(debugfs_dump, wa);
 
 		free(debugfs_dump);
 

-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.