Check as much as possible before taking lock.
Change-Id: I03d71da369c01ef25939ddf2301dc8d989f94917
diff --git a/src/api.c b/src/api.c
index d131ca1..f9f3ceb 100644
--- a/src/api.c
+++ b/src/api.c
@@ -964,6 +964,12 @@
return spci_error(SPCI_INVALID_PARAMETERS);
}
+ /* Ensure the receiver VM exists. */
+ to = vm_find(receiver_vm_id);
+ if (to == NULL) {
+ return spci_error(SPCI_INVALID_PARAMETERS);
+ }
+
/*
* Check that the sender has configured its send buffer. If the tx
* mailbox at from_msg is configured (i.e. from_msg != NULL) then it can
@@ -978,12 +984,6 @@
return spci_error(SPCI_INVALID_PARAMETERS);
}
- /* Ensure the receiver VM exists. */
- to = vm_find(receiver_vm_id);
- if (to == NULL) {
- return spci_error(SPCI_INVALID_PARAMETERS);
- }
-
/*
* Hafnium needs to hold the lock on <to> before the mailbox state is
* checked. The lock on <to> must be held until the information is