Fix concurrent access to IDR in kernel driver

The IDR instance must be protected against concurrent access and the
device mutex in the kernel driver should be used to protect it. However,
the device mutex is not locked when an inference is released or when the
mailbox is cleared which means the IDR is not protected in these
instances.

To resolve this, the missing mutex locks have been added and the
functions using the IDR instance have been updated to make it clearer
that the device mutex is expected to be locked when called.

Change-Id: Id0b314db556836c36663d6481806b7c113e55e5f
Signed-off-by: Mikael Olsson <mikael.olsson@arm.com>
diff --git a/kernel/ethosu_mailbox.h b/kernel/ethosu_mailbox.h
index c192b54..ea4409f 100644
--- a/kernel/ethosu_mailbox.h
+++ b/kernel/ethosu_mailbox.h
@@ -50,6 +50,14 @@
 	struct idr            msg_idr;
 };
 
+/**
+ * struct ethosu_mailbox_msg - Mailbox message
+ * @id: Message id
+ * @type: Message request type
+ * @fail: Message failure callback
+ *
+ * The fail callback will be called with the device mutex locked
+ */
 struct ethosu_mailbox_msg {
 	int      id;
 	uint32_t type;
@@ -77,6 +85,8 @@
 /**
  * ethosu_mailbox_register() - Register the ethosu_mailbox_msg in ethosu_mailbox
  *
+ * Context: Must be called with the device mutex locked
+ *
  * Return: 0 on success, else error code.
  */
 int ethosu_mailbox_register(struct ethosu_mailbox *mbox,
@@ -84,6 +94,8 @@
 
 /**
  * ethosu_mailbox_free_id() - Free the id of the ethosu_mailbox_msg
+ *
+ * Context: Must be called with the device mutex locked
  */
 void ethosu_mailbox_deregister(struct ethosu_mailbox *mbox,
 			       struct ethosu_mailbox_msg *msg);
@@ -91,6 +103,8 @@
 /**
  * ethosu_mailbox_find() - Find mailbox message
  *
+ * Context: Must be called with the device mutex locked
+ *
  * Return: a valid pointer on success, otherwise an error ptr.
  */
 struct ethosu_mailbox_msg *ethosu_mailbox_find(struct ethosu_mailbox *mbox,
@@ -101,6 +115,8 @@
  * ethosu_mailbox_fail() - Fail mailbox messages
  *
  * Call fail() callback on all messages in pending list.
+ *
+ * Context: Must be called with the device mutex locked
  */
 void ethosu_mailbox_fail(struct ethosu_mailbox *mbox);