/* Do not call this function with either the hvc_structs_lock or the hvc_struct lock held. If successful, this function increments the kref reference count against the target hvc_struct so it should be released when finished.  */
static struct hvc_struct* hvc_get_by_index(int index)
/* Do not call this function with either the hvc_structs_lock or the hvc_struct lock held. If successful, this function increments the kref reference count against the target hvc_struct so it should be released when finished.  */
static struct hvc_struct* hvc_get_by_index(int index)
{
	struct hvc_struct *hp;
	unsigned long flags;
	spin_lock(&hvc_structs_lock);
	list_for_each_entry(hp, &hvc_structs, next) {
		spin_lock_irqsave(&hp->lock, flags);
		if (hp->index == index) {
			kref_get(&hp->kref);
			spin_unlock_irqrestore(&hp->lock, flags);
			spin_unlock(&hvc_structs_lock);
			return hp;
		}
		spin_unlock_irqrestore(&hp->lock, flags);
	}
	hp = NULL;
	spin_unlock(&hvc_structs_lock);
	return hp;
}