/* Acquires a context element from the free list and locks the mutex on the context. Sets the msg_ctx task to current. Returns zero on success; non-zero on error or upon failure to acquire a free context element. Must be called with ecryptfs_msg_ctx_lists_mux held.  */
static int ecryptfs_acquire_free_msg_ctx(struct ecryptfs_msg_ctx **msg_ctx)
/* Acquires a context element from the free list and locks the mutex on the context. Sets the msg_ctx task to current. Returns zero on success; non-zero on error or upon failure to acquire a free context element. Must be called with ecryptfs_msg_ctx_lists_mux held.  */
static int ecryptfs_acquire_free_msg_ctx(struct ecryptfs_msg_ctx **msg_ctx)
{
	struct list_head *p;
	int rc;
	if (list_empty(&ecryptfs_msg_ctx_free_list)) {
		printk(KERN_WARNING "%s: The eCryptfs free "
		       "context list is empty.  It may be helpful to "
		       "specify the ecryptfs_message_buf_len "
		       "parameter to be greater than the current "
		       "value of [%d]\n", __func__, ecryptfs_message_buf_len);
		rc = -ENOMEM;
		goto out;
	}
	list_for_each(p, &ecryptfs_msg_ctx_free_list) {
		*msg_ctx = list_entry(p, struct ecryptfs_msg_ctx, node);
		if (mutex_trylock(&(*msg_ctx)->mux)) {
			(*msg_ctx)->task = current;
			rc = 0;
			goto out;
		}
	}
	rc = -ENOMEM;
out:
	return rc;
}