Hi,
[Copy-paste reuse alert!]
On 12/29/05, Bryan O'Sullivan <[email protected]> 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
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Stuff]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
[Linux Resources]