[LTP] [PATCH v3] tst_taint: print readable error message instead of numerical codes

Kushal Chand kushalkataria5@gmail.com
Thu Jan 20 17:34:07 CET 2022


This patch stores the possible kernel tainted messages in taint_strings
and corresponding error is printed.

Fixes: #776
---
 lib/tst_taint.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/lib/tst_taint.c b/lib/tst_taint.c
index 49146aacb..e224984f5 100644
--- a/lib/tst_taint.c
+++ b/lib/tst_taint.c
@@ -8,6 +8,27 @@
 
 static unsigned int taint_mask = -1;
 
+static const char * const taint_strings[] = {
+				       "G (Propriety module loaded)",
+				       "F (Module force loaded)",
+				       "S (Running on out of spec system)",
+				       "R (Module force unloaded)",
+				       "M (Machine check exception)",
+				       "B (Bad page reference)",
+				       "U (User request)",
+				       "D (OOPS/BUG)",
+				       "A (ACPI table overridden)",
+				       "W (Warning)",
+				       "C (Staging driver loaded)",
+				       "I (Workaround BIOS/FW bug)",
+				       "O (Out of tree module loaded)",
+				       "E (Unsigned module loaded)",
+				       "L (Soft lock up occured)",
+				       "K (Live patched)",
+				       "X (Auxilary)",
+				       "T (Built with struct randomization)",
+};
+
 static unsigned int tst_taint_read(void)
 {
 	unsigned int val;
@@ -74,6 +95,7 @@ static int tst_taint_check_kver(unsigned int mask)
 void tst_taint_init(unsigned int mask)
 {
 	unsigned int taint = -1;
+	long unsigned int i;
 
 	if (mask == 0)
 		tst_brk(TBROK, "mask is not allowed to be 0");
@@ -90,7 +112,10 @@ void tst_taint_init(unsigned int mask)
 	}
 
 	if ((taint & taint_mask) != 0)
-		tst_brk(TBROK, "Kernel is already tainted: %u", taint);
+		for (i = 0; i < ARRAY_SIZE(taint_strings); i++)
+			if (taint & (1 << i))
+				tst_brk(TBROK, "Kernel is already tainted: %s",
+					taint_strings[i]);
 }
 
 
-- 
2.25.1



More information about the ltp mailing list