Fix race condition in SError inject test

tftf/tests/misc_tests/inject_serror.S clears a flag, serror_received,
then waits for it to be set by an error handler. However, it
currently clears the flag after having started the count down timer
to generate the error, so there is a data race between it and
the error handler.
This can cause the test to fail, if the error is generated and the
flag set before it is first cleared.

Fix this by clearing the serror_received flag before starting the
count down timer.

Change-Id: I919ef2a1bba66b19f47bccfcdbee944357881e8f
Signed-off-by: David Horstmann <david.horstmann@arm.com>
diff --git a/tftf/tests/misc_tests/inject_serror.S b/tftf/tests/misc_tests/inject_serror.S
index 008503f..d42441d 100644
--- a/tftf/tests/misc_tests/inject_serror.S
+++ b/tftf/tests/misc_tests/inject_serror.S
@@ -16,9 +16,7 @@
 
 /*
  * Program fault injection register, and wait for ever for the fault to trigger.
- * Note that Trusted Firmware must be compiled for ARMv8.4 along with
- * FAULT_INJECTION_SUPPORT=1 for this to work. Besides, the model has to be
- * launched with fault inject support.
+ * Note that the model must be launched with fault inject support.
  *
  * x0: Fault record number to program
  * x1: Injected fault properties
@@ -26,6 +24,10 @@
  * x3: Memory location to wait for, or 0 if no waiting is required
  */
 func inject_serror_record
+	/* Clear SError received flag if necessary */
+	cbz	x3, 1f
+	str	xzr, [x3, #0]
+1:
 	/* Choose Error record 0 on the PE */
 	msr	ERRSELR_EL1, x0
 	isb
@@ -43,18 +45,17 @@
 	msr	ERXPFGCTL_EL1, x2
 	isb
 
-	cbz	x3, 2f
+	/* If no waiting is required, jump to end */
+	cbz	x3, 3f
 
-	/* Clear SError received flag */
-	str	xzr, [x3, #0]
 	sevl
 
-1:
+2:
 	wfe
 	ldr	x0, [x3, #0]
-	cbz	x0, 1b
+	cbz	x0, 2b
 
-2:
+3:
 	ret
 endfunc inject_serror_record