/* The caller is responsible for decrementing the reference count if found.  */
struct ipath_mcast* ipath_mcast_find(union ib_gid *mgid)
/* The caller is responsible for decrementing the reference count if found.  */
struct ipath_mcast* ipath_mcast_find(union ib_gid *mgid)
{
	struct rb_node *n;
	unsigned long flags;
	struct ipath_mcast *mcast;
	spin_lock_irqsave(&mcast_lock, flags);
	n = mcast_tree.rb_node;
	while (n) {
		int ret;
		mcast = rb_entry(n, struct ipath_mcast, rb_node);
		ret = memcmp(mgid->raw, mcast->mgid.raw,
			     sizeof(union ib_gid));
		if (ret < 0)
			n = n->rb_left;
		else if (ret > 0)
			n = n->rb_right;
		else {
			atomic_inc(&mcast->refcount);
			spin_unlock_irqrestore(&mcast_lock, flags);
			goto bail;
		}
	}
	spin_unlock_irqrestore(&mcast_lock, flags);
	mcast = NULL;
bail:
	return mcast;
}