/* NOTICE: Do NOT hold either the hvcs_struct.lock or hvcs_structs_lock when calling this function or you will get deadlock.  */
static struct hvcs_struct* hvcs_get_by_index(int index)
/* NOTICE: Do NOT hold either the hvcs_struct.lock or hvcs_structs_lock when calling this function or you will get deadlock.  */
static struct hvcs_struct* hvcs_get_by_index(int index)
{
	struct hvcs_struct *hvcsd = NULL;
	unsigned long flags;
	spin_lock(&hvcs_structs_lock);
	if (index >= 0 && index < HVCS_MAX_SERVER_ADAPTERS) {
		list_for_each_entry(hvcsd, &hvcs_structs, next) {
			spin_lock_irqsave(&hvcsd->lock, flags);
			if (hvcsd->index == index) {
				kref_get(&hvcsd->kref);
				spin_unlock_irqrestore(&hvcsd->lock, flags);
				spin_unlock(&hvcs_structs_lock);
				return hvcsd;
			}
			spin_unlock_irqrestore(&hvcsd->lock, flags);
		}
		hvcsd = NULL;
	}
	spin_unlock(&hvcs_structs_lock);
	return hvcsd;
}