/* Note that this is called to free MRs created by ipath_get_dma_mr() or ipath_reg_user_mr().  */
int ipath_dereg_mr(struct ib_mr *ibmr)
/* Note that this is called to free MRs created by ipath_get_dma_mr() or ipath_reg_user_mr().  */
int ipath_dereg_mr(struct ib_mr *ibmr)
{
	struct ipath_mr *mr = to_imr(ibmr);
	int i;
	ipath_free_lkey(&to_idev(ibmr->device)->lk_table, ibmr->lkey);
	i = mr->mr.mapsz;
	while (i) {
		i--;
		kfree(mr->mr.map[i]);
	}
	if (mr->umem)
		ib_umem_release(mr->umem);
	kfree(mr);
	return 0;
}