mthca_free_db(dev, MTHCA_DB_TYPE_CQ_ARM, cq->arm_db_index); 
if (dev->hca_type == ARBEL_NATIVE) mthca_free_db(dev, MTHCA_DB_TYPE_CQ_ARM, cq->arm_db_index); 
int mthca_init_cq(struct mthca_dev *dev, int nent,		  struct mthca_cq *cq){	int size = nent * MTHCA_CQ_ENTRY_SIZE;	void *mailbox = NULL;	struct mthca_cq_context *cq_context;	int err = -ENOMEM;	u8 status;	int i;	might_sleep();	cq->ibcq.cqe = nent - 1;	cq->cqn = mthca_alloc(&dev->cq_table.alloc);	if (cq->cqn == -1)		return -ENOMEM;	if (dev->hca_type == ARBEL_NATIVE) {		cq->arm_sn = 1;		err = mthca_table_get(dev, dev->cq_table.table, cq->cqn);		if (err)			goto err_out;		err = -ENOMEM;		cq->set_ci_db_index = mthca_alloc_db(dev, MTHCA_DB_TYPE_CQ_SET_CI,						     cq->cqn, &cq->set_ci_db);		if (cq->set_ci_db_index < 0)			goto err_out_icm;		cq->arm_db_index = mthca_alloc_db(dev, MTHCA_DB_TYPE_CQ_ARM,						  cq->cqn, &cq->arm_db);		if (cq->arm_db_index < 0)			goto err_out_ci;	}	mailbox = kmalloc(sizeof (struct mthca_cq_context) + MTHCA_CMD_MAILBOX_EXTRA,			  GFP_KERNEL);	if (!mailbox)		goto err_out_mailbox;	cq_context = MAILBOX_ALIGN(mailbox);	err = mthca_alloc_cq_buf(dev, size, cq);	if (err)		goto err_out_mailbox;	for (i = 0; i < nent; ++i)		set_cqe_hw(get_cqe(cq, i));	spin_lock_init(&cq->lock);	atomic_set(&cq->refcount, 1);	init_waitqueue_head(&cq->wait);	memset(cq_context, 0, sizeof *cq_context);	cq_context->flags           = cpu_to_be32(MTHCA_CQ_STATUS_OK      |						  MTHCA_CQ_STATE_DISARMED |						  MTHCA_CQ_FLAG_TR);	cq_context->start           = cpu_to_be64(0);	cq_context->logsize_usrpage = cpu_to_be32((ffs(nent) - 1) << 24 |						  dev->driver_uar.index);	cq_context->error_eqn       = cpu_to_be32(dev->eq_table.eq[MTHCA_EQ_ASYNC].eqn);	cq_context->comp_eqn        = cpu_to_be32(dev->eq_table.eq[MTHCA_EQ_COMP].eqn);	cq_context->pd              = cpu_to_be32(dev->driver_pd.pd_num);	cq_context->lkey            = cpu_to_be32(cq->mr.ibmr.lkey);	cq_context->cqn             = cpu_to_be32(cq->cqn);	if (dev->hca_type == ARBEL_NATIVE) {		cq_context->ci_db    = cpu_to_be32(cq->set_ci_db_index);		cq_context->state_db = cpu_to_be32(cq->arm_db_index);	}	err = mthca_SW2HW_CQ(dev, cq_context, cq->cqn, &status);	if (err) {		mthca_warn(dev, "SW2HW_CQ failed (%d)\n", err);		goto err_out_free_mr;	}	if (status) {		mthca_warn(dev, "SW2HW_CQ returned status 0x%02x\n",			   status);		err = -EINVAL;		goto err_out_free_mr;	}	spin_lock_irq(&dev->cq_table.lock);	if (mthca_array_set(&dev->cq_table.cq,			    cq->cqn & (dev->limits.num_cqs - 1),			    cq)) {		spin_unlock_irq(&dev->cq_table.lock);		goto err_out_free_mr;	}	spin_unlock_irq(&dev->cq_table.lock);	cq->cons_index = 0;	kfree(mailbox);	return 0;err_out_free_mr:	mthca_free_mr(dev, &cq->mr);	mthca_free_cq_buf(dev, cq);err_out_mailbox:	kfree(mailbox);	mthca_free_db(dev, MTHCA_DB_TYPE_CQ_ARM, cq->arm_db_index);err_out_ci:	mthca_free_db(dev, MTHCA_DB_TYPE_CQ_SET_CI, cq->set_ci_db_index);err_out_icm:	mthca_table_put(dev, dev->cq_table.table, cq->cqn);err_out:	mthca_free(&dev->cq_table.alloc, cq->cqn);	return err;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/b635fa215192a02e58e8e30d5d927435aa108192/mthca_cq.c/buggy/drivers/infiniband/hw/mthca/mthca_cq.c