fix(indirect message): fix flags check in  FFA_MSG_SEND2

Change-Id: I9e80be7d0e58623f97e338e4e865cfe4a5c151a0
Signed-off-by: Federico Recanati <federico.recanati@arm.com>
diff --git a/src/api.c b/src/api.c
index 39b6298..f696a14 100644
--- a/src/api.c
+++ b/src/api.c
@@ -1631,12 +1631,6 @@
 		return ffa_error(FFA_INVALID_PARAMETERS);
 	}
 
-	/* `flags` can be set only at secure virtual FF-A instances. */
-	if (plat_ffa_is_vm_id(sender_vm_id) && (flags != 0)) {
-		dlog_error("flags must be zero.\n");
-		return ffa_error(FFA_INVALID_PARAMETERS);
-	}
-
 	/*
 	 * Get message sender's mailbox, which can be different to the `from` vm
 	 * when the message is forwarded.
@@ -1683,6 +1677,12 @@
 		goto out_unlock_sender;
 	}
 
+	/* `flags` can be set only at secure virtual FF-A instances. */
+	if (plat_ffa_is_vm_id(sender_id) && (flags != 0)) {
+		dlog_error("flags must be zero.\n");
+		return ffa_error(FFA_INVALID_PARAMETERS);
+	}
+
 	/*
 	 * Check if the message has to be forwarded to the SPMC, in
 	 * this case return, the SPMC will handle the buffer copy.