[openib-general] Re: [PATCH 17 of 20] ipath - infiniband verbs support, part 3 of 3
Pekka Enberg
penberg at cs.helsinki.fi
Thu Dec 29 11:24:38 PST 2005
Hi,
[Copy-paste reuse alert!]
On 12/29/05, Bryan O'Sullivan <bos at pathscale.com> wrote:
> +static struct ib_mr *ipath_reg_phys_mr(struct ib_pd *pd,
> + struct ib_phys_buf *buffer_list,
> + int num_phys_buf,
> + int acc, u64 *iova_start)
> +{
> + struct ipath_mr *mr;
> + int n, m, i;
> +
> + /* Allocate struct plus pointers to first level page tables. */
> + m = (num_phys_buf + IPATH_SEGSZ - 1) / IPATH_SEGSZ;
> + mr = kmalloc(sizeof *mr + m * sizeof mr->mr.map[0], GFP_KERNEL);
> + if (!mr)
> + return ERR_PTR(-ENOMEM);
> +
> + /* Allocate first level page tables. */
> + for (i = 0; i < m; i++) {
> + mr->mr.map[i] = kmalloc(sizeof *mr->mr.map[0], GFP_KERNEL);
> + if (!mr->mr.map[i]) {
> + while (i)
> + kfree(mr->mr.map[--i]);
> + kfree(mr);
> + return ERR_PTR(-ENOMEM);
> + }
> + }
> + mr->mr.mapsz = m;
[snip, snip]
> +static struct ib_mr *ipath_reg_user_mr(struct ib_pd *pd,
> + struct ib_umem *region,
> + int mr_access_flags,
> + struct ib_udata *udata)
> +{
> + struct ipath_mr *mr;
> + struct ib_umem_chunk *chunk;
> + int n, m, i;
> +
> + n = 0;
> + list_for_each_entry(chunk, ®ion->chunk_list, list)
> + n += chunk->nents;
> +
> + /* Allocate struct plus pointers to first level page tables. */
> + m = (n + IPATH_SEGSZ - 1) / IPATH_SEGSZ;
> + mr = kmalloc(sizeof *mr + m * sizeof mr->mr.map[0], GFP_KERNEL);
> + if (!mr)
> + return ERR_PTR(-ENOMEM);
> +
> + /* Allocate first level page tables. */
> + for (i = 0; i < m; i++) {
> + mr->mr.map[i] = kmalloc(sizeof *mr->mr.map[0], GFP_KERNEL);
> + if (!mr->mr.map[i]) {
> + while (i)
> + kfree(mr->mr.map[--i]);
> + kfree(mr);
> + return ERR_PTR(-ENOMEM);
> + }
> + }
> + mr->mr.mapsz = m;
[snip, more duplicate code]
The above fragment is repeated at least three times. Please factor out
the common code into separate functions.
Pekka
More information about the general
mailing list