kfree(mailbox); 
mthca_free_mailbox(dev, mailbox); 
int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid){	struct mthca_dev *dev = to_mdev(ibqp->device);	void *mailbox;	struct mthca_mgm *mgm;	u16 hash;	int prev, index;	int i, loc;	int err;	u8 status;	mailbox = kmalloc(sizeof *mgm + MTHCA_CMD_MAILBOX_EXTRA, GFP_KERNEL);	if (!mailbox)		return -ENOMEM;	mgm = MAILBOX_ALIGN(mailbox);	if (down_interruptible(&dev->mcg_table.sem))		return -EINTR;	err = find_mgm(dev, gid->raw, mgm, &hash, &prev, &index);	if (err)		goto out;	if (index == -1) {		mthca_err(dev, "MGID %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x "			  "not found\n",			  be16_to_cpu(((u16 *) gid->raw)[0]),			  be16_to_cpu(((u16 *) gid->raw)[1]),			  be16_to_cpu(((u16 *) gid->raw)[2]),			  be16_to_cpu(((u16 *) gid->raw)[3]),			  be16_to_cpu(((u16 *) gid->raw)[4]),			  be16_to_cpu(((u16 *) gid->raw)[5]),			  be16_to_cpu(((u16 *) gid->raw)[6]),			  be16_to_cpu(((u16 *) gid->raw)[7]));		err = -EINVAL;		goto out;	}	for (loc = -1, i = 0; i < MTHCA_QP_PER_MGM; ++i) {		if (mgm->qp[i] == cpu_to_be32(ibqp->qp_num | (1 << 31)))			loc = i;		if (!(mgm->qp[i] & cpu_to_be32(1 << 31)))			break;	}	if (loc == -1) {		mthca_err(dev, "QP %06x not found in MGM\n", ibqp->qp_num);		err = -EINVAL;		goto out;	}	mgm->qp[loc]   = mgm->qp[i - 1];	mgm->qp[i - 1] = 0;	err = mthca_WRITE_MGM(dev, index, mgm, &status);	if (err)		goto out;	if (status) {		mthca_err(dev, "WRITE_MGM returned status %02x\n", status);		err = -EINVAL;		goto out;	}	if (i != 1)		goto out;	goto out;	if (prev == -1) {		/* Remove entry from MGM */		if (be32_to_cpu(mgm->next_gid_index) >> 5) {			err = mthca_READ_MGM(dev,					     be32_to_cpu(mgm->next_gid_index) >> 5,					     mgm, &status);			if (err)				goto out;			if (status) {				mthca_err(dev, "READ_MGM returned status %02x\n",					  status);				err = -EINVAL;				goto out;			}		} else			memset(mgm->gid, 0, 16);		err = mthca_WRITE_MGM(dev, index, mgm, &status);		if (err)			goto out;		if (status) {			mthca_err(dev, "WRITE_MGM returned status %02x\n", status);			err = -EINVAL;			goto out;		}	} else {		/* Remove entry from AMGM */		index = be32_to_cpu(mgm->next_gid_index) >> 5;		err = mthca_READ_MGM(dev, prev, mgm, &status);		if (err)			goto out;		if (status) {			mthca_err(dev, "READ_MGM returned status %02x\n", status);			err = -EINVAL;			goto out;		}		mgm->next_gid_index = cpu_to_be32(index << 5);		err = mthca_WRITE_MGM(dev, prev, mgm, &status);		if (err)			goto out;		if (status) {			mthca_err(dev, "WRITE_MGM returned status %02x\n", status);			err = -EINVAL;			goto out;		}	} out:	up(&dev->mcg_table.sem);	kfree(mailbox);	return err;}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/ed878458eeff9754d66f1b0325df6ebbfcdce668/mthca_mcg.c/buggy/drivers/infiniband/hw/mthca/mthca_mcg.c