Skip to content

Commit

Permalink
[IB] mthca: Fix doorbell record resource leak
Browse files Browse the repository at this point in the history
If we allocate a bunch of doorbell records and then free them, we'll
end up with completely empty pages, which we then free.  However, when
we come back to allocate more doorbell pages, we have to reallocate
those empty pages rather than always trying to take a slot that we've
never used.  If we don't, we eventually use up every slot and fail to
allocate a doorbell record, even though we have plenty of free space.

Signed-off-by: Roland Dreier <rolandd@cisco.com>
  • Loading branch information
Roland Dreier committed Sep 26, 2005
1 parent 8ddec74 commit 018771f
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions drivers/infiniband/hw/mthca/mthca_memfree.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,12 +529,25 @@ int mthca_alloc_db(struct mthca_dev *dev, int type, u32 qn, __be32 **db)
goto found;
}

for (i = start; i != end; i += dir)
if (!dev->db_tab->page[i].db_rec) {
page = dev->db_tab->page + i;
goto alloc;
}

if (dev->db_tab->max_group1 >= dev->db_tab->min_group2 - 1) {
ret = -ENOMEM;
goto out;
}

if (group == 0)
++dev->db_tab->max_group1;
else
--dev->db_tab->min_group2;

page = dev->db_tab->page + end;

alloc:
page->db_rec = dma_alloc_coherent(&dev->pdev->dev, 4096,
&page->mapping, GFP_KERNEL);
if (!page->db_rec) {
Expand All @@ -554,10 +567,6 @@ int mthca_alloc_db(struct mthca_dev *dev, int type, u32 qn, __be32 **db)
}

bitmap_zero(page->used, MTHCA_DB_REC_PER_PAGE);
if (group == 0)
++dev->db_tab->max_group1;
else
--dev->db_tab->min_group2;

found:
j = find_first_zero_bit(page->used, MTHCA_DB_REC_PER_PAGE);
Expand Down

0 comments on commit 018771f

Please sign in to comment.