Commit a479433a authored by Dean Luick's avatar Dean Luick Committed by Leon Romanovsky

IB/hfi1: Assign npages earlier

Improve code clarity and enable earlier use of
tidbuf->npages by moving its assignment to
structure creation time.
Signed-off-by: default avatarDean Luick <dean.luick@cornelisnetworks.com>
Signed-off-by: default avatarDennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>
Link: https://lore.kernel.org/r/167329104884.1472990.4639750192433251493.stgit@awfm-02.cornelisnetworks.comSigned-off-by: default avatarLeon Romanovsky <leon@kernel.org>
parent 3c49eef3
...@@ -152,16 +152,11 @@ static void unpin_rcv_pages(struct hfi1_filedata *fd, ...@@ -152,16 +152,11 @@ static void unpin_rcv_pages(struct hfi1_filedata *fd,
static int pin_rcv_pages(struct hfi1_filedata *fd, struct tid_user_buf *tidbuf) static int pin_rcv_pages(struct hfi1_filedata *fd, struct tid_user_buf *tidbuf)
{ {
int pinned; int pinned;
unsigned int npages; unsigned int npages = tidbuf->npages;
unsigned long vaddr = tidbuf->vaddr; unsigned long vaddr = tidbuf->vaddr;
struct page **pages = NULL; struct page **pages = NULL;
struct hfi1_devdata *dd = fd->uctxt->dd; struct hfi1_devdata *dd = fd->uctxt->dd;
/* Get the number of pages the user buffer spans */
npages = num_user_pages(vaddr, tidbuf->length);
if (!npages)
return -EINVAL;
if (npages > fd->uctxt->expected_count) { if (npages > fd->uctxt->expected_count) {
dd_dev_err(dd, "Expected buffer too big\n"); dd_dev_err(dd, "Expected buffer too big\n");
return -EINVAL; return -EINVAL;
...@@ -188,7 +183,6 @@ static int pin_rcv_pages(struct hfi1_filedata *fd, struct tid_user_buf *tidbuf) ...@@ -188,7 +183,6 @@ static int pin_rcv_pages(struct hfi1_filedata *fd, struct tid_user_buf *tidbuf)
return pinned; return pinned;
} }
tidbuf->pages = pages; tidbuf->pages = pages;
tidbuf->npages = npages;
fd->tid_n_pinned += pinned; fd->tid_n_pinned += pinned;
return pinned; return pinned;
} }
...@@ -262,6 +256,7 @@ int hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd, ...@@ -262,6 +256,7 @@ int hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd,
tidbuf->vaddr = tinfo->vaddr; tidbuf->vaddr = tinfo->vaddr;
tidbuf->length = tinfo->length; tidbuf->length = tinfo->length;
tidbuf->npages = num_user_pages(tidbuf->vaddr, tidbuf->length);
tidbuf->psets = kcalloc(uctxt->expected_count, sizeof(*tidbuf->psets), tidbuf->psets = kcalloc(uctxt->expected_count, sizeof(*tidbuf->psets),
GFP_KERNEL); GFP_KERNEL);
if (!tidbuf->psets) { if (!tidbuf->psets) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment